Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLSL Geometry shader and generic vertex attributes

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?

like image 997
kamziro Avatar asked Jun 30 '11 13:06

kamziro


1 Answers

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.

like image 124
Christian Rau Avatar answered Sep 21 '22 07:09

Christian Rau