PDA

View Full Version : fog not working correctly.



chronozphere
23-02-2007, 05:10 PM
Hi all :)

I'm implementing vertex fog, but it's not working correctly.
Here is my code:


fogstart := 1;
fogend := 5;
with fD3DDevice do
begin
SetRenderState(D3DRS_FOGENABLE,1);
SetRenderState(D3DRS_RANGEFOGENABLE,1);
SetRenderState(D3DRS_FOGCOLOR,D3DCOLOR_XRGB(128,12 8,128));
SetRenderState(D3DRS_FOGVERTEXMODE,D3DFOG_LINEAR);
SetRenderState(D3DRS_FOGSTART,PDWORD(@FogStart)^);
SetRenderState(D3DRS_FOGEND,PDWORD(@FogEnd)^);
end;


I have tried many value's for fogstart and fogend. When the values are too high, the whole scene was rendered without fog and when i set the too low, the whole scene was rendered gray. :(

When i finetuned the values, the scene was fogged but all objects (far and near) were fogged with the same density/value/grayness.
When i used values (1,1.5) the fog seemed to look better.
The only problem was that the position of the clear circle was the area pointed by the lookat vector of my camera.
So i can see a circle of my scene with fog around it.
the camera must be IN that circle and must not look at it... it just drives me crazy. :x

Can a weird camera setting be the cause of this, or some wierd matrices. Or are my fog settings wrong

Can someone help me out?? :?

{maybe i can post some pics later}

Huehnerschaender
23-02-2007, 06:27 PM
Can it be that you set the camera after you set the fog?

If so, try it vice versa...

chronozphere
23-02-2007, 07:37 PM
Yeah thanx... that sounds like a logical sollution ;)

I read somewhere that the fog effect is based on the view matrix.
When vertices are transformed to the view matrix, the fog can be easily computed by using the Z coordinates.
But the problem is that i multiply all my matrices and send them to D3D as World matrix,
So the view matrix is propably an identity matrix.
That's why the fog effect didnt work. :)

I have to rewrite my matrix code to solve this issue.
I'll let you know wheter it works after these changes. ;)

chronozphere
24-02-2007, 12:04 PM
I've rewritten my code and the problem seems to be solved.... thanx :)

So multiply my view/proj/world matrices and pass them as world matrix wasn't a good idea after all.

Huehnerschaender
24-02-2007, 12:32 PM
:)

Glad to hear the problem is gone...