Sign in to follow this  

Problem with fod

This topic is 2078 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 found this sample from msdn how to create fog:



[CODE]


float Start = 0.5f, // Linear fog distances
End = 1000;

// Enable fog blending.
g_pd3dDevice->SetRenderState(D3DRS_FOGENABLE, TRUE);

// Set the fog color.
g_pd3dDevice->SetRenderState(D3DRS_FOGCOLOR, 0x00ffffff);

// Set fog parameters.


g_pd3dDevice->SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_EXP);
g_pd3dDevice->SetRenderState(D3DRS_FOGSTART, *(DWORD *)(&Start));
g_pd3dDevice->SetRenderState(D3DRS_FOGEND, *(DWORD *)(&End));

[/CODE]
but i see only a white screen, without any objects...where is wrong here?

Share this post


Link to post
Share on other sites
You copied the 'linear fog' code instead of the 'exponential fog' code [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

[source]if(D3DFOG_LINEAR == Mode)
{
// This is what you copied, notice the condition above
g_pDevice->SetRenderState(D3DRS_FOGVERTEXMODE, Mode);
g_pDevice->SetRenderState(D3DRS_FOGSTART, *(DWORD *)(&Start));
g_pDevice->SetRenderState(D3DRS_FOGEND, *(DWORD *)(&End));
}
else
{
// This is what you want to be using, i.e. D3DFOG_LINEAR is *not* your fog mode
g_pDevice->SetRenderState(D3DRS_FOGVERTEXMODE, Mode);
g_pDevice->SetRenderState(D3DRS_FOGDENSITY, *(DWORD *)(&Density));
}[/source]

Share this post


Link to post
Share on other sites
[CODE]

g_pd3dDevice->SetRenderState(D3DRS_FOGENABLE, TRUE);

// Set the fog color.
g_pd3dDevice->SetRenderState(D3DRS_FOGCOLOR, 0x00ffffff);

// Set fog parameters.

g_pd3dDevice->SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_EXP2);
g_pd3dDevice->SetRenderState(D3DRS_FOGDENSITY, 100);
[/CODE]
in this variant - i have white screen too

Share this post


Link to post
Share on other sites
Density also needs the float/DWORD trick, and should be quite low - it's a long time since I've used fixed pipeline fog, but if memory serves you should start at about 0.1 and work downwards from there.

Share this post


Link to post
Share on other sites
I think he means like this:

float fogStart = 0.1f;
float fogEnd = 1000.0f;

device->SetRenderState(D3DRS_FOGENABLE, TRUE);
device->SetRenderState(D3DRS_FOGSTART, *(DWORD *)&fogStart);
device->SetRenderState(D3DRS_FOGEND, *(DWORD *)&fogEnd);
device->SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);

Share this post


Link to post
Share on other sites
Fog start and end are not valid for exp2 mode. You need to set density the same way that you were originally setting start and end in your first post, like so:
[CODE]
float Density = 0.001f;
g_pd3dDevice->SetRenderState(D3DRS_FOGDENSITY, *(DWORD *)(&Density));
[/CODE]

Share this post


Link to post
Share on other sites

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