BOOL SetVertexFog(BOOL Enabled, short Mode, DWORD Color, float Density, BOOL UseRange)
{
// Check to see if Device Error
if(m_pD3DDevice == NULL)
return FALSE;
float Start = 0.5f, End = 0.8f; // Linear fog distances
// Enable the Blending of Fog
if(Enabled == TRUE)
m_pD3DDevice->SetRenderState(D3DRS_FOGENABLE, TRUE);
// Set the Color of the Fog
m_pD3DDevice->SetRenderState(D3DRS_FOGCOLOR, Color);
// Set Linear fog mode with start and end variables
if(Mode == D3DFOG_LINEAR) {
m_pD3DDevice->SetRenderState(D3DRS_FOGVERTEXMODE, Mode);
m_pD3DDevice->SetRenderState(D3DRS_FOGSTART, *(DWORD *)(&Start));
m_pD3DDevice->SetRenderState(D3DRS_FOGEND, *(DWORD *)(&End));
}
// Set Exponetial fog mode with density variable
if(Mode == D3DFOG_EXP) {
m_pD3DDevice->SetRenderState(D3DRS_FOGVERTEXMODE, Mode);
m_pD3DDevice->SetRenderState(D3DRS_FOGDENSITY, *(DWORD *)(&Density));
}
// Check if to use range fog or not
if(UseRange)
m_pD3DDevice->SetRenderState(D3DRS_RANGEFOGENABLE, TRUE);
return TRUE;
}
Vertex Fog
I created the following function to render fog, but it doesn't seem to work. When I load up the application, all 3d objects just turn the specified color.
Here is when I called it...
SetPixelFog(TRUE, D3DFOG_EXP, D3DCOLOR_RGBA(255,255,255,255), 0.1f, FALSE);
Does anyone know what the problem is here? Does my graphics card need to support vertex shaders in order to accomplish this?
Yeah, you have to turn the distances up really freakin high. Try a Start of 0.99999 and an end of 1.0.
edit: Oh, and it's just a guess, but I think the distances reflect your z-buffer depth.
edit: Oh, and it's just a guess, but I think the distances reflect your z-buffer depth.
It didn't work. The entire scene still shows up as a white blob.
I'm not sure what you ment by the z buffer depth though. My current Z Buffer Depth is 1.0f, so that should be okay, right?
Otherwise, there's something wrong with the code. Most of the code is from the April DirectX Documentation...
I'm not sure what you ment by the z buffer depth though. My current Z Buffer Depth is 1.0f, so that should be okay, right?
Otherwise, there's something wrong with the code. Most of the code is from the April DirectX Documentation...
Does it work for linear fog. Try using linear fog with a distance of 50 for start and 150 for end.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement