Using rgba-packed texture in depth pre-pass?


I’m trying to use (externally rendered) depth textures (32-bit, rgba packed) in a depth prepass, so that all subsequently rendered geomtries will be depth-tested against this custom depth buffer.

I’m using a custom shader on a full screen triangle to write the unpacked depth value into gl_fragDepth. However, geometries that render after the prepass are not occluded as expected. The depth test seems to be kind of inverted, but not really (???).

Maybe I’m missing something fundamentally here…?

I added a picture to better illustrate what is happening:

I also created a codepen. The only difference is, that instead of loading an external rgba-packed depth texture, the texture is created on the fly (in the “Pack” mode). In the “Prepass” mode, this texture is then used as described above. You can switch between the modes with the two buttons.


1 Like

This is tricky stuff…

float depthLinear = depth;//linear01Depth(depth, cameraNear, cameraFar);

I made that change and got something that looked… different? You’re probably close but you won’t know how close until you’ve made it. :smiley: