Sign in to follow this  

[DX9] fog won't turn on

Recommended Posts

I added this bit of code into the program

device->SetRenderState(D3DRS_FOGENABLE, true);
device->SetRenderState(D3DRS_FOGCOLOR, D3DCOLOR_XRGB(255, 255, 0));
device->SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_EXP);
device->SetRenderState(D3DRS_FOGDENSITY, 0.1);

No fog at all when I run the program. I tried changing fog's density from 0.1 to 0.99, nothing at all. If I put in more than that, still nothing. Less than 0, everything but background is filled with yellow I set for the fog. I changed from FOGTABLEMODE to FOGVERTEXMODE, from exp to exp2, to linear. I tried everything I can think of. but the fog just doesn't show up at all. The model goes beyond the far plane. I'm quite sure I did something wrong here. What could I do wrong?

Share this post

Link to post
Share on other sites
Read the documentation for D3DRS_FOGDENSITY (
[quote]Values for this render state are floating-point values. Because the IDirect3DDevice9::SetRenderState method accepts DWORD values, your application must cast a variable that contains the value, as shown in the following code example.[code]m_pDevice9->SetRenderState(D3DRS_FOGDENSITY, *((DWORD*) (&fFogDensity)));[/code][/quote]

Also, this kind of fog will flat-out not work at all with SM3 or higher hardware:

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