3

Is there a way to read fragment from the framebuffer currently rendered?

So, I'm looking for a way to read color information from the fragment that's on the place that current fragment will probably overwrite. So, exact position of the fragment that previously rendered.

I found gl_FragData and gl_LastFragData to be added with certain EXT_ extensions to shaders, but if they are what I need, could somebody explain how to use those?

I am looking either for a OpenGL or OpenGL ES 2.0 solution.

EDIT:

All the time I was searching for the solution that would allow me to have some kind of read&write "uniform" accessible from shaders. For anyone out there searching for similar thing, OpenGL version 4.3+ support image and buffer storage types. They do allow both reading and writing to them simultaneously, and in combination with compute shaders they proved to be very powerful tool.

4

2 回答 2

6

你的问题似乎很困惑。

您的部分问题(第一句)询问您是否可以从片段着色器中的帧缓冲区中读取。答案是,一般不会。有一个 OpenGL ES 2.0 扩展可以让您这样做,但它仅在某些硬件上受支持。在桌面 GL 4.2+ 中,您可以使用任意图像加载/存储来获得相同的效果。但是你不能再渲染到那个图像了;您必须使用图像存储功能写入数据。

gl_LastFragData非常简单:帧缓冲区中样本的颜色将被此片段着色器覆盖。如果可用,您可以随心所欲地使用它。

您问题的第二部分(第二段)是一个完全不同的问题。在那里,您询问可能从未写入帧缓冲区的片段。您无法从片段着色器中读取;你只能阅读图像。如果一个片段没有通过深度测试,那么它的数据就永远不会被渲染到图像上。所以你读不出来。

于 2013-05-13T21:24:15.130 回答
1

对于大多数 nVidia 硬件,您可以使用 GL_NV_texture_barrier 扩展来读取当前绑定到帧缓冲区的纹理。但请记住,您将无法读取比上次绘制调用中生成的数据更新的数据

于 2013-05-14T09:06:11.710 回答