0

I only have partially opaque/transparent but not translucent sprites in my scene. My approach would be to render the scene to an FBO with a simple fragment shader writing gl_FragCoord.z for opaque- or 1.0 for transparent regions to gl_FragColor.a, then blending the alpha with glBlendEquation(GL_MIN).

Now having a texture with depth information on the alpha channel, I'd like to use it as a depth attachment and render the scene again, this time with potentially more expensive shaders to color it.

Compared to the usual far-near blending technique, this would benefit from early-z in the second pass and have low fillrate if the first pass was drawn near-far.

I have not found any material about this approach, but is it possible?

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
ichi
  • 1
  • 1
  • I think it should work, but you have to take in mind how many bits your alpha channel will have ... not sure what are the limits for blending ... so you should look into OpenGL docs for suported Alpha channel bitwidths ... as 8/16 bits is not much for depth testing ... – Spektre Nov 12 '20 at 08:22
  • i cannot come with a working solution. attaching a renderbuffer with depth format to a framebuffers color attachment doesnt work for the first pass. and the other way using a renderbuffer with color format as a depth attachment doesnt work either. color and depth seem to have no compatible format – ichi Nov 12 '20 at 22:57
  • I am using [FBO](https://stackoverflow.com/a/43930271/2521214) in there you can have more attachments ... depth is separate texture ... yes they have slightly different format but that is no problem you can mix them in the next pass in fragment shader ... the only disadwantage is that you need 2 texture units instead of 1 ... – Spektre Nov 13 '20 at 07:36
  • Your question needs some work. The sentence `I only have partially opaque/transparent but not translucent sprites in my scene.` makes no sense. Partial opacity IS translucency. `Now having a texture with depth information on the alpha channel, I'd like to use it as a depth attachment and render the scene again` you can't attach color textures as depth buffers. If you're trying to trick the hardware into doing something basic faster, you're not gonna succeed, especially if you are not even using the API correctly. – Tara Mar 30 '21 at 20:18

0 Answers0