Drei useDepthBuffer gives mes feedback loop errors

A while ago I posted Reading from depth texture where I read the depth texture from Drei’s useDepthBuffer. When trying the same thing now, I keep getting GL_INVALID_OPERATION: glDrawElements: Feedback loop formed between Framebuffer and active Texture errors, both when passed down to a uniform to a ShaderMaterial, or passed to a MeshBasicMaterial map.

What is the use case of that hook, then? How would I set it up to be passable to a shader material, or just visualize it as a texture on a mesh?

You can’t write to a texture while reading from it at the same time.
You can use .layers.mask on objects and the camera, to control which things get rendered in which passes. How this works in r3f is a bit of a mystery to me tho… i guess there is some kind of renderpass abstraction? where you could toggle layers etc…

2 Likes

If i remember right i think i got the same error previously as well (makes sense), but that setting depthWrite = false fixed the issue. that seems to no longer be the case.

so i think i got something working: useFBO together with

useFrame(({ gl, scene, camera }) => { 
  // hide mesh that consumes depth texture
  ref.current.visible = false 
  gl.setRenderTarget(fbo) 
  gl.render(scene, camera)   
  gl.setRenderTarget(null) 
  ref.current.visible = true 
})

But that still leaves me with the question of what the use case is for useDepthBuffer is, is it meant for post processing?

1 Like