Add FOG (atomization effect) in a 3D scenario to increase the realism, produce depth and distance sensation, can also be used to create an atmosphere; or feel the scenery. Direct3D supports two atomization modes - Pixel Fog and Vertex Fog.
The use of FOG is quite simple. Just set a few parameters. First set whether the FOG effect is enabled: g_pdevice-> setrenderstate (D3DRS_FOGENABLE, TRUE);
Then determine the color of the FOG:
g_pdevice-> setrenderstate (D3DRS_FOGCOLOR, 0x0F0F0F);
Then determine the formula mode of the FOG to be used, and the FOG formula mode has three -d3dfog_linear, d3dfog_exp, d3dfog_exp21. If you use the D3DFOG_LINEAR mode, set the start value D3DRS_FOGSTART and end value D3DRS_FOGEND with Fog's depth.
PD3DDEVICE8-> Setrenderstate (D3DRS_FOGSTART, * ((DWORD *)))); pd3ddevice8-> setrenderstate (D3DRS_FOGEND, * ((DWORD *)));
2. If you use a non-D3DFOG_LINEAR mode, set the concentration of the FOG.
g_pdevice-> setrenderstate (D3DRS_FOGDENSITY, * (DWORD *));
A Pixel Fog is given below
float Start = 0.5f, // For linear modeEnd = 0.8f, Density = 0.66; // For exponential modesDWORD Mode = D3DFOG_EXP; // You can also try to set Mode = D3DFOG_LINEAR // Enable fog blending.g_pDevice-> SetRenderState ( D3DRS_FOGENABLE, TRUE); // Set the fog color.g_pDevice-> SetRenderState (D3DRS_FOGCOLOR, 0x0f0fff); // Set fog parameters.if (D3DFOG_LINEAR == Mode) {g_pDevice-> SetRenderState (D3DRS_FOGTABLEMODE, Mode); g_pDevice-> SetRenderState (D3DRS_FOGSTART, * (DWORD *) (& Start)); g_pDevice-> SetRenderState (D3DRS_FOGEND, * (DWORD *) (& End));} else {g_pDevice-> SetRenderState (D3DRS_FOGTABLEMODE, Mode); g_pDevice-> SetRenderState (D3DRS_FOGDENSITY, * (DWORD *) (& Density));