1
\$\begingroup\$

I have an FBO with only 16-bit depth attachment:

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, w, h, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, nullptr);

I render something to it, so now I have a depth texture with 16-bit precision. What is the best way to update this texture on the GPU (while maintaining precision), before passing it to the shader that will actually use it?

For example, let's say I want to update depth texture so that for every texel at (u,v), if u < 0.5 then the resulting texel would be equal to min between texel at (u,v) and (u+0.5, v). Value is unchanged otherwise.

The only way to do this that I can see is to create second FBO with similar depth attachment, and render to it while reading from 1st FBO's depth texture. During this render pass I can write updated values to 2nd FBO's texture through gl_FragDepth.

Is there a better way to do this? Can I avoid having 2 FBOs and update depth texture in-place, or is it considered a feedback loop and thus undefined behavior?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.