Sign in to follow this  
matt77hias

Transparency and normals

Recommended Posts

I decided to draw all transparent geometry twice. First, opaque fragments are processed by the pixel shader whereas transparent fragments are clipped inside the pixel shader. Second, opaque fragments will be discarded by the early-z-test of the rasterizer whereas transparent fragments are processed by the pixel shader (and blended afterwards).

  1. Bind a rasterizer state with a Less-Equal comparison function.
  2. Bind no blend state.
  3. Render all geometry and clip transparent fragments
  4. Bind a rasterizer state with a Less comparison function.
  5. Bind alpha-to-coverage or alpha/transparency blend state.
  6. Render transparent geometry.

I assume that one should use the most restrictive threshold to check for transparency: alpha less than 1?

In a deferred renderer, the normals of opaque geometry are stored in the GBuffer. So step 3 will correspond to GBuffer packing and unpacking (i.e. 2 passes). Transparency will be handled separately in a forward pass (step 6). But what if I want to use the normal buffer of the GBuffer in the post-processing? Should I take normals of transparent fragments into account (and thus update the normal buffer as well in step 6) with or without blending? Or should I neglect these normals (but what about high alpha values?)?

Share this post


Link to post
Share on other sites
7 hours ago, matt77hias said:

But what if I want to use the normal buffer of the GBuffer in the post-processing

All geometry aware post processing (anything that uses position / depth / normals / etc) is a complete hack as soon as you've blended any translucent pixels  :(

Do what looks best in your situation. If that's using the GBuffer as is, or doing a late pass to distort the GBuffer, or whatever... Do what you have to. 

If you want examples of this going badly, find any game that does close up shots of a character who wears glasses, while DOF is active. Usually, either the blurry background will magically not be blurry when seen through the glass, or the specular reflections on the glass will be blurred as if they're in the background. 

Characters with translucent hair in front of A DOF'ed background are another common offender. 

Share this post


Link to post
Share on other sites

Is it best to hard code the PSs for forward rendering:

#ifdef ENABLE_TRANSPARENCY
    clip(base_color.w - TRANSPARENCY_SKIP_THRESHOLD); // ~1/255
#else
    clip(base_color.w - TRANSPARENCY_THRESHOLD); // ~254/255
#endif

For depth, you have a similar problem as well with transparency. Furthermore, if you want to skip the normals of transparent fragments, you'll also have to avoid writing the depth of transparent fragments and vice versa.

Edited by matt77hias

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this