Use depth in effect composer pass

Hi,

I want to implement a shader that renders on top of a previous pass and is able to read the depth buffer value. For context, I do ray marching in the scene after the regular geometry has rendered, but I want the geometry to be able to occlude the rays, hence my need for the depth buffer.

From what it looks like, this is not straight forward with RenderPass or ShaderPass. I could set up a custom rendertarget with a depth texture but then I’m not sure how to integrate it into the effect composer pipeline. I could override the generic Pass to do that but it seems like a lot of boiler plate just to read the depth texture.

Do you have any suggestions or is there something that I’ve missed?

As you write, you’re working with WebGL. I have an old repo of mine where I do exactly this. I hope this helps:

I do all the setup with the Effect Composer in the main, as well as with the depth texture. I’ve kept the repo as simple as possible. The shader for raymarching, however, is a bit more complex.

2 Likes

Thanks for the link, I really appreciate it. I tried to understand what is being done but I have to confess that I’m a little confused. Is it correct that you render the scene twice, once into a render target and once into the framebuffer before invoking the effect composer? I want to avoid rerenders as much as possible, but I think I could work around that quite easily.

If you need the depth of the scene, you need to use a renderTarget, into which you render the depth before each actual scene render. This doesn’t hurt performance. My primitive raymarcher in the shader in this example is far more critical.