Jump to content
  • Advertisement
Sign in to follow this  
zealotgi

Vertex Fog

This topic is 4813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
Does it work for linear fog. Try using linear fog with a distance of 50 for start and 150 for end.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
There's no real difference between vertex fog and pixel fog as far as appearance goes...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!