Respect for the wisdom of others, welcome reprint, please indicate the author's heart if Transparent, the original address http://www.cnblogs.com/ubanck/p/4105941.html
In the game development process, the lighting should be an essential part, of course, this refers to most of the slightly larger 3D games will need to give the model or rivers with light, it will look more real, get a better experience. A non-luminous object itself shows what color, in itself reflects what color, such as a stone, in the sun after irradiation, you see is red, and the sun is white, white is because of the combination of RGB, this fast stone absorbs the green and blue, reflected red, then you see this stone will be red.
So when it comes to reflection, it is divided into diffuse reflection (diffuse) and specular reflection (specular), first of all diffuse reflection
Because the surface is uneven, all normal direction is inconsistent, then the reflected light is not consistent, what is normal, so-called normal, is the vertical and the surface of the line (see a buddy said because the normal must be perpendicular to the line, like a justice not a judge, so called normal), incident light to the surface, So that the incident light and reflected light angle equal, to get the reflected light, and we are in the calculation of the dot (n,l) to get a value, N is the normal vector, L represents the incident light vector representation, the two vectors are normalized (using the normalize function) so-called normalization processing, That is, the modulus of this vector is equal to 1 (in fact, let the vector divided by his modulus, this block can refer to the 3D graphics based on the vector part mentioned), and the dot function is a vector point multiplication, that is n*l=| n|*| l|cosθ because of the previous normalization of N and L, then n*l=cosθ, review the trigonometric functions, that is, DOT can also be said to be, the light L projection on the normal size, the incident light and the normal angle between (0,90), the greater the angle, the smaller the value.
The following is a formula for diffuse reflection: Diffuse = Kd * Lightcolor * MAX (N· l,0).
First KD for the light intensity, that is, the strength of the light, accurate is the material to the reflection coefficient, between 0 to 1, according to the name can be imagined. Second Lightcolor, this thing refers to the color of the light, it has RGB three components, in a word, all the colors of the world can be expressed in RGB, through the computer RGB three different values can be matched out of countless colors, 8bit color channels can represent 0-255, So 256 of 3 times, you can combine to get 16777216 colors, of course, the human eye seems to feel less than so many colors, pull away, back to just that topic, the color of light has, multiplied by Max (n*l,0), why do this. Because if the angle is greater than 90 degrees, then there will be negative numbers, negative numbers are meaningless (as for why the situation is greater than 90 degrees, please play the Space Imaging Ability (brain)), so that the diffuse color value is obtained ...