PDA

View Full Version : 3D Alpha in OpenGL


Apocalypse
10-14-2005, 12:37 PM
I have a serious problem here... I want to make an object 50% transparent and another one 100% opaque. The code looks something like this:


glEnable(GL_DEPTH_TEST);
Draw_Opaque_Object();
glEnable(GL_BLEND);
glDepthMask(GL_FALSE); // don't update the z-buffer!
Draw_Transparent_Object();
glDepthMask(GL_TRUE);
...


I know that I must draw the opaque objects first, then the transparent ones but this is a serious problem... if I want to create a grate texture, it's impossible to draw half of it (the opaque part) and then the other part... so, how can it be done?


Another question is what means 'Render the polygons from front to back'?:huh: It means to draw all the front facing polygons and then the back ones, or what? In 'The Red Book' says that for antialiasing polygons you need to render the polygons from front to back... what does it mean?

zavie
10-14-2005, 02:04 PM
The problem with transparent object is the following: as shown in the Red book, when you render transparent objects, order does count. You have to render distant objects before close ones, in order to be able to see objects through others. This is called "rendering back to front".

Of course "front to back" is the contrary. ;-) Doing so is interesting for opaque objects because is avoids overdrawing.

About your grate, you have to render it as a transparent object.

zavie
10-14-2005, 02:07 PM
Oh, by the way I forgot: when rendering transparent objects back to front, you can to let the depth test enabled.

Apocalypse
10-14-2005, 02:55 PM
And how can I arrange the polygons so that I render them correctly? Know any fast method? Of course I could put lots of ifs there, but this will surely affect the performance.

Anyway, thanks for the previous information!:happy:

zavie
10-15-2005, 09:46 AM
To be honest I don't know any special method: I just sort polygons according to the distance to the camera.

NomadRock
10-15-2005, 10:48 AM
You cant just sort polygons, because this doesnt work for ones that happen to intersect. In this case you have to start splitting polygons. A BSP tree does this automatically. If you happen to know that your scene by definition cannot have intersecting transparent polygons then go right ahead and just sort them.

baldurk
10-15-2005, 03:51 PM
In some cases you can just go ahead and do it anyway, the chances of an intersection actually showing up and being glaringly obvious will maybe be low. It's certainly a lot to do to split polygons correctly if you'll only be correcting a very minor artifact seen 1% of the time.

Depends how much of a perfectionist vs. how lazy you are I guess :).

Apocalypse
10-17-2005, 12:22 AM
Thanks, guys!:happy: