View Full Version : Three-pass rendering with fog
01-05-2002, 03:10 AM
My problem is related to the age-old problem of fog with blending. I'm trying to figure out how to use 3 passes in my rendering; one to draw the scene with the base texture, one to blend in a detail texture, and a third pass to add in fog. If possible I'd prefer to let OpenGL do the fogging work but if necessary then software calculations are an option. How can this be achieved? (I'm not fond of white fog - if I was, I'd just use 2-pass rendering.)
Disable lighting, texturing, and similar functions that affect the color of a fragment.
Redraw the geometry that needs fog, and for each vertex, set the color to glColor4*(r, g, b, a), where r, g and b is the color of the fog (this is probably three constant values), and a is the fog density (based on the distance from the viewpoint, 0 is no fog, 1 is full density).
Use the blending mode glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). Also set depth function to glDepthFunc(GL_EQUAL);
01-05-2002, 12:30 PM
Hmm... the entire scenery gets tinted the fog colour nomatter what the alpha is, although the fogging does work. Any ideas?
01-05-2002, 05:06 PM
OK, so you have problems with blended alpha in the scene when you want to add fog in a subsequent pass. I assume this is the issue, otherwise it should 'just work'.
You'd need to the rendering for all passes of the opaque scene then for the blended stuff and trim the alpha back with an alpha func. You can use stencil when doing the alpha pass to limit the scope of the fog to the alpha tested fragments if you don't have multitexture for this stuff.
Hope that makes sense to you. It still won't be perfect unless you use multitexture, the blend region around things like trees might look like they have fogged halos without multitexture, so you might want to work on avoiding the multipass on stuff like trees any way you can. For example they don't need detail texture in a second pass right? So why not just fog them as normal, same with other transparent blended stuff.
01-06-2002, 03:00 AM
Well, using multitexturing and GL fog works perfectly. However, I'm wondering whether it's safe to assume that nearly all users will have a graphics card that supports multitexturing, or whether I'll have to come up with a way to do fogging with standard multi-pass rendering. Any views?
01-06-2002, 05:16 AM
Originally posted by DeathWish:
However, I'm wondering whether it's safe to assume that nearly all users will have a graphics card that supports multitexturing, or whether I'll have to come up with a way to do fogging with standard multi-pass rendering.
All NVidia cards since the TNT have ARB_multitexture. So do the Voodoo3 and up, the Matrox G400 series and up, the ATI Rage128 and Radeon series, the Kyro, and so on... Don't go through a lot of effort to support multipass -- it's completely pointless, IMO.
01-06-2002, 10:18 AM
Even the entirely pathethic Intel i810/i815 "built in 3D graphics" (based on i740) has multi-texturing (as does the Voodoo2). You can't call it a 3D accellerator without it, and haven't been able to for the past few years, really.
Now, the i810 is slow enough that you can't really do anything interesting on it anyway, but I thought I'd mention it.
Um, what if you want to do 3+ passes? That would cut out everything but GF3+, Radeon+ and Kyro+ IIRC (corrections welcome :]). 4+ cuts out Radeon. 5+ cuts out GF3.
Are there really that many applications that do everything in 2 stages?
01-06-2002, 01:23 PM
I think you misread. I said that unless you have multitexture things wouldn't look OK. i.e. if you go to multipass which was what your question was about, you will experience problems if you have transparent geometry in the scene. These are classic zbuffer + blend multipass issues, there's no good solution, the kind of PC hardware that has the features to solve this (multisample + alpha to mask) also has multitexture.
[This message has been edited by dorbie (edited 01-06-2002).]
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.