vertex shader and fog.

Started by
1 comment, last by 88er 15 years, 7 months ago
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_FOGVERTEXMODE, D3DFOG_LINEAR);
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 "
Quote: 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
"
Advertisement
Hi,
The quote of the D3DSDK might be confusing (don't know where exactly you found it :) but here's another one :

Quote:
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 :)
thanks a lot.
btw i found the words in the
+-Direct9
+--advanced topics
+---Frame buffer
+----fog type
+-----vertex fog

the sdk is November 2007.

This topic is closed to new replies.

Advertisement