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?
I already tried that and it made no difference. Is a geforce4 mx440 recent enough to utilise per pixel calculations for fog? Maybe not.
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
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?
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_factor
For fog color and fog factor encoded in the texture it will be
unfogged_color.rgb * ( 1 - fog_texture.a ) + fog_texture.rgb * fog_texture.a
which is what texture function GL_DECAL does.
Thanks for the answers guys. I guess I’ll have a look at the suggested options.