在缓冲区对象上运行并通过着色器更改其数据? [英] Run on buffer object and change it's data by shader?

查看:155
本文介绍了在缓冲区对象上运行并通过着色器更改其数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Buffer Object上运行着色器并使用着色器用其他一些数据对其进行修改?

Is there a way to run a shader on Buffer Object and modifying it with some other data with shader?

换句话说:是否有一种方法可以在着色器中创建统一的全局变量并且可修改?

In other words: Is there a way to create uniform global variable in shader and modifiable?

推荐答案

是的,尽管它取决于您的硬件.所有这些机制都需要具有GL 3.x或更高版本的硬件.

Yes, though it depends on your hardware. All of these mechanisms require hardware capable of GL 3.x or above.

转换反馈

这使您可以在一个或多个缓冲区对象中捕获顶点处理的结果.

This allows you to capture the results of vertex processing in one or more buffer objects.

这是最粗糙的机制,因为每个顶点着色器只能访问作为输入提供的顶点数据,并且只能写入输出顶点.因此,着色器无法在其之前或之后访问顶点.此外,输出量非常有限,通常从GL 3.x级硬件只有4个输出值.

This is the most crude mechanism, because each vertex shader can only access the vertex data it is given as input, and can only write to the output vertex. So the shader can't access the vertex before or after it. Also, the amount of outputting is quite limited, usually only 4 output values from GL 3.x-class hardware.

您可以使用几何着色器来提高您的一些读写能力;反馈发生在VS或GS之后.

You could use a geometry shader to increase some of your reading and writing abilities; feedback happens after the VS or GS.

渲染到缓冲区对象

缓冲区纹理是使用缓冲区对象进行存储的纹理.它们就像非常大的一维纹理.

Buffer textures are textures that use a buffer object for storage. They're like really big 1D textures.

作为纹理,您可以自由地将它们附加

Being a texture, you can freely attach them to a Framebuffer Object and render to it.

该技术的缺点是,要渲染到高度为1像素的图像很困难,这是因为您正在处理光栅化器.这不是完全正确的.您可以使用gl_FragCoord知道片段中的位置,但是如果要将明显不同的数据写入图像的不同区域,则可能会遇到困难.

The downside of this technique, beyond the difficulty of rendering to an image with 1 pixel of height, is that you're dealing with the rasterizer. It's not perfectly exact. You can use gl_FragCoord to know where you are in the fragment, but if you want to write significantly different data to different areas of the image, there may be difficulties.

另一个问题是FBO的大小受视口尺寸的限制,通常在8192到16384之间.充其量,您可以编写65536个单独的浮点数(如果缓冲区纹理使用GL_RGBA32F格式).因此,您实际可写入的数据量非常有限.

The other problem is that FBO sizes are limited by the viewport dimensions, usually around 8192 to 16384. That's not a lot of room to write; at best, you can write 65536 individual floats (if the buffer texture uses the GL_RGBA32F format). So you're very restricted in how much data you can actually write.

图像加载/存储

ARB_shader_image_load_store 表示着色器可以从中任意读取并读取着色器.写入图像数据.结合缓冲区纹理(使用缓冲区对象作为存储的纹理),您可以任意读写缓冲对象.

ARB_shader_image_load_store, core in GL 4.2, represents the ability of a shader to arbitrarily read from and write to image data. Combined with buffer textures (textures that use buffer objects as storage), you can arbitrarily read from and write to buffer objects.

除了硬件要求之外,最大的缺点是没有免费的午餐.通过使用Image Load Store,您可以有效地放弃所有OpenGL的自动内存同步系统.因此,您必须所有同步手动 进行读写.这是一个很大的痛苦,您可以很容易地将其弄糟并获得未定义的行为,而无需知道为什么.它可能只能在一个平台上运行,而不能在用户的计算机上运行.

The big downside, besides the hardware requirements, is that there's no free lunch. By using Image Load Store, you effectively give up on all of OpenGL's automatic memory synchronization systems. So you have to do all synchronizations manually for writes and reads. This is a big pain and you can very easily screw it up and get undefined behavior without having a clue as to why. It might work on one platform, but not out on a user's machine.

您必须非常小心使用这些东西.

You have to be very careful with this stuff.

着色器存储缓冲区对象

着色器存储缓冲区对象实际上只是从缓冲区纹理加载/存储图像,仅带有 很多更好的界面.就像定义结构并只是访问它们一样.

Shader storage buffer objects are really just Image Load/Store from buffer textures, only with a much nicer interface. It's like defining structs and just accessing them.

与图像加载/存储相同的缺点也适用.另外,SSBO是真正的新功能;只有NVIDIA才能实现,甚至那时也只能在beta驱动程序中实现.

The same downsides as for Image Load/Store apply. Also, SSBO is really new; only NVIDIA implements it yet, and even then, only in beta drivers.

这篇关于在缓冲区对象上运行并通过着色器更改其数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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