The two main elements of illumination are the light source and the object's material. The material attribute of the object's surface determines the color of light it can reflect and the amount of light it can reflect.
I. Definition of materials in direct3d
Materials in d3d are represented by the d3dmaterial9 structure:
Typedef struct d3dmaterial9 ...{
D3dcolorvalue diffuse;
D3dcolorvalue ambient;
D3dcolorvalue specular;
D3dcolorvalue emissive;
Float power;
} D3dmaterial9, * lpd3dmaterial9;
- Diffuse-specifies the diffuse reflection of the surface.
- Ambient-specifies the ambient light reflected on the surface.
- Specular-specifies the mirrored light reflected on the surface.
- Emissive-the surface itself emits light.
- The value of the power-mirror highlight is the sharpness of the highlight. A larger value indicates a greater difference between the intensity of the highlight and the surrounding brightness.
The total brightness of the surface vertices is:
I indicates the color value of an object. The above expression indicates the total color of the object = ambient light of the Object reflection + diffuse light of the Object reflection + reflected light of the mirror + self-emitting light.
II. Application of Materials
Function idirect3ddevice9: setmaterial () to set the current material attribute of direct3d:
Hresult setmaterial (
Const d3dmaterial9 * pmaterial
);
References:
Frank D. Luna: Introduction to 3D game programming with DirectX 9.0
Weng yunbing: getting started with 3D game programming (directx9.0)
Chen Ka: directx9 3D graphics program design