Archived

This topic is now archived and is closed to further replies.

code_evo

OpenGL having trouble with standard openGL fog, when to render?

Recommended Posts

Hey all, so I'm 3 weeks away from the due date of my game (senior college project) I've been away from the boards for the last few months just going really hard. Everything is going great though, except fog.... basically i set the projection matrix, set the perspective, set the camera, then switch to modelview and render the track and cars. What I want is the fog distance to follow the player, so the fog horizon is always the same, just like a skybox that always is centered around the player. But right now when I render the fog it is static and you drive into it. So how can I "transform" the fog? Thanks so much. ps, I'm using standard openGL fog functions, not volumetric or anything of that sort. [edited by - code_evo on March 29, 2004 10:52:59 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by code_evo
basically i set the projection matrix, set the perspective, set the camera, then switch to modelview...


Unless you know what you''re doing, never, ever, do the viewpoint and object transform in the projection matrix. The reason is that fogging, among other things, is performed in eye space, that is, between the modelview and projection matrix. That means that if you put the viewpoint/object tarnsform in the wrong place, fogging will be wrong also.

Share this post


Link to post
Share on other sites

Can you expand? I''m not doing object transformations in the projection matrix, I set the persepective and set the camera. So i''m assuming your saying I should set the camera in the modelview matrix? I was never aware of that.

Thanks.

ps, how do I post images?

Share this post


Link to post
Share on other sites
So I just tried setting the camera in the modelview matrix, and I have major lighting issues (the lighting on the car doesnt update, and the lighting on the track is dynamic[is shouldnt be]) The fog is fine though. And I tried setting the viewport in modelview and I see no difference (fog is still messed up).

[edited by - code_evo on March 29, 2004 10:41:52 PM]

Share this post


Link to post
Share on other sites
So, you mean the lighting sortof moves with the viewpoint?

If so, I guess you never update the light position each frame, but only once during initialization. Or, you update the light position in the wrong place.

When you set the light position, the position will be transformed by the modelview matrix at the time you set it, and then OpenGL will store the coordinate as the lights actual position in eyespace. This means that if you want the light to be static in the scene (street lights for example), you have to set the position after you set the viewpoint transform. If you want the light to move with the viewpoint (holding a flashlight in a first person shooter for example), set it just before setting the viewpoint transform.

I suggest you make a small test program where you can move around in, say, a grid of spheres or so with a light and fog. Experiment with putting the viewpoint transform in the projection matrix vs. the modelview matrix, and setting light right before vs. after viewpoint transform, and see how the lighting and fogging behaves.

Share this post


Link to post
Share on other sites

yes I''m only setting the light position once, thanks a lot. I didnt realize the light position got transformed with the modelview matrix.

/jeff

Share this post


Link to post
Share on other sites