GLSL 几何着色器和通用顶点属性

发布于 2024-11-17 16:19:57 字数 456 浏览 7 评论 0原文

所以我已经尝试了一段时间,将顶点属性数组传递到几何着色器中。它是一个浮点数组(其中每个顶点的属性只是一个浮点值)

现在,当我将其放入几何着色器中时:

attribute float nodesizes;

着色器编译器抱怨:

OpenGL requires geometry inputs to be arrays

我如何准确地传递它?

另外,这是我放置顶点属性的代码:

glBindAttribLocation(programid, 1, "nodesizes");
glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, array);
glEnableVertexAttribArray(1);

我做错了什么吗?

So I've been trying for a while now, to pass a vertex attribute array into the geometry shader. It is an array of float (where the attribute per vertex is just a float value)

Now, when I put this in the geometry shader:

attribute float nodesizes;

The shader compiler complains:

OpenGL requires geometry inputs to be arrays

How do I exactly pass it along?

Also, here's my code for putting the vertex attrib:

glBindAttribLocation(programid, 1, "nodesizes");
glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, array);
glEnableVertexAttribArray(1);

Am I doing something wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泪是无色的血 2024-11-24 16:19:57

几何着色器不获取属性。顶点着色器获取属性并输出变化(用旧语法来说)。然后可以在几何着色器中读取它们,但作为数组,因为一个几何着色器调用跟随多个顶点着色器调用。像这样的东西:

顶点着色器:

attribute float nodesize;
varying float vNodesize;

void main() {
    ...
    vNodesize = nodesize;
    ...
}

几何着色器:

varying float vNodesize[];

void main() {
    ...vNodesize[i]...
}

名称是任意的,但当然变量的名称必须在两个着色器中匹配。我希望您不要混淆顶点着色器和几何着色器这两个术语。

The geometry shader doesn't get attributes. The vertex shader gets attributes and puts out varyings (speaking in the old syntax). These can then be read in the geometry shader, but as an array, as one geometry shader invocation follows multiple vertex shader invocations. Something like this:

vertex shader:

attribute float nodesize;
varying float vNodesize;

void main() {
    ...
    vNodesize = nodesize;
    ...
}

geometry shader:

varying float vNodesize[];

void main() {
    ...vNodesize[i]...
}

The names are arbitrary, but of course the names of the varyings have to match in both shaders. I hope you didn't just mess up the terms vertex shader and geometry shader.

萌酱 2024-11-24 16:19:57

您使用的是哪个 open gl 版本?

来自Open GL语言规范(4.10.6)

几何处理器上几何着色器可执行文件的单次调用将在
声明的输入基元具有固定数量的顶点。这个单一的调用可以发出一个变量
组装成声明的输出基元类型的基元并传递给的顶点数
随后的管道阶段。

这意味着您需要指定几何图形所采用的图元类型(点、线、三角形、四边形)。

如果我理解正确的话,您希望几何着色器为每个顶点发出一个立方体。因此,您应该将几何输入类型设置为点。

因此,几何着色器代码应该这样开始:

varying float vNodesize[];

void main() {
    ...vNodesize[i]...
}

其中 i = 0 表示点 =1 表示线等。

Which open gl version are you using?

From the Open GL language specification (4.10.6)

A single invocation of the geometry shader executable on the geometry processor will operate on a
declared input primitive with a fixed number of vertices. This single invocation can emit a variable
number of vertices that are assembled into primitives of a declared output primitive type and passed to
subsequent pipeline stages.

This means that you need to specify on witch kind of primitive (point, line, trianle, quad) the geometry assumes.

If I understand you correctly you want the geom shader to emit a cube for each vertex. So you should set the geometry input type to point.

As a reslult the geom shader code should start like this:

varying float vNodesize[];

void main() {
    ...vNodesize[i]...
}

Where i = 0 for points =1 for lines and so on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文