Frage

Here is the code:

Vertex shader:

#version 330

layout(std140) uniform;


layout(location = 6) in vec4 worldPosition;
layout(location = 7) in int FIndex;


flat out int[] passFIndex;


uniform Projection
{
    mat4 view;
    mat4 projection;
};

uniform mat3[6] FMatrix;
void main()
{
    gl_Position = worldPosition;
    passFIndex = int[](FIndex);
}

geometry shader:

#version 330

layout(std140) uniform;

layout(points) in;
layout(triangle_strip, max_vertices = 136) out;

flat in int[] passFIndex;

uniform Projection
{
    mat4 view;
    mat4 projection;
};

uniform mat3[6] FMatrix;

void main()
{

    vec3 newPos = FMatrix[passFIndex[0]] * vec3(-0.5f, -0.5f, 0.5f);
...

So the problem is, the passFIndex is not being set properly when I set it equal to an array consisting of just the vertex attribute at location 7. The problem is, it's always set to 0. However, I KNOW the underlying vertex data for FIndex is not 0, because I can use a different shader program (one without a GS) and FIndex varies appropriately.

I can replace "passFIndex = int [ ] (FIndex)" with "passFIndex = int [ ] (2)" or some other constant in there, and that works to create an array with a non-zero, and it indexes as expected in the geometry shader. This seems to tell me that something is going wrong in the vertex shader but I can't imagine what it is.

War es hilfreich?

Lösung

Your attempt to output an array in the vertex shader is baffling. This should generate a link error in your GLSL program, because the interface between vertex shader and geometry shader does not match.

Geometry shader inputs are always in the form of an array because they take multiple transformed vertices to construct primitives. The output in the vertex shader, however, is generally not an array. If you wanted to output an array in the vertex shader, you would create a situation where the geometry shader needs a 2D array to match the interface - this is not supported.

GLSL 3.30 Specification - 4 Variables and Types - pp. 30

For the interface between a vertex shader and a geometry shader, vertex shader output variables and geometry shader input variables of the same name must match in type and qualification, except that the vertex shader name cannot be declared as an array while the geometry shader name must be declared as an array. Otherwise, a link error will occur.

If the output of a vertex shader is itself an array to be consumed by a geometry shader, then it must appear in an output block (see interface blocks below) in the vertex shader and in an input block in the geometry shader with a block instance name declared as an array. This is required for arrays output from a vertex shader because two-dimensional arrays are not supported.


I would consider re-writing your shaders:

Vertex Shader:

#version 330

layout(std140) uniform;


layout(location = 6) in vec4 worldPosition;
layout(location = 7) in int FIndex;


flat out int passFIndex;


uniform Projection
{
    mat4 view;
    mat4 projection;
};

uniform mat3 FMatrix [6];

void main()
{
    gl_Position = worldPosition;
    passFIndex  = FIndex;
}

Geometry Shader:

#version 330

layout(std140) uniform;

layout(points) in;
layout(triangle_strip, max_vertices = 136) out;

flat in int passFIndex [];

uniform Projection
{
    mat4 view;
    mat4 projection;
};

uniform mat3 FMatrix [6];

void main()
{

    vec3 newPos = FMatrix[passFIndex[0]] * vec3(-0.5f, -0.5f, 0.5f);
...
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top