PDA

View Full Version : High-quality transparency in one pass?



mogumbo
08-11-2005, 10:26 AM
I'm looking at making high quality material properties with transparency. The only way I can think to do this currently is a two pass rendering method:

1. Diffuse lighting/coloring/texturing using {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}
2. Highlights from specular light and/or reflections using {GL_ONE, GL_ONE}

The two passes are necessary simply because you can only have one blend mode at a time and different aspects of the lighting require different blend modes. I don't know of any tricks for getting the same visual quality in a single pass. Does anyone know a way?

There was talk at the OpenGL BOF at Siggraph of blend shaders, but I don't know anything about those yet or if they would help.

Any thoughts or suggestions?

dorbie
08-11-2005, 11:38 AM
Do the source math in the shader and premultiply the rgb as the net result of src * color + highlights.

Then set outgoing alpha for the destination modulation factor only and use a glBlendFunc(GL_ONE, GL_SRC_ALPHA).

mogumbo
08-11-2005, 11:50 AM
Maybe I don't understand correctly. Doesn't that require you to use the color that is already in the framebuffer? I thought gl_FBColor was not implemented.

Dirk
08-12-2005, 05:39 AM
Originally posted by mogumbo:
Maybe I don't understand correctly. Doesn't that require you to use the color that is already in the framebuffer? I thought gl_FBColor was not implemented.Nope, that's not what he's saying.

If I understand you right what you want to is

(dif * tex) * alpha + (1-alpha) * fb + spec

What dorbie is saying is that you can do it with GL_ONE, GL_ONE_MINUS_SRC_ALPHA by doing

frag_col = vec4((dif * tex) * alpha + spec, alpha)

Hope it helps

mogumbo
08-12-2005, 06:19 AM
Aha! That makes perfect sense now. And it sounds like it should work fine. Thanks guys.