Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I modify vertex buffer in GPU through the vertex shader?

Tags:

gpu

opengl

shader

For some reason cannot find the answer on the web. I want to update vertex attributes in GPU through the shader in similar form:

#version 330 core
layout(location = 0) in vec4 position;

uniform mat4 someTransformation;

void main()
{
    position = position * someTransformation;
    gl_Position = position;
}

Is it possible?

like image 596
Jurby Avatar asked Oct 20 '25 16:10

Jurby


1 Answers

Can you write the code you have written? Yes, that is legal code.

Will that change the contents of any GPU storage? No.

While there are ways for a VS to directly manipulate the contents of a buffer, if the buffer region being manipulated is also potentially being used as an attribute array for a rendering command, then you will have undefined behavior.

You can use SSBOs to manipulate other storage which is not being used as the input for rendering. And you can use transform feedback to accumulate data output from vertex processing. But you cannot have a VS directly modify its own input array.

like image 151
Nicol Bolas Avatar answered Oct 23 '25 11:10

Nicol Bolas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!