Show
Ignore:
Timestamp:
09/17/08 19:25:39 (6 years ago)
Author:
robert
Message:

From Christophe Loustaunau,"
I have found some errors on the example osgGeometryShaders. It's about the varying in the geometry shader.
take a look at the varying vec4 v_color.
In the vertex shader, v_color is initialized to gl_vertex
then in the geometry shader v_color is initialized to gl_PositionIn[0]
and in the fragment shader v_color is used as the fragment color.

Try to initialized v_color to vec4(1.0, 0.0, 0.0, 1.0) in the vertex shader and comment the line :
" v_color = v;\n" in the geometry shader, and you will see the lines as black !

It's because you have to use keywords in and out.

extract from : http://www.opengl.org/registry/specs/EXT/geometry_shader4.txt :

in - for function parameters passed into a function or for input varying
variables (geometry only)

out - for function parameters passed back out of a function, but not
initialized for use when passed in. Also for output varying variables
(geometry only).

Then for a geometry shader, a varying must be an array :
extract from : http://www.opengl.org/registry/specs/EXT/geometry_shader4.txt :

Since a geometry shader operates on primitives, each input varying variable needs to be
declared as an array. Each element of such an array corresponds to a
vertex of the primitive being processed. If the varying variable is
declared as a scalar or matrix in the vertex shader, it will be a
one-dimensional array in the geometry shader. Each array can optionally
have a size declared. If a size is not specified, it inferred by the
linker and depends on the value of the input primitive type.

Here is a patch based on the svn version of osg that correct that.
"

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osggeometryshaders/osggeometryshaders.cpp

    r7776 r8871  
    8585"#extension GL_EXT_geometry_shader4 : enable\n" 
    8686"uniform float u_anim1;\n" 
    87 "varying vec4 v_color;\n" 
     87"varying in vec4 v_color[];\n" 
     88"varying out vec4 v_color_out;\n" 
    8889"void main(void)\n" 
    8990"{\n" 
    9091"    vec4 v = gl_PositionIn[0];\n" 
    91 "    v_color = v;\n" 
     92"    v_color_out = v + v_color[0];\n" 
    9293"\n" 
    9394"    gl_Position = v + vec4(u_anim1,0.,0.,0.);  EmitVertex();\n" 
     
    106107"#extension GL_EXT_geometry_shader4 : enable\n" 
    107108"uniform float u_anim1;\n" 
    108 "varying vec4 v_color;\n" 
     109"varying vec4 v_color_out;\n" 
    109110"void main(void)\n" 
    110111"{\n" 
    111 "    gl_FragColor = v_color;\n" 
     112"    gl_FragColor = v_color_out;\n" 
    112113"}\n" 
    113114};