我可以通过顶点着色器修改 GPU 中的顶点缓冲区吗?

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

由于某种原因无法在网上找到答案。我想通过类似形式的着色器更新 GPU 中的顶点属性:

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

uniform mat4 someTransformation;

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

可以吗?

你能写出你写的代码吗?是的,那是法典。

这会改变任何 GPU 存储的内容吗?编号

虽然有 ways for a VS to directly manipulate the contents of a buffer,但如果正在操作的缓冲区也可能被用作渲染命令的属性数组,那么您将有未定义的行为。

您可以使用 SSBO 操纵未用作渲染输入的 其他 存储。您可以使用 transform feedback 来累积顶点处理输出的数据。但是你不能让VS直接修改自己的输入数组。