III, Projection Matrix
It is said that at 2:00 in the morning, I can see the Lion Square rain, very much missing the evening three years ago, the beautiful meteor shower made me unforgettable for life; support it now, I don't know if it can be seen.
Projection, it is an object in 3D space, which shows the effect on the 2D screen. There are two projections in D3D: perspective projection and orthogonal projection. Perspective projection is affected by viewpoints, the farther from the observer, the smaller the object observed, which is true to the world. The influence of orthogonal projection is unacceptable, the projection on the plane is the actual size of the object. The three views during the drawing process are orthogonal projection.
D3DXMAMATRIX MATPROJ;
D3DXMAMATRIXIDENTITY (& MATPROJ);
// Perspective projection
D3DXMAMATRIXPERSPECTIVEFORLH (& Matproj, FFovy, Faspect, Fnearplane, FFARPLANE);
PD3DDEVICE-> SetTransform (D3DTS_PROJECTION, & MATPROJ);
正 正 投 投
D3DXMatrixortholh (& Matproj, Width, Height, Nearplane, FarPlane);
PD3DDEVICE-> SetTransform (D3DTS_PROJECTION, & MATPROJ);
The above is based on the perspective projection and orthogonal projection established by the left hand coordinate system, and DXSDK has a detailed description for each function; and it is very understandable. The functions of each and matrix in D3D are D3DXMATRIX_____.
In some cases, we can package the observation matrix and perspective matrix into a class, that is, the camera. Set the default value when initialization, do not need to be set once each rendering. But because the world matrix is also established each time rendering.
D3D advanced
Fifth, material:
The discussion of the D3D material can be very simple or complicated. It is combined with the light, no lights, what materials are P words. It is said that the material of D3D is actually the reflection method of the object to the light of the light, and the reflection method of various types of light in D3D. D3D simulates the efficacy of true world, including diffuse reflection, mirror reflection, and environmental reflection.
Set the process of setting the material:
D3DMATERIAL9 mtrl;
ZeromeMory (& MTRL, SIZEOF (D3DMATERIAL9));
mtrl.diffuse.r = 1.0f; // Set the diffuse reflection of the light
mtrl.diffuse.g = 1.0f;
mtrl.diffuse.b = 1.0f;
mtrl.diffuse.a = 1.0f;
mtrl.specular.r = 1.0f; / / Set specular reflection to the light
mtrl.specular.g = 1.0f;
mtrl.specular.b = 1.0f;
mtrl.specular.a = 1.0f;
Mtrl.power = 10.0f; // The larger value, the higher the degree of penetration, the smaller the highlight range, the brighter
mtrl.ambient.r = 1.0f; // Set the reflection of the ambient light
mtrl.ambient.g = 1.0f;
mtrl.ambient.b = 1.0f;
mtrl.ambient.a = 1.0f;
PD3DDEVICE-> SetMaterial (& mtrl); // call each time you render
See D3DMaterial9 Structure by D3DMATERIAL9 STRUCTURE. The diffuse reflection is actually the surface color of the object, and the mirror reflection can cause the object to produce a high light effect. The ambient light is generally to control the brightness of the entire space, as well as "atmosphere" :). In D3D, different polygons that make up an object may even have different materials. Because most scenes contain the diffuse reflection light than the ambient light, the effect is the greatest in the process of deciding the final color. Further, since the diffuse reflection has directionality, the incident angle of diffuse reflected light affects the strength of the entire reflected light. When the incident direction of the light is parallel to the vertex method, the reflection is the strongest. As the incident direction is increasing between the angle between the vertex, the diffuse reflection effect is gradually reduced. The number of reflected light is the cosine value of the incident light and the vertex method.
The ambient reflection and ambient light are no directionality. Environmental reflection is small in the final color of the rendered object, but it does affect the final color, the most obvious is that when the material is small or even reflective reflected light. The environmental reflection of materials is affected by the ambient light in the scene.
There is another property that is radioactivity, which is the same as it is the same as it is the same as it is. The EMISSIVE member of the D3DMaRial9 structure is used to describe the color and transparency of the light emitted by the object. The radiation can affect the color of the object, or the dark material brightens and partially presents the color of the illuminated color. Example: If you want an object to make an object in the application, you can use this property to use this property, which can also avoid the calculation consumption caused by adding the light source in the scene.
My concept of materials is not very strong. Sometimes I want a metal, the result is like a brick, I am, I am not learning art. With some other 3D tools, you can build the model you need, which can contain material information. Then export into a .x suffix file, file files can be loaded directly from D3D.
Today's "small fat sheep" is delicious!
Sixth, lighting:
Lights and materials are unlike, from the previous chapter, you should see some clues. The properties of the light and materials are all corresponding. If there is no setting, the light in the scene will not see any effect.
All types of light are three kinds, it is easy to understand. It is recommended that you create a sphere as a rendering object, a combination of various rays and materials, can be significantly reacted on the sphere; this is like a child's art classics still life sketch, the first iron is a sphere and a column. (My art is still good, unfortunately, a genius is stifled in the cradle.)
I don't know if you have a "miracle" experience, the light effect inside can only be described with a word, that is, "Bow B"! Our goal is to learn 3D, do only one word to describe games - "More cattle B"! - Begin to dream.
First, direction light; this source is only the direction and color, no position. And it is not affected by attenuation and scope, so the directional light is a light source that requires the smallest amount of calculated amount in D3D. In general, the directional light is considered to be a parallel light in an infinity of the source, just like a sunlight.
Second, point light source; feature is color and location, but there is no direction. It issues exactly the same light in each direction; however, the light of the point source will be affected by the scope and attenuation. If the scope of the light is exceeded, the light is not visible; the simultaneous point of the light source is also influenced, it has a attenuation value:
D3DLIGHT9 LIGHT;
Light.Type = D3DLight_Point D3DLIGHT_POINT;
Light.position = D3DVector3 (50.0F, 20.0F, -50.0F);
Light.diffuse.r = light.diffuse.g = light.diffuse.b = 1.0f; light.range = 100.0f;
Light.attion0 = 0.0f;
Light.attion1 = 0.1f;
Light.attion2 = 0.0f;
As the distance to the light source is getting farther, the intensity of the light will be weaker. The edge light intensity is equal to 1 / Range of the intensity of the source.
Third, spotlights; it is the most complex and largest amount of light in D3D. It includes the most attributes: position, direction, color, inner diameter aperture, outer diameter aperture, range and attenuation factor. Among them, the attenuation factor is very sensitive to subtle changes, typically set to light.falloff = 1.0f, otherwise it will be unexpected, but will never be a good thing.
Fourth, in addition, there is an ambient light, which can also be used to control the color of the object, and the reflected light is used in conjunction, however, I feel more of the ambient light or on the brightness of the entire scene.
There is a "" related mathematics related to illumination "in the help documentation of the SDK:
The Microsoft® Direct3D® lighting model covers ambient light, diffuse reflected light, mirror reflected light, and radiation light, which is sufficient to solve most of the lighting conditions. We use the sum of the light in the scene as global illumination and calculate using the following formula:
Global illumination = ambient light diffuse reflected light mirror reflected light radiation light
The ambient light is a constant light. It does not change in all directions, and the effects of all pixels in the object are also identical. It calculates very fast, but the object it gets looks flat, there is no real sense. The diffuse reflected light depends on the direction of the light and the surface of the surface. Since the direction of the light and the change of the surface method, the diffuse reflected light varies with the surface of the object. Because the diffuse reflected light varies with each vertex, it takes a longer time to calculate, but the benefit of using a diffuse reflection light is that it exhibits a bright and dark change and a three-dimensional depth. The mirror reflected light represents the bright specular reflection highlight of the reflected back to the camera when the light is irradiated into the object surface. It is more reflected than reflected, but the surface of the object is faster. The method of calculating the specular reflected light is longer than the calculation of reflected light, but the advantage of using the mirror reflected light is that it adds important details to the surface. The radiation light is light emitted by the object, such as a glow. The real light effect can be obtained by using these types of light in a three-dimensional scene. To get a more real illumination, the application can add more light sources, but this increases the time of rendering scene. To achieve all the effects you want (game) designer, some games use exceed general CPU computing power. In this case, it is generally added to the scene to add light to the scene by using the light map and the ambient map while using the texture map, so that the amount of calculation required to be minimized can be minimized. Ambient light, diffuse reflected light, and mirror reflected light are affected by the decay of the given light and the concentrating lamp factor. The color value calculated for the ambient light, the radiation light and the diffuse reflected light component is stored in the diffuse reflection colors of the output vertex. The diffuse reflection and mirror reflection formulas include attenuation and spotlight factor properties.
The above words are very persuasive, so I still say, want to really understand D3D, you must read the help documentation of the SDK carefully. :)
Today, take this now, the next chapter will take the IDirect3ddevice9 :: setrenderState (...) interface. It is a bit like the total switch of the 3D effect, I don't know if this beet will be despised?
Seventh, setrenderstate (): There is a big problem today, the English is not good ...
About SETRENDERSTATE () There is no skillful thing, all fixed settings, in order to implement an effect in the program, you must make the correct settings. So, this chapter, I want to explain each parameter in setrenderstate (), which is to translate the content of SDK, although this is true, this paragraph is really awkward. If I have a place, everyone helps to point out, please ^ ______ ^.
Setrenderstate ()
The role is to set the parameters of the rendering state of a single device. The first parameter of the interface is
D3DrenderstateType
Enumeration type; also the key to this interface, the second parameter is only the specific set value of the rendering state. This enumeration type has
100
Multiple values, one of the following one. It's already 2 o'clock in the morning, my buddies I really can't ... Hung!