(How) can a shader view the current render-buffer?

拈花ヽ惹草 提交于 2020-01-30 09:12:06

问题


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


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/8492261/how-can-a-shader-view-the-current-render-buffer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!