-2

This is the geometry shader i made, which from my understanding should simply pass the 3 vertices on to the frag shader? When i remove the geom shader and pass the values straight to the frag shader it works and displays what i want. I am drawing terrain with triangles, each draw call passes 6 vertices (2 triangles) through, perhaps this has something to do with it however i cannot figure out what

#version 330

layout(triangles) in;
layout(triangle_strip, max_vertices = 3)out;


in float gHeight;
in vec4 gSurfacePosition;
in float gTerrainHeight;
in vec2 gTexCoords[3];
in vec4 gNormal[3];


out float oTerrainHeight;
out float oHeight;
out vec4 oNormal;
out vec4 oSurfacePosition;
out vec2 oTexCoords;


void main()
{

    oSurfacePosition=gSurfacePosition;
    oHeight=gHeight;
    oTerrainHeight=gTerrainHeight;

    for(int i = 0; i < 3; i++)
    {
        gl_Position = gl_in[i].gl_Position;

        oNormal = gNormal[i];
        oTexCoords = gTexCoords[i];

        EmitVertex();

    }
}
galaban
  • 11
  • 4

1 Answers1

1
in float gHeight;
in vec4 gSurfacePosition;
in float gTerrainHeight;

This should not compile. Either you haven't checked for errors properly, or your implementation is really lax on reporting errors.

The reason this shouldn't compile is because all GS inputs must be arrayed. You get one input value per vertex in the primitive. Your GS takes triangles as input, and therefore it gets each input value as an array of 3 values. You did this for some of the inputs, but you didn't do it for all of them.

oSurfacePosition=gSurfacePosition;
oHeight=gHeight;
oTerrainHeight=gTerrainHeight;

This doesn't do what you think it does. Every time you call EmitVertex, the value of all out variables becomes undefined. Therefore, every time you want to emit a new vertex, you must set the out variables again. Even if you want to write the same value, you have to set it each time.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • Wow after reading that through i have realised how stupid that was of me, thanks for correcting that. Have only just started using GS today, thanks +1 – galaban Jul 09 '16 at 15:17