09/17/08 19:25:39 (7 years ago)

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 : :

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 : :

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.

1 modified


  • 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" 
    9091"    vec4 v = gl_PositionIn[0];\n" 
    91 "    v_color = v;\n" 
     92"    v_color_out = v + v_color[0];\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" 
    111 "    gl_FragColor = v_color;\n" 
     112"    gl_FragColor = v_color_out;\n"