Render textures with full alpha-components correct

Hello guys,
i have a problem with getting the rendering of textures with fully alpha-components right, like leaves, grass etc. (I dont want to render semi-transparent objects yet)
I found two approaches on the internet:
1.) Just use discard in the shader-code when the alpha-component is e.g. below 0.1

  • This works but looks ugly for some textures
    2.) Use Blending
  • This looks fantastic but the problem is it writes the depth aswell, so the depth-test fails for new fragments behind invisible fragments.

I really want to use the second approach. Can i disable depth-writing for fragments where the alpha is zero?

Thanks in Advance :slight_smile:

1 Like

So i have tested a bit more and yea i wasn’t aware of the fact that the alpha-values at the borders are linearly decrease, so the fact approach 2) looks fantastic is it blends those pixels with the background.
I guess then the proper way to deal with such kind of textures is to use blending and a back-to-front rendering order right?

1 Like

Yes, either sort (and render) back-to-front or use something like depth peeling to get proper blending independent of render order. Vulkan’s input attachments and sub passes are very well suited for something like depth peeling, see e.g. Depth Peeling Order Independent Transparency in Vulkan - Matthew Wellings.

1 Like

A cheap and cheerful alternative is to render the geometry twice. First time use alpha test with a high threshold (e.g. 0.75 or higher) and enable depth-write. Second time use alpha blend but disable depth-write. It’s not quite as correct as depth peeling or sorting, but in most cases it’s good enough, it’s far easier to implement, and it’s much faster. Here’s a blog that discusses it: Rendering Plants with Smooth Edges - Wolfire Games Blog

1 Like

thanks :slight_smile: Will review both approaches and implement one which i will happy with