Log in

View Full Version : OpenGL Fog and large triangles


Nemesis
07-01-2004, 03:27 PM
Hi,

Has anyone experienced problems using OpenGL fog with large triangles. We are getting funny results e.g. with a large water surface quad. My understanding is that fog is calculated per vertex and interpolated across.. hence the problem.

What's your take on this?

Jim Buck
07-01-2004, 03:39 PM
You are right - per-vertex lighting. You would either have to break it up if it's not getting the effect you'd like or write some pixel shader for a finer granularity of calculation. It's the same problem when you are lighting large polys with OpenGL (or any API) lights. If you have a light pointed in the center of the poly, it will still be rendered dark-ish since it's the corners that get lit.

Nemesis
07-01-2004, 03:43 PM
Lighting isn't such a problem actually, especially since the water surface quad is blended. Fogging however, behaves in a very weird manner, moving back and forth when panning the camera!

The techie in the team will be looking into creating a fog algorithm to replace OGL fog. As a last resort however, I will be forced to tessellate the large quads into smaller ones.

Jim Buck
07-01-2004, 04:35 PM
Well, I believe the fogging is just simple depth-cueing.. which means that it's camera relative (using the transformed Z). It will change as you move the camera. But, back and forth? That sounds odd. Any screenshots? (Or better - a movie?)

Nemesis
07-01-2004, 04:37 PM
Actually, I can show you a demo. Check my post here (http://www.dexterity.com/forums/showthread.php?s=&threadid=3425&highlight=perihelion).

CrystalSquid
07-02-2004, 02:13 AM
Vertex based fog uses the standard gouroud shading interpolaters - which have one major issue, they interpolate LINEARLY across a poly (not perspective correct).

As Jim Buck says, you get the same effects with lighting, but ususally you don't notice as the colours tend to be fairly close, and they blend with the textures (which usually are perspective correct) so it usually fools the eye.

'Table based' fog (supported on some cards) allows you to set fog values based on the z of a pixel, and this gives 'perfect' results, but can be slow, and I'm not sure how you set it up in OpenGL.

Hope this helps,

- Dom

Jim Buck
07-02-2004, 09:33 AM
I just ran the demo, and water seemed fine on my machine. It was bright as it was "fogged out" far away, but that was fine. Moving back and forth, I noticed nothing weird. I'm not sure what you are seeing on your machine, but is the effect that you are seeing something to do with the fact that the water polygons are semi-transparent?

Nemesis
07-02-2004, 01:32 PM
I am aware that the water becomes whiter rather than fade into the fog colour. I presume that's because additive blending of the water material is done after fog blending is calculated... I have no idea what possessed the OGL people to do such a thing! :) It would be fine the other way round i.e. additive blending first, then fog blending after.

As for the moving fog anomaly, it in fact occurs only on some machines and not others. I suspect that some drivers mess up vertex fog colours when clipping polygons to the view frustum or something of the sort.

Jim Buck
07-02-2004, 01:44 PM
Hmm.. makes me wonder if older OpenGL drivers are buggy after all. Are these older machines that this problem occurs on? I would be curious if DX does the same or not.

Nemesis
07-02-2004, 02:00 PM
Well.. my machine is a P3 with a Geforce 4 MX 440.. so I guess it's not the most modern card in the world.

Henrik
07-04-2004, 06:30 AM
The explanation is probably simply that many older card interpolated gouraud shading linearly while modern cards use perspective correction (yes, even for color, not only for texcoords).

Moral of the story is, avoid really huge polygons.

CrystalSquid
07-04-2004, 09:52 AM
Are you using the GL hints for the fog?

(from: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=16)

Eric Desrosiers Adds: Little explanation of glHint(GL_FOG_HINT, hintval);

hintval can be : GL_DONT_CARE, GL_NICEST or GL_FASTEST

gl_dont_care - Lets opengl choose the kind of fog (per vertex of per pixel) and an unknown formula.
gl_nicest - Makes the fog per pixel (look good)
glfastest - Makes the fog per vertex (faster, but less nice)


If you don't specify one it will probably use the 'DONT_CARE', which could be either. Some (better) cards will default to per-pixel if they do it fast enough, others to per-vertex.

- Dom

Nemesis
07-10-2004, 07:01 AM
Guys, thanks for the tips!

Sorry for my delay in replying.. I was in Basingstoke, UK for the past week on a business trip. I'll pass on your tips to the 3d engine man in the team.

Cheers,