PDA

View Full Version : Is fog affected by the number of tris?



benwestgarth
08-01-2005, 09:47 PM
Hi there,

I have a game dungeon which I am adding fog to. The initial results were very unsatisfactory - the fog appears to work in places but in others it is just a blank sheet. However I noticed that when I increased the number of tris with which the dungeon floor is drawn the fog effect improves. I am not quite sure how fog is computed so is this to be expected? Is there any way I can have my floor drawn with two tris and still get a good fog effect?

Thanks, Ben

memfr0b
08-01-2005, 11:34 PM
Originally posted by benwestgarth:
Is there any way I can have my floor drawn with two tris and still get a good fog effect?Try glHint(GL_FOG_HINT, GL_NICEST). It should enable per pixel fog calculation, if your implementation supports that.

benwestgarth
08-02-2005, 01:13 AM
Thanks,
I already tried that and it made no difference. Is a geforce4 mx440 recent enough to utilise per pixel calculations for fog? Maybe not.

UrbanLegend
08-02-2005, 01:55 AM
How large are your tris/polygons, are you using large poly's for the wall/floors etc or lots of small sections.

You should find that Fog looks better with higher tessellation

benwestgarth
08-02-2005, 01:38 PM
The tesselation on the floors and walls is very low. 2 large triangles per surface to be specific. I made the assumption that it wasn't important since they are completely flat and square surfaces. In general should I tesselate my surfaces more? Is there a performance penalty for doing so?

Komat
08-02-2005, 03:37 PM
Originally posted by benwestgarth:
I made the assumption that it wasn't important since they are completely flat and square surfaces.
In general should I tesselate my surfaces more? Is there a performance penalty for doing so?If per pixel fog is not supported, fog factor is calculated in each vertex and interpolated across the triangle so in that case the smaller the triangles are the better the result is.

Unless you increase number of triangles by too much the performance penalty caused by sending more vertices to OpenGL should be slight. What is high depends on method used to render the geometry. If you are using vertex array, vertex buffer objects or display lists the value may be much higher than when immediate mode is used.

If you have sufficiently capable hw (for simplicity it has to support multitexturing and have one additional texture unit to whichever number of texture units you are using normaly), you can emulate per pixel fog by use of additional texture that does encode fog factor and fog color for various distances.
In that case you need to set texture coordinage generation mode for the texture unit containing this texture in such way that generated texture coordinates will in some way correspond to distance of vertex from eye plane.
Then you need to setup hw to calculate:

unfogged_color.rgb * ( 1 - fog_factor ) + fog_color.rgb * fog_factorFor fog color and fog factor encoded in the texture it will be

unfogged_color.rgb * ( 1 - fog_texture.a ) + fog_texture.rgb * fog_texture.awhich is what texture function GL_DECAL does.

benwestgarth
08-02-2005, 08:07 PM
Thanks for the answers guys. I guess I'll have a look at the suggested options.
Peace.
Ben