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

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

问题描述

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

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

推荐答案

没有为片段着色器提供其正在处理的片段的当前缓冲区值.尝试通过使用这些缓冲区作为纹理来读取这些值在 general 情况下不会产生合理的结果.这是未定义的行为".

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天全站免登陆