Sign in to follow this  

[DX9] fog won't turn on

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

I added this bit of code into the program

[CODE]
LPDIRECT3DDEVICE9 device;
...
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);
[/CODE]

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 (http://msdn.microsoft.com/en-us/library/windows/desktop/bb172599%28v=vs.85%29.aspx):
[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: http://msdn.microsoft.com/en-us/library/windows/desktop/bb147365%28v=vs.85%29.aspx#Fog_Depth_and_Shading_Mode_Changes

Share this post


Link to post
Share on other sites

This topic is 2074 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.

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