• Advertisement
Sign in to follow this  

Fog question

This topic is 4146 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been trying to add in fog to my game with a single quad thats in a circle and surrounds my view and is place X amount from the view so I can try and hide the popping in and out of my units and terrain. Problem is I don't like how it looks like a wall and not much depth or volume to it. So my question is how does one solve that problem? Do I need to make a few more circle behind each other to add some more depth? And does anyone have a good shader that covers some decent looking fog? Thanks

Share this post


Link to post
Share on other sites
Advertisement
D3D or OpenGL?

Both have fog done in-hardware, you just turn it off/on and set the near/far zone and the falloff type (linear, exp, exp2)

First hit on google was this
see if that works for d3d

First hit on google for OpenGL was this

HTH
-Michael g.

Share this post


Link to post
Share on other sites
Yes I know they both do, and how to use them, my question is how to get a more volumetic looking fog so it looks deeper. That's why I was asking do I need to have a few rows of polygons so spread the fog depth over a few row vs. one row of polygons? BTW I am using GLSL so FFP fog doesn't work unless you do it in the shader...

Share this post


Link to post
Share on other sites
"I have been trying to add in fog to my game with a single quad thats in a circle and surrounds my view and is place X amount from the view so I can try and hide the popping in and out of my units and terrain."

This sounds like a bad method for this.. i reccomend instead that you use a skydome or skybox with a fog-colored horizon.. then just use the fog to fade into that..

As far as fog goes, fog is fog.. there are various formulas to calculate it, but it all looks mostly the same unless you use some kind of pixel fog..

But none of these will help in your case i think. but then you havent described your problem very well anyway..

Share this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
Yes I know they both do, and how to use them, my question is how to get a more volumetic looking fog so it looks deeper. That's why I was asking do I need to have a few rows of polygons so spread the fog depth over a few row vs. one row of polygons? BTW I am using GLSL so FFP fog doesn't work unless you do it in the shader...


There s something called fog coordinate extention for volumetric fog in opengl

see here

http://oss.sgi.com/projects/ogl-sample/registry/EXT/fog_coord.txt

Share this post


Link to post
Share on other sites
Yeah that is probably what I am looking at using is that extension... What I am trying to do is the horizon where the land and sky or water plane is at I would like to cover that up with this fog but allow it to have some depth to it. So I am thinking about taking my current circle I have with one quad that faces me all the time and is at the point where it meets the water and sky and making them all cubes and using this extension with that to add the depth so I can control the fading and how far away I want it? Not sure if this clears up my issue? Thanks

Share this post


Link to post
Share on other sites
that probably works, you got a 2d quad parallel to the ground and each vertex has its own fog coordinate value, just make sure you don t overlap the quads this might lead to artifacts


maybe have a look at gametutorials.com they had a tutorial about this a few years ago

Share this post


Link to post
Share on other sites
Well I think its working but I still don't like the way it looks 100%. I think the problem is the effect has a wall look to it. I am thinking I am going to need to use a particle engine and make some fog with that so it looks less like a wall and more natural? What do you think? Thanks

Share this post


Link to post
Share on other sites
MARS_999, have you considered doing the fog as post-render fullscreen pass?

If you can capture the z-buffer to a texture, then you can use that in a fragment shader to computer distance fog on a per-pixel basis, as an overlay to the scene.

Share this post


Link to post
Share on other sites
Quote:
Original post by Exorcist
MARS_999, have you considered doing the fog as post-render fullscreen pass?

If you can capture the z-buffer to a texture, then you can use that in a fragment shader to computer distance fog on a per-pixel basis, as an overlay to the scene.


Interesting, I have just gotten a depthbuffer read into a FBO and have the scene rendered into a texture. So now do you want me to just render a single quad? like a overlay for UI or some other method? Thanks for the tip hopefully it works out like I need it to.

Share this post


Link to post
Share on other sites
Exactly, if the FBO contains a copy of the depth buffer, pixel for pixel, then you can use it as a texture on a single fullscreen quad which stresses across the screen. Then in your shader, you output a colour where you pick the alpha based off the depth off each pixel. If you want to not colour over a skybox etc, just kill the fragment if the depth is 1.0.

Share this post


Link to post
Share on other sites
Quote:
Original post by Exorcist
Exactly, if the FBO contains a copy of the depth buffer, pixel for pixel, then you can use it as a texture on a single fullscreen quad which stresses across the screen. Then in your shader, you output a colour where you pick the alpha based off the depth off each pixel. If you want to not colour over a skybox etc, just kill the fragment if the depth is 1.0.


Hmmm think I am close but must be missing something. The quad is all foggy, but not what I was looking for. Maybe its my shader?


uniform sampler2D fogDepthmap;

void main(void)
{
vec4 color = texture2D(fogDepthmap, gl_TexCoord[0].xy);
if(color.a >= 1.0)
discard;
gl_FragColor = color;
}




Thanks

Update,
Exorcist I am not sure if I pointed this out but this is for a RTS sytle game and starting to think this method only works for FPS? Thanks again for the help so far.

[Edited by - MARS_999 on October 19, 2006 1:05:24 AM]

Share this post


Link to post
Share on other sites
The problem is that you're not doing anything with the color you just read. If fogDepthmap contains the depth buffer, you'll need to use it's values to calculate how much fog you'll output. Right now you are just returning the depth buffer values.

You must return a constant fog color with an alpha value that is calculated based on the depth value stored on the depth buffer (the higher the distance, the higher the alpha value). You also need to turn on alpha blending before drawing the full screen quad.

Share this post


Link to post
Share on other sites
Actually, it sounds like you most likely just aren't using the hardware fog correctly.

Volumetric fog *might* be what you're looking for, but from all your descriptions, it doesn't sound like it.



Ah, you say you're making an rts - is it an isometric type view (viewed from above for the most part)?
If so you might want to apply volumetric fog - but if you have the equivalent of a heightmap, you can always do a cheap hack by applying vertex fog based on vertex absolute height.
This would give a radiation fog type effect.
The exact math would be to perform a raytrace through the fog volume (which, in this case, would be a rectangular cube-like shape) and calculating the fog volume's near hit and far hit...

Actually, if you're not doing volumetric zones, this become *very* easy in a pixel (or vertex for that matter) shader. If the camera's absolute height is above the volume, calculate the distance to the height=fog volume height, using the view normal, then use the current pixel's z-buffer value (or vertex transformed xyz to find the distance). Subtract the dist to volume from the dist to vertex/pixel, and viola! nice murky foggy stuff :)


-M

Share this post


Link to post
Share on other sites
I would like to thank everyone here for help so far. I would like to point out that I am not trying to add fog to my overall terrain but in Thr33d's pic where the sky line meets the terrain I am trying to cover that up with a fog wall if you will. I would also like to have the fog wall have a depth to the fog so you can barely see units/terrain in the distance. So far I have a wall that is in front of this skyline and where the terrain meet, but looks to old school where the fog wall hits the terrain where its sliced through at it looks like a hard line.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement