fog and vertex shaders?

Started by
2 comments, last by Joeman 18 years, 6 months ago
I'm rendering a scene with terrain, water, and objects. I am rendering the terrain and the water using the programmable pipeline (both pixel and vertex shaders). I'm using the fixed function pipeline for objects. I am having a problem getting fog to work correctly on different graphics cards. On a GeForce 6800 ULTRA, I have no problem, the fog renders correctly for the objects, terrain, and water. When running the application on a GeForce FX Go5600 however, the fog does not render on primitives rendered using the programmable pipeline. I figured out that when using the programmable pipeline, the fog was being automatically calculated for me on the GeForce 6800 but not on the 5600. Therefore to make the application run correctly on both cards I attempted calculated the fog ratio in the vertex shader by hand. This is a snippet of calculating the fog by hand. struct VS_OUTPUT { float4 Pos : POSITION; float4 Diff : COLOR0; float2 TexCoord1 : TEXCOORD0; float2 TexCoord2 : TEXCOORD1; float1 Fog : FOG; }; VS_OUTPUT VS( float3 Pos : POSITION ) { VS_OUTPUT Out; Out.Fog = calculateFog(Pos); .... .... process lots of other stuff .... return Out; } The "Fog" variable outputed from the vertex shader has absolutely no effect on the render. Fog is still displayed on the 6800 and breaks on the 5600. My questions are: Is there a way to make the 5600 calculate fog for me (like the 6800) so that I don't have to do it myself in the vertex shader? Is there a setting I need to change so that the output fog variable in the vertex shader is used as the fog intensity? Any help is appreciated!
Advertisement
Hi,

Just blend your fog parameter with the diffuse color yourself. (e.g. pass the fog parameter as a COLORN to your pixel shader, and in your pixel shader, blend it with the pixel color)
That is a valid option. However, not using the FOG semantic to export the fog value from the vertex shader is kind of a hack. The fog output should work and I need to find out why it doesn't.
Figured out what it was. The D3DRS_FOGTABLEMODE must be set to none.

This topic is closed to new replies.

Advertisement