Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problem with fod

Started by Arkanoid Apr 3, 2012 at 7:21 PM 9 replies 1.8k views
Original Post
Arkanoid
Arkanoid
I found this sample from msdn how to create fog:






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));


but i see only a white screen, without any objects...where is wrong here?
Waterlimon
Waterlimon
should 1000 be 1000.0f?
o3o
InvalidPointer
InvalidPointer
You copied the 'linear fog' code instead of the 'exponential fog' code smile.png

[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]
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
Arkanoid
Arkanoid


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);

in this variant - i have white screen too
InvalidPointer
InvalidPointer
Have you experimented at all with adjusting the fog density value? It's entirely possible that things are working as intended though it looks different from what you want.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
21st Century Moose
21st Century Moose
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.
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
Arkanoid
Arkanoid
g_pd3dDevice->SetRenderState(D3DRS_FOGDENSITY, 0.001f);

and white screen too...
froop
froop
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);
21st Century Moose
21st Century Moose
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:

float Density = 0.001f;
g_pd3dDevice->SetRenderState(D3DRS_FOGDENSITY, *(DWORD *)(&Density));
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
froop
froop
oops sorry for adding even more confusion. wanted to point out the float/DWORD thing

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.