如何将深度缓冲区复制到GPU上的纹理? [英] How to copy depth buffer to a texture on the GPU?

查看:224
本文介绍了如何将深度缓冲区复制到GPU上的纹理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将当前深度缓冲区获取到纹理,以在着色器中对其进行访问.由于种种原因,我无法进行单独的深度传递,但是需要复制已经渲染的深度.

I want to get the current depth buffer to a texture, to access it in a shader. For various reasons I can't do a separate depth pass, but would need to copy the already-rendered depth.

glReadPixels会占用CPU并可能会破坏性能,据我所知,glBlitFramebuffer不能只对深度进行颜色转换,而只能对深度进行转换.

glReadPixels would involve the CPU and potentially kill performance, and as far as I know glBlitFramebuffer can't blit depth-to-color, only depth-to-depth.

如何在GPU上执行此操作?

How to do this on the GPU?

推荐答案

执行此操作的现代方法是使用FBO.将颜色和深度纹理附加到其上,进行渲染,然后禁用FBO,并将这些纹理用作着色器的输入,该着色器将渲染到默认的帧缓冲区.

The modern way of doing this would be to use a FBO. Attach a color and depth texture to it, render, then disable the FBO and use the textures as inputs to a shader that will render to the default framebuffer.

您需要的有关FBO的所有详细信息可以在此处找到.

All the details you need about FBO can be found here.

这篇关于如何将深度缓冲区复制到GPU上的纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆