Jump to content


3D Alpha in OpenGL


7 replies to this topic

#1 Apocalypse

    New Member

  • Members
  • PipPip
  • 24 posts

Posted 14 October 2005 - 06: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?
Apocalypse, the End of the World.

#2 zavie

    Member

  • Members
  • PipPip
  • 91 posts

Posted 14 October 2005 - 08: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.

#3 zavie

    Member

  • Members
  • PipPip
  • 91 posts

Posted 14 October 2005 - 08:07 PM

Oh, by the way I forgot: when rendering transparent objects back to front, you can to let the depth test enabled.

#4 Apocalypse

    New Member

  • Members
  • PipPip
  • 24 posts

Posted 14 October 2005 - 08: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:
Apocalypse, the End of the World.

#5 zavie

    Member

  • Members
  • PipPip
  • 91 posts

Posted 15 October 2005 - 03:46 PM

To be honest I don't know any special method: I just sort polygons according to the distance to the camera.

#6 NomadRock

    Senior Member

  • Members
  • PipPipPipPip
  • 785 posts

Posted 15 October 2005 - 04:48 PM

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.
Jesse Coyle

#7 baldurk

    Senior Member

  • Members
  • PipPipPipPip
  • 1057 posts

Posted 15 October 2005 - 09: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 :).
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.

#8 Apocalypse

    New Member

  • Members
  • PipPip
  • 24 posts

Posted 17 October 2005 - 06:22 AM

Thanks, guys!:happy:
Apocalypse, the End of the World.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users