GLSL 1.5 Geometry shader issue


I’ve been playing with shaders using OpenSceneGraph and as an experiment, I thought I’d try implementing vertex normals using a geometry shader.

What’s odd is that I can get the shader to output only two of the three normals at a time and I have no idea why. If I comment out any one of the three normals, the other two are rendered fine. If, however, I try to render all three, the shader fails.

Unfortunately, I’m having a difficult time extracting the log in OSG, so I don’t have compile error information (working on that, though).

That said, I have no idea why the code doesn’t work for all three normals, nor am I sure that the problem is in the shader code (it could be something with OSG, I suppose).

Anyway, the shader code follows. Any thoughts would be appreciated.

vertex shader:

#version 150
uniform mat4  osg_ModelViewMatrix;  //from application program.
uniform mat4  osg_ModelViewProjectionMatrix;
in vec4       osg_Vertex;     //from vertex buffer from app pgm.

void main (void) {
  gl_Position = osg_ModelViewMatrix * osg_Vertex;

geometry shader:

#version 150
layout (triangles) in;
layout (line_strip, max_vertices = 6) out;
uniform mat4  osg_ProjectionMatrix;  //from application program.
out vec3 normal;

void main (void) {
  vec3        vector1;
  vec3        vector2;

  vector1 = gl_in[1] - gl_in[0];
  vector2 = gl_in[2] - gl_in[0];
  normal = normalize (cross (vector1, vector2));
  gl_Position = osg_ProjectionMatrix * gl_in[0].gl_Position;
  EmitVertex ();

  gl_Position = osg_ProjectionMatrix * (gl_in[0].gl_Position + vec4(normal, 0.0));
  EmitVertex ();

  gl_Position = osg_ProjectionMatrix * gl_in[1].gl_Position;
  EmitVertex ();

  gl_Position = osg_ProjectionMatrix * (gl_in[1].gl_Position + vec4(normal, 0.0));
  EmitVertex ();

  EndPrimitve ();
  gl_Position = osg_ProjectionMatrix * gl_in[2].gl_Position;
  EmitVertex ();

  gl_Position = osg_ProjectionMatrix * (gl_in[2].gl_Position + vec4(normal, 0.0));
  EmitVertex ();

frag shader:

#version 150
in vec3   normal;  //from geometry shader.
out vec4  color;   //to framebuffer.

void main (void) {
  gl_FragColor = vec4 (normal, 1.0);

When I compile to check your shaders, a log error is generated:

OpenGL Version: 4.1.0 NVIDIA 260.19.21
Can't compile Fluid.zG:
0(243) : error C1008: undefined variable "EndPrimitve"

Hence, you have a typo in your geometry shader
replace “EndPrimitve” with “EndPrimitive”.

Ya know, I reread that code several times trying to find typos - that’s happened to me before. :o Anyway, I’ve gotta figure
out how to get the logs out of OSG - much less embarrassing to have a compiler tell me that I can’t type…

Thanks for catching that.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.