Passing variables from a geometric shader to a fragment shader

I have a GLSL geometry shader that looks like this:

#version 150

uniform mat4 p;
uniform mat4 mv;
uniform mat3 nm;

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

out vec4 test;

void main() {
    for (int i = 0; i < gl_in.length(); i++) {
        ....        
        gl_Position = p * mv * gl_in[i].gl_Position;
        test = vec4(1.0, 0.0, 0.0, 0.0);
        EmitVertex();       
        ....        
        EndPrimitive();
    }
}

However, when I try to access the “test” in my fragment shader, my application crashes. Here is my fragment shader:

#version 150

out vec4 fColor;
in vec4 test;

void main(void) {
    fColor = vec4(test.x, 1.0, 0.4, 0);
}

Can someone help me pass a variable from geometry to a fragment shader? varyingdeprecated in #version 150.

+3
source share
1 answer

You need to declare the test as an input in your fragment shader (I wonder why the shader compiles):

in vec4 test;
+2
source

All Articles