If the original article needs to be reproduced, please note: Reprinted from Fengyu Chong unity3d tutorial Institute
Lecture on shader 15thIllumination Basics
Simply put, the final color output of the shader with illumination is the material color * The light color, in which the material color: As mentioned earlier, fixed format tex2d (_ maintex, I. UV) light color: light color =Self-Illumination+Ambient Light+Diffuse Light+Mirror light
The following describes the four types of opticalI. Self-IlluminationLight emissive = coloremissivecoloremissive self-emitting color emitted from the object surface in all directions
II. Environment lightThe light received from all directions on the surface of the object is then reflected in all directions ambient = Ka * colorambientka ambient light coefficient colorambientAmbient light colorWhat is a normal?Normal Line is a vector that is always perpendicular to a certain plane. It is just and selfless. Like a judge, it is named normal. The normal of a point on a surface refers to the line (vector) that goes through this point and perpendicular to the cut plane of the point ). Normal direction: Generally, the Interior Direction of the stereo is the positive direction of the normal direction, and the opposite is the negative direction of the normal.
3. diffuse reflection lightThe main difference between diffuse reflection and mirror reflection is the distribution of normal. If the object is completely smooth, the normal is completely perpendicular to the plane, such as a mirror and bright metal surface. Many objects that look smooth and flat, such as paper, desktop, and clothes, use a magnifier to observe them carefully. The normal is not perpendicular to the visible surface, but parallel to the actual surface. Diffuse Reflection: when the light emits on a rough surface, the light is reflected in all directions. Even if the rays are parallel, the normal directions of each point are inconsistent, this causes the reflected light to be automatically reflected in different directions. This reflected light is called diffuse reflection light.
Diffuse Reflection computingDiffuse = KD x colorlight x max (N * l, 0) KD diffuse reflection coefficient colorlight color n unit normal vector l point to the light source unit vector where N and l point multiplication, if the result is less than or equal to 0, the diffuse reflection is 0.
Iv. reflected lightMirror reflection: light emits light on the smooth and smooth surface of an object with a uniform normal. This reflected light is called a mirror reflection.
KS mirror coefficient colorlight color n unit normal vector l unit vector from point to light source V unit vector from point to observer H (L + V) vector, that is, the intensity coefficient of the normalize (L + V) shininess mirror. The smaller the value, the higher the light dispersion. The higher the value, the more concentrated the light. Facing if the point multiplication between N and L is greater than 0, facing is 1. If it is less than or equal to 0, facing is 0.
Diffuse Reflection and mirror reflection
The reflection mode of light is mainly determined by the material of the object surface. If the source is from the same single light source, the color of the two light sources is the same. The core is the point Multiplication operation involving unit normal. The diffuse reflection is only related to the incident angle of the light. The mirror reflection is related to the incident angle of the light and the angle of the observer.
In the surface shaderIllumination Model
In short, Lambert is a diffuse reflection, and blinnphong contains a mirror reflection. Related definitions can be found inView in lighting. cginc
BlinN-Phong:An evolution Lighting Model of the phone reflection model. The default illumination model of OpenGL and d3d fixed pipelines. After the illumination is calculated in the vertex stage, the pixel values between vertices are obtained through interpolation.
Http://en.wikipedia.org/wiki/Blinn-Phong_shading_model
Lambert:
Only diffuse reflection is available. It has nothing to do with the observer (CAMERA) perspective.