Jump to content
  • Advertisement
Sign in to follow this  
Woodchuck

Pixel fog.

This topic is 4082 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

Correct me if i'm wrong, but the pixel fog render state are only valid for fixed pipeline ? I mean that there is no effect when using pixel shaders...

Share this post


Link to post
Share on other sites
Advertisement
no, it works if you are writing your own shaders.

you just have to calculate it yourself in the vertex shader, and output it.




struct VS_OUTPUT
{
float4 oPos : POSITION;
float2 oT0 : TEXCOORD0;
float oFog : FOG;
};

//RcpFogEndMinusFogStart is the reciprical of the FOG_END - the FOG_START.... 1.0f / ( FOG_END - FOG_START ).

float CalculateFog ( float fDistanceFromCamera )
{
return max ( min ( ( FOG_END - fDistanceFromCamera ) * RcpFogEndMinusFogStart, 1.0f ), 0.0f );
}


float4 fDistanceFromCamera = mul ( vPos, matWorldView ); // vPos is vertex position
Out.oFog = CalculateFog ( fDistanceFromCamera.z );


Share this post


Link to post
Share on other sites
You can do anything and more advance stuff with vertex/pixel shaders just as with the FVF. So you can do pixel fog in HLSL.

Share this post


Link to post
Share on other sites
Thank you for reply all.

Quote:
Original post by programmer_tom
no, it works if you are writing your own shaders.

you just have to calculate it yourself in the vertex shader, and output it.

*** Source Snippet Removed ***


Is that pixel fog or vertex fog ? ;)

Share this post


Link to post
Share on other sites
The fog parameter is calculated per vertex, and then interpolated. However you get the same result you would have gotten had you calculated the parameter per pixel, since the fog equation is linear.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zipster
The fog parameter is calculated per vertex, and then interpolated. However you get the same result you would have gotten had you calculated the parameter per pixel, since the fog equation is linear.


I see, your right, thank you very much.

A last question, do this technic works on shader model 3 (vertex oFog) ?

Share this post


Link to post
Share on other sites
Quote:
Original post by Namethatnobodyelsetook
Quote:
Original post by Namethatnobodyelsetook
Shader model 3 removes the built in fog. If you use SM3 you must do your own fogging.


That's it. ;) Thank you !

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!