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

correct transparency without depth-sorting

Started by ehmdjii Aug 10, 2007 at 9:17 AM 1 replies 1k views
Original Post
ehmdjii
ehmdjii
hello, i want to visualize an object inside a transparent bubble. the bubble is just a textured sphere where the texture has an alphachannel which defines the transparency. now in order to correctly visualize the transparency i think i will need to do polygon-based depth sorting on the polygons of the sphere. is that absolutely necessary or is there any other way to do that without the pain of polygon-depth-sorting. thanks! [Edited by - ehmdjii on August 10, 2007 9:41:15 AM]
jpetrie
jpetrie
Depth-peeling can be used for order-independent blending, but it's probably just as hard -- if not harder -- than sorting your objects so you render them back-to-front.
kRogue
kRogue
there is an easy way to do transparencies without depth sorting, but it can have issues, this is what I do in my stuff. Note, you will need FBO and GL_EXT_framebuffer_object to get this to go, but it is not hard:

init:
1) create an FBO with 2 texture targets (or 2 FBOS each with one texture target),the texture targets will be "opaque" and "filter", use a floting point for the filter texture target (like GL_RGBA16).. if you use one FBO then the opauq must be the same, if you use two fbo's make sure that they share the same depth render buffer object.

for each frame:
1) set to draw the the opaque texture.
2) disable blending
3) enable depth testing and writing.
4) draw all opaque objects (as usual)

5) set to draw to the filter frame
6) enable additive blending with

glBlendFunc(GL_ONE, GL_ONE); //for transluscent objects, we just add the filtering!glBlendEquation(GL_FUNC_ADD);


and use glClampColorARB to stop GL from clamping the values after blending:
glClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB, GL_FALSE);glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, GL_FALSE);glClampColorARB(GL_CLAMP_READ_COLOR_ARB, GL_FALSE);


7) disbale writing to depth buffer, but keep depth test on.
8) draw transluscent objects.

9) now use a fragment shader to do the post process of applying the filtering.


now some things to be aware of:
a) you need to decide what the filter means, I chose to make it a multiplier in the post process, i.e. gl_FragColor.rgb= opaque_color.rgb * filter_color.rgb and when I clear the filter texture I set the clear color to (1,1,1) and when I do the colors I start to use negative values....


Close this Gamedev account, I have outgrown Gamedev.

Topic Locked

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

Sign in to reply to this topic.