Running on a buffer object and changing its data using a shader?

Is there a way to start a shader for a Buffer object and change it using some other data using a shader?

In other words: is there a way to create a single global variable in the shader and modify it?

+4
source share
2 answers

Yes, although it depends on your equipment. All of these mechanisms require equipment capable of GL 3.x or higher.

Conversion Feedback

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

This is the roughest mechanism, because each vertex shader can only access the vertex data that it sets as input, and can only write to the output vertex. Thus, the shader cannot access the vertex before or after it. In addition, the output volume is quite limited, usually only 4 output values ​​from GL 3.x hardware.

You can use the geometric shader to increase some of your reading and writing abilities; Feedback occurs after VS or GS.

Display Buffer Object

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

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

The disadvantage of this technique, in addition to the complexity of rendering an image with 1 pixel height, is that you are dealing with a rasterizer. This is not entirely accurate. 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, difficulties can arise.

Another problem is that FBO sizes are limited by viewing sizes, usually around 8192-16384. This is not much space for recording; at best, you can write 65,536 individual floats (if the buffer texture uses the GL_RGBA32F format). Thus, you are very limited by how much data you can actually write.

Download and save images

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

A big drawback, in addition to the hardware requirements, is that there is no free lunch. Using the Image Load Store, you actually abandon all OpenGL memory synchronization systems . Thus, you must synchronize everything manually for writing and reading. This is a big pain, and you can very easily ruin it and get undefined behavior without having a clue about why. It can work on one platform, but not on the user machine.

You must be very careful with this.

Shader Storage Buffer Object

Shader repository buffer objects - it's really just loading images from the texture repository, only with a much nicer interface . This is similar to defining structures and accessing them.

The same drawbacks are used as for image loading / saving. In addition, SSBO is really new; only NVIDIA implements it even then, only in beta versions.

+7
source

I don’t know how to do this, but I know that changing the VBO from the shader is called Transform Feedback . You will need OpenGL> = 3.0 or OpenGL> = 2.0 with the extension NV_transform_feedback or EXT_transform_feedback .

If you need more general computing power, you can try making OpenCL / OpenGL interop ...

+1
source

All Articles