Vertex Fog

Started by
4 comments, last by pichu 18 years, 10 months ago
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.

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;
}



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?
---------------------------------The Shadow Sun - Want Your Writing Exposed?
Advertisement
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.
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...
---------------------------------The Shadow Sun - Want Your Writing Exposed?
Does it work for linear fog. Try using linear fog with a distance of 50 for start and 150 for end.
Go on an Intense Rampage
Okay, that works.

The problem for the linear was that the Start and End were too close to eachother, and the problem for the exponential was that the density was too high (was supposed to be around 0.001)

Thanks

Edit: Which has a better effect, vertex or pixel fog?
---------------------------------The Shadow Sun - Want Your Writing Exposed?
There's no real difference between vertex fog and pixel fog as far as appearance goes...

This topic is closed to new replies.

Advertisement