Direct3D learning notes (5) Primary light technology

xiaoxiao2021-03-06  15

We've Got Camera and action; What affright lights now we have let our triangle spinning, 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; actually we can do not this statement, because the device's lamp is open; we just have better understanding This code is on. 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] .Attion.lights [0] .Range = 10000.0f; device.lights [0] .commit (); device.lights [0] .enabled = true; ok, what is the top of each line above Meaning. 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.

转载请注明原文地址:https://www.9cbs.com/read-48690.html

New Post(0)