Author Topic: Handling drawing semi transparent faces on objects.  (Read 4582 times)

0 Members and 1 Guest are viewing this topic.

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile


I've begun to fiddle around with transparent shapes with OpenGL. As anyone knows the materials are not drawn at the correct depth once transparent faces come into play because the zbuffer must be disabled. I know that the faces must be reordered but I'm not sure how to store and sort the data when polyhedra are being procedurally generated. Do I put each face into a face object then store the face objects in an array or list? I keep hearing that the faces must be processed in a special order but I'm not sure how to store the information or how to process the faces once (and if) they are stored.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Handling drawing semi transparent faces on objects.
« Reply #1 on: October 30, 2007 »
Alpha objects need to be rendered from back to front, after everything else has been rendered.

Jim
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: Handling drawing semi transparent faces on objects.
« Reply #2 on: October 30, 2007 »


I have read that elseware. Maybe my question is unclear, what is the best way to calculate which faces are drawn first and do I need to store the faces in a datastructure for ordering and processing?
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Handling drawing semi transparent faces on objects.
« Reply #3 on: October 30, 2007 »
Pixel outlaw,

man thats a tough question. Basically what you want is called painters algorithm or sometimes depth sorting. To do a really good, foolproof job is tough coding. Have a look at painters algorithm on wiki to understand how tough this can get with mutual overlapping polygons.

So, what you need to do instead is work out if you can live with an approximation.

Maybe shockwave or one of the software poly render guys can give you better advice but essentially this is a HARD problem. OK heres a first example. This assumes most of your polygons are the same size and dont mutually overlap.

For each polygon you will draw pre-calculate a centre point and store this in an array. Also store an index for the polygon. When you draw this frame, transform the array of centre points by hand (ie not using opengl). Then sort this array on Z, being careful to also sort the index.
Now draw your real polygons in the correct order using the index.

This will not work in all circumstances.
http://www.sjbaker.org/steve/omniv/alpha_sorting.html

Alpha polygons is the main reason most games writers dont rely on the transform pipeline of the hardware but do it themselves.

You might be able to do better, if you can live with some "artefacts". You say you have polyhedra. If they are convex polyhedra, what you could do is this:
- only draw front facing polygons
- sort centres of polyhedra (not polygons).

Still a lot of code but much faster.

Chris
« Last Edit: October 30, 2007 by chris »
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: Handling drawing semi transparent faces on objects.
« Reply #4 on: October 30, 2007 »
Thanks alot, I think I'll be able to try some of this. It seems kind of funny that there is no native support for z buffer and transparent polygons. I'll just try to get into the algorithems.
Challenge Trophies Won:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: Handling drawing semi transparent faces on objects.
« Reply #5 on: October 30, 2007 »
Going by the assumption that you have your faces/polys organised in either arrays, types or other structual way, and if you can live with minor flaws, then I would probably go for the method suggested by Chris where you sort the faces/polys based on the average z value of all the vertices within each face/poly. I did a couple of effects that used that, and it worked fairly well, with the bonus of being quite fast since less math is involved.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Handling drawing semi transparent faces on objects.
« Reply #6 on: October 30, 2007 »
In my experience, if you're just going to use Painter's Algorithm there's not much benefit to using the centre point of a triangle over choosing either the min-z or max-z of the polygon to sort by, which is less calculation.  As Chris says, it really depends what your geometry looks like.
The zbuffer still works, you just have to save all the alpha triangles 'til last and then render them in back to front order for them to appear correctly.  I guess this makes sense - if you want to see something through a window, you have to render the outside before the window, else it won't be outside ;D

Jim
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Handling drawing semi transparent faces on objects.
« Reply #7 on: October 30, 2007 »
Quote from: chris
You might be able to do better, if you can live with some "artefacts". You say you have polyhedra. If they are convex polyhedra, what you could do is this:
- only draw front facing polygons
- sort centres of polyhedra (not polygons).

that could be taken a little further, draw the inward facing triangles first then draw the outward facing triangles. As chris said you'll still need to sort the polyhedra and there will probably be some visual artefacts if they intersect at all.

Fryer.

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Handling drawing semi transparent faces on objects.
« Reply #8 on: October 31, 2007 »
In my experience, if you're just going to use Painter's Algorithm there's not much benefit to using the centre point of a triangle over choosing either the min-z or max-z of the polygon to sort by, which is less calculation.

Jim,

If you are using OpenGL (as in this case) to transform the polys, how do you get the min, max of the transformed poly? If you cant, how do you know before hand which will be the min or max? I dont think you can. This means you would need to transform all points by hand - ok for software rendering but wasteful if using GL so I still think transforming the centre point of polys is the least calculations when using OpenGL to render alpha polys...

Chris
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Handling drawing semi transparent faces on objects.
« Reply #9 on: October 31, 2007 »
I see your point.
If you're comparing apples and apples, there would be no need to take the average of the 3 points, just add them up.

Jim
Challenge Trophies Won: