Skip to main content
gamedev.net
🔒 Locked

Simple Fog Problem

Started by Programmer101 3 replies 1.6k views
Original Post
Programmer101
Programmer101
Okay, I have just decided to put fog into a program I am making, but all polygons become the fog color with no depth or textures(it seems so simple yet I can't place my finger on it). Here are my present parameters for fog: g_pD3DDevice->SetRenderState(D3DRS_FOGENABLE, TRUE); g_pD3DDevice->SetRenderState(D3DRS_FOGCOLOR, 0x00AAAAAA ); g_pD3DDevice->SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_LINEAR); g_pD3DDevice->SetRenderState(D3DRS_FOGSTART, 100.0); g_pD3DDevice->SetRenderState(D3DRS_FOGEND, 1000.0); g_pD3DDevice->SetRenderState(D3DRS_FOGDENSITY, 0.1); g_pD3DDevice->SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_NONE ); Here is a picture of what I am talking about: (lol, 4 fps) Thnx
jollyjeffers
jollyjeffers
SetRenderState() doesn't have a floating point overload - the second parameter is always DWORD.

I'm pretty sure if you work through the dword->float binary casting integer values of 100 and 1000 will work out as extremely small floating point values so close to zero as to not matter and therefore fogging your entire display!

Basically you need to pack 32bit IEEE float data as a 32bit unsigned integer:

float fValue = 0.1f;
DWORD dwValue = *reinterpret_cast<DWORD*>(&fValue);


ISTR some of the SDK samples used to include a "f2dw" macro that did this conversion in a slightly neater way...

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
Programmer101
Programmer101
Cool, thanks. All I had to do was change my fogstart and fogend to:

g_pD3DDevice->SetRenderState(D3DRS_FOGSTART, *(DWORD *)&vertex_fogstart);
g_pD3DDevice->SetRenderState(D3DRS_FOGEND, *(DWORD *)&vertex_fogend);

I now have a new problem with my fog. I have a semi-sphere for my sky and I want it to blend with the horizon. I was using fog but...when I have fog enabled it fogs out the whole semi-sphere. Does anyone know if I can disable fog for part of the semi-sphere or if I can set the max height for the fog?
Draconis_9
Draconis_9
I've found that if you reduce the fog end and put up the fog density to 0.5ish it works quite well

Topic Locked

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

Sign in to reply to this topic.