Jump to content
  • Advertisement
Sign in to follow this  

vertex shader and fog.

This topic is 3737 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 use vertex shader process the vertex and set the fog use the code below.
float fStart = 100.0f;
float fEnd = 2000.0f;
DWORD Color = 0x92a4a6;
lpDev->SetRenderState(D3DRS_FOGSTART, *(DWORD *)(&fStart));
lpDev->SetRenderState(D3DRS_FOGEND,   *(DWORD *)(&fEnd));
lpDev->SetRenderState(D3DRS_FOGCOLOR, Color);
lpDev->SetRenderState(D3DRS_FOGENABLE, TRUE);

there is no fog in the scene,but the code works well when i render scene use fixed function pipeline. but if i change the D3DRS_FOGVERTEXMODE to D3DRS_FOGTABLEMODE,the fog appears. why the pixel fog works well but vertex fog failed.It is said in D3DSDK "
When using a vertex shader, you must use vertex fog. This is accomplished by using the vertex shader to write the per-vertex fog intensity to the oFog register. After the pixel shader completes, the oFog data is used to linearly interpolate with the fog color. This intensity is not available in a pixel shader

Share this post

Link to post
Share on other sites
The quote of the D3DSDK might be confusing (don't know where exactly you found it :) but here's another one :


In short, pixel fog - also called table fog - is implemented in the device driver and vertex fog is implemented in the Direct3D lighting engine. An application can implement fog with a vertex shader, and pixel fog simultaneously if desired.

Vertex fog is implemented in the D3D lighting engine. This means if you're using a vertex shader, then you don't use the lighting engine anymore, and you need to compute the fog parameter in your vertex shader.

Pixel shader is implemented in the driver. Don't know exactly what this means but I know that pixel fog is applied automatically after everything. It's simply a function of the pixel depth, the pixel color and the fog parameters. It is applied after the pixel shader. This means that you don't have to do anything, it will allways be applied, even if you use shaders.

I hope my explanations weren't too confusing :)

Share this post

Link to post
Share on other sites
thanks a lot.
btw i found the words in the
+--advanced topics
+---Frame buffer
+----fog type
+-----vertex fog

the sdk is November 2007.

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!