Sign in to follow this  

vertex shader and fog.

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this