Learn Shaderforge–custom together with Keyle Blinn-phong

Source: Internet
Author: User

Spent two days carefully prepared this tutorial, come and Keyle together to learn shaderforge, play up ~

Chapter Directory

1. What is the Blinn-phong illumination model

2. How to use a custom lighting model

2.1 Shaderforge built-in illumination model

3. How to use custom-like lighting to achieve blinn-phong illumination model

4. Refine our custom shader

4.1 We'll start by simulating a diffuse algorithm.
4.2 Merging (via addition) to get the results we want
4.3 Optimizing the removal of duplicate declared variables as normal Direction
4.4 Adding a normal map
4.5 Adding emission effects
4.7 Final Effect

1. What is the Blinn-phong illumination model?

To know what Blinn-phong is, first you need to know what is the Phong illumination model, the Phong illumination model is the first influential illumination model in real graphics, the model only considers the reflection of the object to direct illumination, and considers that the ambient light is constant, Reflecting light between objects is not considered, and the reflected light between objects is only represented by ambient light. Phong Light model is a simple lighting model, details to the encyclopedia, and Blinn-phong is to strengthen the Phong, the specific code I will not copy up, in order to improve our business standards can be summed up with a sentence to improve the difference between:

The difference between the Blinn-phong model and the Phong model is that the dot (v,r) is replaced by the dot (n,h), where H is the half-width vector, and the angle of the normal N and the Ray L are in the direction of the split line.

The Blinn-phong model can be expressed as:

Ispecular = ks*is* Pow (dot (n,h), N)

where H = (L + V)/| L+v |, calculating h is faster than calculating the reflection vector R.

The image on the left is a typical example of the Phong illumination model, and the image on the right is an example of the Blinn-phong illumination model

2. How to use a custom lighting model

Check the property bar Lighting unlit/custom , the effect of the change is as follows diffuse will be disabled, this will not be affected by ambient lighting

2.1 Shaderforge built-in illumination model

Amblient Light Ambient

As the name implies, not affected by any angle, position relations, directly take the ambient light color value coloring

Half Direction

The color of the output is related to the angle reflected by the incident light

Light Attenuation

Light attenuation, attenuation and lightcolor effect, very beautiful.

Light Ccolor

Color of the light in the output scene

Light Direction

The expression of things and half Direction the same, the effect is half Direction * 2, the angle of the light source of the effect is very large, the opposite direction of the light source directly on the black, half Direction when also retain color value/2 of the color

Light Position

Ignore the light source according to the Y axis rotation angle change, conversely if the X axis ignores the light source x axis changes, XYZ is not ignored, the default Z axis rotation will not change (around itself to the z axis does not move, there is no displacement)

The effect is as follows

3. How to use custom-like lighting to achieve blinn-phong illumination model

According to the following formula, we make the following implementation in Shaderforge

Ispecular = ks*is* Pow (dot (n,h), N)

The core implementation results are as follows

4. Refine our custom shader

4.1 We'll start by simulating a diffuse algorithm.

4.2 Merging (via addition) to get the results we want

4.3 Optimizing the removal of duplicate declared variables as normal Direction

4.4 Adding a normal map

Add a normal map and tick the check box in normal dir to align the map with the normal map, and the official translation is as follows

The perturbed checkbox makes it use the normals after has applied the "normal" input of the main node, such as a Normal Map.

Right-click to see the big picture Bar ~ Now you will find all the graphics are distorted, very image (including the normal information)

4.5 adding emission effects

In the previous article I have explained the effect of the emission node, and we use the knowledge described above to simulate the effect of ambient illumination using amblient light

First of all I hope that you now know what the environment Light is a concept (do not disappoint me to write so long description), pure light, then we want to make the effect of the mapping of the environment to the map

4.7 Final Effect

If you think the effect is not obvious, let's change a picture.

Done! Lift up our hands and let the people who are still struggling to write shader tremble ~

Learn Shaderforge–custom together with Keyle Blinn-phong

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.