We've Got Camera and Action; What about is the About Lights?
Now we have let our triangle shape, but we still want to do better, what should I do? We can give him a light, the concept we have already mentioned in front, in our black triangle, in order to see his original color, we have closed the lights, now we must do the first thing to do The lamp is opened, first modify the following statement, set to trueDevice.renderstate.lighting = true;
In fact, we can do not do this, because the lights of the device are open by default; we just write this code for everyone better understanding. Ok, now run our program, I will find that black triangle comes out again. It's just that it starts to rotate. What we need to do now is to define a light attribute, and turn the lights. In fact, there is an array of light in the Device class. Every member describes the different properties of light, now We began to define your own lights. Ok, we can use the code that defines the light attributes below after the triangle definition in the onpaint method. Device.lights [0] .TYPE = LIGHTTYPE.POINT; device.lights [0] .position = new vector3 (); device.lights [0] .diffuse = system.drawing.color.white; device.lights [0] .Attenuation0 = 0.2f; device.lights [0] .range = 10000.0f; device.lights [0] .commit (); device.lights [0] .enabled = true;
Ok, what does it mean to represent every line of it? First, we define the type of light. It is a point source. The point light source means that the defined lamp is like a light bulb, and its light is launched in all directions. This paragraph has said some light sources, in fact, everyone should know. There is a bit of light source and parallel light source, etc., I will not say much. The second line, we define the location of the light source. We have built a new Vector3 vector, and the value of his default constructor is (0, 0, 0), which means that our light source location is in the circle of the world coordinate system. Next, we define the color of the light is white. The following is the decay of light, that is, the light intensity of our light. The farther distance is weaker than the light intensity. This truth should everyone understand. He has not given me a strong concept, you can modify the value of yourself to understand the concept of strength. The Range parameter is the maximum range of light to function. In these parameters, some are no longer programs, but the concept of photophysics to understand, so please take a look at the relevant information. I don't have much to say this here, if I completely understand, I will post it. Next device.lights [0] .commit (); is to submit the above properties to the device (Device), some versions do not provide this function, you can delete this line directly, and then automatically submit it after setting the properties. Just in this tutorial I suggest that there is this function's DirectX version, please ensure that you have submitted to the device before using the lights and enabled is set to true. The last row is more obvious, that is, allowing the above properties to display the light source we define.
If you are now running our programs, you will notice that although we have defined our light source, our triangle is still black, we still see any light, Direct3D does not use our light source to illuminate objects. But actually is not the case, but why don't you light? Because the lighting calculation can only be calculated in each normal vector, and the geometric shape we defined in front is that there is no defined method, about what is the way to learn high school mathematics, I am here. It's not ambiot. I know these, let's define the normal normal to give our triangles to make the light calculation correctly calculate the color. The easiest way is to change our vertex type format that enables him to include a normal properties. So modify your triangular data code and become the same below.
CustomvertEX.POSITIONNORMALCOLORED [] VERTS = New CustomvertEX.PositionNormalColored [3]; VERTS [0] .SetPosition (New Vector3 (0.0F, 1.0F, 1.0F)); VERTS [0] .SetNormal (New Vector3 (0.0F, 0.0 f, -1.0f)); VERTS [0] .COLOR = system.drawing.color.White.Toargb (); VERTS [1] .SetPosition (New Vector3 (-1.0F, -1.0F, 1.0F)); VERTS [1] .SetNormal (New Vector3 (0.0F, 0.0F, -1.0F)); VERTS [1] .Color = system.drawing.color. White.Toargb (); VERTS [2] .SetPosition (New Vector3 (1.0F, -1.0F, 1.0F); VERTS [2] .SetNormal (New Vector3 (0.0F, 0.0F, -1.0F)); VERTS [2] .Color = system.drawing.color. White. TOARGB ();
Finally, modify the next code into the following.
Device.beginscene (); device.vertexformat = CustomvertEX.PositionNormalColored.Format; Device.DrawuserPrimities (PrimitiveType.trianglelist, 1, VERTS); device.endscene ();
In fact, we only modified the second line, let it have a normal line.
Here, the biggest change is that we define a triangular plane with a method and set the colors of the three vertices to white, and the light source is also white, and the normal vector is the Z-axis direction, we will see a full White triangle, everyone is interested, can change the top of the top color and the light source color to get different results, because our vector is the z direction, so change the X and Y coordinate vector or independent. Not completely and the plane is vertical, (I don't know if my translation is right. It seems to be this meaning, wait for me to debug code plus the correct understanding), good, now the color of the triangle is not simple color. It is calculated by the color of the color and the color of the light source, because the color in all 3D scenes is calculated so, and the spatial position is also calculated, so it is slower than ordinary 2D scenes, this That is why good 3D games are good for graphics card support. There is also something because the light source will calculate each vertex, so in a relatively large pattern of polygons (just like our triangular environment), it is not so real, we will continue to discuss more advanced lighting technology, For example, Per Pixel Lighting (each pixel lighting technology, I don't know how to translate, everyone will look at English), which will make our scenes look more real. The primary lighting technology finally translated, the bird language is boring, a new word is very long, or Chinese is good, what new vocabulary can be understood by literally, no wonder, some vocabulary only experts know, just like us in front As the vision of the chapter, it is clear that it is a four-priced platform. He said that it is the top of the pyramid. It is also a picture, otherwise it is good, then I check, four-prize Kingshan word tyrant put all the dictionaries. It can't be checked. It seems that it is a professional, no wonder, people will not say, huh, huh. Later, I was interested, I checked some geometric nouns. From the front quadranda to the sideline, only the top of the six-sided, is regular hexagon, who will go back. No wonder now the English word is spent. A cold one. . . . . . Ok, let go of tomorrow. The following chapter is not a drawing, it is equipment testing. But there is not much, then start drawing. Please be patient, I have a limited strength. . Ha ha