Skip to main content
GameDev.net gamedev.net
🔒 Locked

Fog and MultiTexture : Bug?

Started by mikeman Jul 15, 2004 at 5:21 AM 6 replies 1.1k views
Original Post
mikeman
mikeman
First of all,take a look at this thread,because that's what's got me thinking.I'm working on a GFX5200. Anyway,I made a demo to check out how fog works with multitexture,and I found a really weird situation.I made a terrain with water,and then I used fog with glEnable(GL_FOG).The water is just a huge flat quad.Everything was fine,until I decided to use multitexturing in order to use lightmap too on the terrain.Well,if I enable more that one texture units,the fog just don't work right with the water.It seems that there is a problem in the calculation of the fog coordinate,and that's really visible when I just rotate the camera.I even tried it with a totally white lightmap,and the problem remained.I disabled blending,in case that was the problem,but with no luck.Note that the whole scene is rendered with a single pass. If I simply disable one of the texture units(no matter which one),then fog works fine. Some will say that the problem should be fixed if I tesselate the water more.That's true,since the terrain,that is highly tesselated,works fine.But,as I said,the fog worked with the water when I wasn't using multitexturing.So the problem must be somewhere else. Anyway,I wrote a vertex shader(no fragment shaders) that substituted the fixed pipeline and set the FogCoord myself: gl_FogFragCoord=-V_eye.z; Everything works perfect,with multitexturing and fog.Now,if,inside the vertex shader,I clamp the FogFragCoord to 0.0,then I have the exact same problem as before.So,I think that 99% it's a bug:for some reason,the vertex fixed pipeline clamps the FogCoord to 0.0 when multitexturing is enabled,thus causing problems on the interpolation of the FogCoord. Has anyone encountered this?What's your opinion?
vincoof
vincoof
You may be right. I fact, fogging may even be emulated by texture stages. Have you enabled multitexturing AND fogging in your vertex program "that works" ? I think it will not work.

I've heard of a similar problem with user-defined clipping planes with GeForce 1-2. If the number of clipping planes + the number of enabled texture units is greater than the graphics cards' texture unit limit, then the framerate drops. Tha'ts because use-defined clipping plane is emulated at the texture stage level, and when there is not enough texture stages, a software fallbak path is used instead.

However, I don't think it is a "bug". It is just a strange behaviour. Why not a bug ? Simply because the way fog contributes computed (ie per-vertex or per-fragment) is just a "hint" in OpenGL. And the way you describe clamping to 0.0 means that fog contribution is per-vertex, not per-fragment.
mikeman
mikeman
Quote:
Original post by vincoof
You may be right. I fact, fogging may even be emulated by texture stages. Have you enabled multitexturing AND fogging in your vertex program "that works" ? I think it will not work.

I've heard of a similar problem with user-defined clipping planes with GeForce 1-2. If the number of clipping planes + the number of enabled texture units is greater than the graphics cards' texture unit limit, then the framerate drops. Tha'ts because use-defined clipping plane is emulated at the texture stage level, and when there is not enough texture stages, a software fallbak path is used instead.

However, I don't think it is a "bug". It is just a strange behaviour. Why not a bug ? Simply because the way fog contributes computed (ie per-vertex or per-fragment) is just a "hint" in OpenGL. And the way you describe clamping to 0.0 means that fog contribution is per-vertex, not per-fragment.


As I said in my first post,when I enable the vertex program,the fog DOES work with multitexturing perfectly.The fog in both cases(fixed pipeline and vertex program) is per-vertex.To clarify,there are 3 cases:

1)Fixed vertex pipeline and single texturing:Fog works fine
2)Fixed vertex pipeline and multitexturing:The fog coords seem to be incorrect.
3)Vertex program and multitexturing:The fog works as expected.

Note that when I use the vertex program,I don't change anything else.Also,I don't use fragment shaders.After the vertex program executes,the GL pipeline handles the fragment processing and everything else.I just use the vertex program to "emulate" the fixed vertex pipeline.The vertex program does exactly what the fixed pipeline should do according to the specs.
vincoof
vincoof
Ok. Then it looks like a bug. ^^

It's really weird. It looks like the old time where OpenGL was not specified to use negative depth in fog computation. It was back in OpenGL1.0, yes OpenGL 1.0 !! (the spec is so old that it's not even available on the Internet).

Anyway, you'd better ask opengl.org in the advanced forums, visited by where NVIDIA engineers and drvier developers.
Meanwhile you could post an executable so that we can test it in a wide variety of hardware (including non-NVIDIA hw) and report our result with graphics card / driver / OS. What do you think of it ?
mikeman
mikeman
Yeah,I was going to post this on opengl.org earlier(I have an account there already),I've just been busy for a while.As for the executable,I will work on it to make it toggle between situations(fog,vertex program,multitexture),and I'll post again when ready.It will need GLSL support,though.
mikeman
mikeman
Ok,I've uploaded the demo:
http://www.angelfire.com/games5/mikeman/FogTest.zip
It requires GLSL,so if you get a violation error or something,it's probably because your card(or drivers) don't support it.

Keys:

LEFT/RIGHT ARROW: Turn left/right
UP ARROW: Move forward
D,C: Move up/down
F,M,V: Toggle Fog,Multitexture and VertexShader


Aurora3D
Aurora3D
I've had similar problems with both blending and fog when using the second color register in Cg programs. I'm guessing that's where OpenGL performs both operations. I try not to touch it anymore.
AndrewAurora Interactivewww.aurora3d.com
vincoof
vincoof
too bad my drivers don't support GLSL here.
I'll try it later on another computer. Cheers

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.