PDA

View Full Version : Alternative to "order independent transparency"



MacReiter
05-08-2003, 08:18 AM
This may be somewhat naive, but I think it solves all of the cases that I want. If I have overlooked something, *please* set me straight...

First, let me specify that my "transparent" surfaces are more like (stained) glass or filters. The color of the surface describes what percentage of which components of light it will allow to pass. A colored piece of glass can NEVER add a color to something. Consider a piece of red glass with a blue object behind it. All you will see through the glass is black.

By contrast, alpha-blending is more like a gauzy surface. Alpha-blended surface CAN add colors to things. If you had a thin piece of red fabric with a blue object behind it, it would tend to look purple.

"Colored glass" transparency is more accurate than "alpha blended" transparency for windows, cockpits, etc. It does lack the ability to "reflect" color back at you -- a real piece of red glass could still look slightly red even with no light behind it, due to reflections and internal reflections. This is especially noticeable if you are trying to do, say, a yellow forcefield around a spaceship -- with no light behind the shield, you won't be able to see the shield itself, and it will just look like you tinted the spaceship itself yellow. But, if what you are trying to render is a complex scene with plenty of light behind your objects (say, a landscape or a white "virtual bench" for a CAD system), then you will be able to see the transparent object just fine.

On the up side, your textures allow controlling the amount of transparency on a per-color basis, instead of just a per-pixel basis with alpha blending.

Alpha blending is order dependent, which is what leads to all of the headaches. Colored-glass transparency is simply modulation, which is just multiplication, and as we all know, multiplication (at least of scalars) is order-independent by nature. So if all of your transparent surfaces are more like colored glass than like gauzy fabrics, you can use modulation and render them in any order you want.

Some notes:
1. You probably want to disable lighting calculations. Modulation can darken things VERY quickly, and if the lighting calculation decides that your glass isn't very well lit, it'll end up looking like smoked glass. Better to simply turn off lighting (or deliberately feed it messed up normals so that it tends to oversaturate, but "there there be dragons...")
2. Your "colored glass" textures will tend to look wildly oversaturated if you look at them in a paint program. That's OK. You want them to look like a stained glass window sitting in front of a blinding spotlight. Otherwise you'll darken things too much.
3. And lastly, how to get modulation effects in blending, which many of you probably already know (but which I had somehow overlooked until recently): glBlendFunc(GL_DEST_COLOR, GL_ZERO) or glBlendFunc(GL_ZERO, GL_SRC_COLOR) (both will do the same thing)

I haven't really thought about it, but replacing GL_ZERO with some other value might provide the ability to handle some of the "reflected color" aspects. Of course, it would probably also ruin the "order independence" of the process...

I only bring this up because none of my OpenGL programming resources ever mentioned using this for transparency. They all talk about the alpha channel and depth sorting, which is just hideous if you are trying to build a object oriented scene graph and don't want to require objects to submit lists of polygons to a global depth sorter/renderer component. It just seems like a tremendous amount of effort has been put forward to make alpha blending work "right" when modulation was just sitting there for the taking. I apologize if this was well known, and I apologize _profusely_ if this approach has well-known problems other than the "reflected color" one I mentioned. I would appreciate any advice from those of you who might have tried this approach.

Thanks,
Mac

MacReiter
05-08-2003, 09:38 AM
OK, sorry, guess I'm a goomer. Just 'coz none of my BOOKS mention it, doesn't mean that it hasn't been done several times out on the net. I just hadn't managed to find it. (why is it only AFTER you make a fool of yourself in a public forum that you find the giant pile of web sites?)

Anyway, I did find this particular web site which uses the multiplicative mode I mentioned followed by an additive mode that inserts specular highlights ("white" highlights on the front, and "glass colored" highlights off of back surfaces). It's more useful than my post, since it gets more done in less space. http://www.opengl.org/discussion_boards/ubb/rolleyes.gif

Since I found it useful, thought I would pass it on: http://www.airdmhor.gen.nz/blancmange/notes/programming/3dgfx/3dgfx.html

Mac

Jan
05-08-2003, 09:54 AM
You didnīt make a fool of yourself, since you had an idea which might be usefull to some people (me maybe). Also you gave us a link to a page which might me interessting.
Anyway, there ARE situations when you never get around depth-sorting. So most applications will still have to sort by depth (for example for light-flares and such additive stuff).

Jan.

MacReiter
05-08-2003, 06:11 PM
Well, I finally got home and got to play with the transparency example from the previously mentioned website.

Once I fixed a problem where I was positioning the "headlight" (makes sense after you read the website) BEFORE moving my camera instead of afterwards (doh), it worked pretty well. As given, it produced (at least for me) an object that appeared to be made out of amber -- fairly deep and rich.

I wanted to see how hard it was to get a lighter "energy field" or "translucent plastic" effect. What hung me up for awhile was that you need to make good use of the ambient lighting. The diffuse lighting with the "headlight" does provide good pseudo-thickness cues, but it tends to render everything too dark, or, more to the point, with too much contrast between face-on and edge-on areas. The lighting model is perfect for conventional lighting, where you want that much contrast, but since you'll be multiplying these values against the background, it just makes things too dark too fast.

So I cranked up the ambient material for the first pass, to lighten things up overall and reduce the contrast. Nothing seemed to happen. Then I paid a little more attention to the code and remembered that he had set the ambient component of the LIGHT to 0,0,0, so it didn't matter what the ambient reflectivity of the MATERIAL was... I cranked up the ambient on the light, and I got a very nice see through plastic yellow spaceship (using a RomulanBirdOfPrey.cob trueSpace model from avalon.viewpoint.com to play with).

This technique gives an excellent (mostly) order-independent glass/jewel/crystal/thin-plastic/energy-field effect, at the cost of only one more transparency rendering pass (to overlay the specular effects). I say "mostly" order-independent, because I suspect that the specular effects of multiple objects that are in front of each other will probably get calculated incorrectly -- the last one drawn _may_ provide tinting over any earlier ones. Or it may not. If you do the first pass for all transparent objects, the tinting pass is all multiplicative and order-independent. Then you do the specular pass for all transparent objects, and it is purely additive, which is also order-independent. What you will miss out on is that, in a perfect system, the additive specular highlight of a distant object *should* be modulated by the multiplicative tinting pass of a near object. However, this only affects the specular highlight, and I bet it will be ignored, much like we ignore the fact that cubic environment refraction mapping does *not* take into account the exit vector refraction.

Anyway, I'm extremely happy to have found "blancmange"'s glass transparency effect, even if I did have to spend a few minutes tweaking it for my own tastes.

Mac

CAD_Swede
05-08-2003, 10:08 PM
Originally posted by MacReiter:
I cranked up the ambient on the light, and I got a very nice see through plastic yellow spaceship (using a RomulanBirdOfPrey.cob trueSpace model from avalon.viewpoint.com to play with).

This technique gives an excellent (mostly) order-independent glass/jewel/crystal/thin-plastic/energy-field effect...

Well..What are you waiting for? Show us some screen shots! :-)

Sounds like a very neat effect with a technique I haven't used before.

Thanks!

/Henrik

knackered
05-09-2003, 03:49 AM
It sounds useful for those specific types of materials (glass/plastics), but I don't think it will help with the most common use of transparency - rendering stuff like trees, which use the alpha channel of the texture to interpolate between the texel and the framebuffer pixel.

MacReiter
05-09-2003, 04:41 AM
CAD_Swede:

Unfortunately, I do not have a publicly available web/ftp server from which to serve the images. (I know, I should join the 21st century... I do this stuff as a hobby, and the people who supply my paychecks wouldn't appreciate my using their FTP server) However, I would be willing to email things to people: either JPGs or the EXE (all I brought with me to work) or the source (which would have to wait until probably next Monday -- I'm travelling this weekend). Of course, I realize most people will not wish to publicly broadcast email addresses, nor run arbitrary EXEs from other people, so I suspect that it will have to wait until I can send the source.

Anyway, if you want any of the above, and are willing to give me your email (or a site where I could upload the stuff), my email is:

reiter@nomadics.com

(I already get so much spam I don't see how it could hurt at this point...)

(By the way, I really enjoyed playing Anachronox.)

knackered:

Thank you. I hadn't really thought about the need for depth sorting in those applications. Given that one of my major goals for my own hobby projects is to make as much use of impostors as I can, I will definitely need to consider the texture/background blending issue. I had focused on full transparent objects because they had been what I first encountered difficulty with, and also because things like spheres and teapots were what the "order independent transparency through depth peeling" guys were working with.

I know what kinds of effects happen when you don't depth sort your fully alpha'd polygons. What kinds of effects happen when you don't depth sort texture-alpha'd polygons? I have seen tree models where "planes" of leaves would pop through each other, and models where the outlines of the leaves would pop from correct to single "white" pixels, but I don't know if this is related. (I say "white", but it seems like they were actually the "original background" -- generally sky colored, since this was a big tree that I had to look up at)

Thanks,
Mac

MacReiter
05-14-2003, 11:41 AM
I'm a goomer again... My ISP *does* provide limited hosting. Some screen shots are available at:
http://www.brightok.net/~reiter

As the site says, I will attempt to get some newer screenshots from updated code (smooth/interpolated normals, different colors and intensities of transparency, objects that have all their normals pointing the right way, etc), but I can't promise when.

Mac