(如何)着色器可以查看当前的渲染缓冲区? [英] (How) can a shader view the current render-buffer?

查看:37
本文介绍了(如何)着色器可以查看当前的渲染缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像素着色器是否有可能看到深度/颜色/模板缓冲区的当前状态?

Is it possible for a pixel shader to see the current state of the depth/color/stencil buffer?

推荐答案

片段着色器未获得其正在处理的片段的当前缓冲区值.尝试通过将这些缓冲区用作纹理来读取这些值,在一般 情况下不会产生合理的结果.这是未定义的行为".

A fragment shader is not given the current buffer values for the fragment it is working on. Attempts to read these values, by using those buffers as textures, will not in the general case produce reasonable results. It's "undefined behavior."

在某些特定情况下它可以工作.

There are certain specific cases where it can work.

首先,您可以使用纹理障碍.这在技术上是 NVIDIA 的扩展,但 ATI 也广泛支持它.屏障基本上是缓存刷新.它允许您将当前渲染目标绑定为纹理并从中读取:恰好一次.您可以进行一次读取,然后,除非您使用另一个屏障来刷新缓存,否则您将返回未定义行为".

First, you can use texture barriers. That is technically an NVIDIA extension, but ATI supports it widely as well. A barrier is basically a cache flush. It allows you to bind the current render targets as textures and read from them: exactly once. You can do one read, and after that, you're back to "undefined behavior" unless you use another barrier to flush the cache.

直接图像读/写是 GL 4 独有的功能.x 级硬件(又名:DX11).它允许您任意读取和写入绑定图像.但是,要做到这一点,您必须同步不同着色器实例之间的访问.这种方法有很多注意事项,所以你应该仔细阅读如何去做.

Direct image read/writes is a feature unique to GL 4.x-class hardware (aka: DX11). It allows you to arbitrarily read from and write to bound images. To do this however, you have to synchronize access between different shader instances. There are a lot of caveats to this approach, so you should read up on how to do it.

这篇关于(如何)着色器可以查看当前的渲染缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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