2

I have a model with transparent quads for a beard. I can not tell what triangles belong to the beard because their color comes from the texture passed to the fragment shader. I have tried to presort the triangles back to front during export of the model, but this does not help. So I implemented MSAA and Alpha to Coverage, but this did not help either. My last attempt was to draw the model, with a depth mask off and skipping any transparent data, so the color buffer would have non-clear color values to blend with. Then I would draw the model a second time with depth testing on and drawing the alpha pieces.

Nothing I have tried so far has worked. What other techniques can I try to get the beard of the model to properly draw? I am looking for a way to handle this that doesn't use a bunch of extensions. I'd prefer techniques that can be handled with plain old OpenGL 4.

Here is an image of what I am dealing with. enter image description here

This is what I got after I applied the selected answer. enter image description here

Jason Smith
  • 765
  • 8
  • 23
  • 2
    Hair is usually rendered in a separate batch from the main model. You draw the opaque parts of the model first, then the hair.. Are you using a single skinned texture for this entire model? If not, it should be trivial to determine which parts of the model are translucent and which are not and draw them at different times. As a last resort (this is a total hack but easy to implement), you could test the alpha value in a fragment shader and discard anything less than say 0.5; then the order you draw the facial hair in will not matter quite as much. – Andon M. Coleman Sep 09 '13 at 21:25
  • Yes, I'm using a single skinned texture. I have tried discarding fragments with an alpha of my choosing but it makes his beard look very splotchy. I'll look at the blender file and see if I can figure out how to get the beard as a separate object that still move with the mocap skeleton. – Jason Smith Sep 09 '13 at 22:03
  • Yeah, I figured as much. That's almost never an acceptable solution these days :) If you can somehow identify your facial hair differently in your model another solution is simply to index their vertices *last* in your draw call. If you're using skeletal animation, for instance, maybe assign hair the highest bone IDs and sort your triangle order by bone ID when you load or export the model. This would ensure that all opaque geometry comes first and the only transparency issues would be related to multiple layers of hair, which is often acceptable. – Andon M. Coleman Sep 09 '13 at 22:17

2 Answers2

3

What you're trying to do there is a still largely unsolved problem: Order independent transparency. MSAA is something entirely different, as is alpha coverage.

So far the best working solution is to separate the model into an opaque and a hairy part. Draw the opaque parts of your scene first, then draw everything (semi-)translucent, ordered far to near in a second pass.

The way your image looks like it seems like the beard is rendered as the first thing, which is quite the opposite of what you actually want.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • This is the method I chose to go with. It was quick to implement and doesn't eat up that much extra time. With the transparent parts drawn as a separate model I can even through them into the transparency queue so they are handled like everything else when I process the render commands. – Jason Smith Sep 10 '13 at 06:34
1

Simple way:

  1. Enable depth write (depth mask), disable alpha-blending, draw model without the beard.
  2. Disable depth write, enable alpha-blending, draw the beard. Make sure face culling is enabled.

Hard way:

Because order-independent transparency in renderers that use z-buffer is an unsolved problem (as datenwolf said), you could try depth-peeling. I believe the paper is available within OpenGL SDK. Most likely it'll be slower than "simple way", and there'll be a limit on number of maximum overlapping transparent polygons. Also check wikipedia article on order-independent transparency.

SigTerm
  • 26,089
  • 6
  • 66
  • 115