Problem with fod

Started by
9 comments, last by Arkanoid 12 years ago
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?
Advertisement
should 1000 be 1000.0f?

o3o

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.


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
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.
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.

g_pd3dDevice->SetRenderState(D3DRS_FOGDENSITY, 0.001f);

and white screen too...
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);
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.

oops sorry for adding even more confusion. wanted to point out the float/DWORD thing

This topic is closed to new replies.

Advertisement