From 274aa49f8aaa137f79b0d37b2617718c545a1062 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 17 Sep 2008 17:25:39 +0000 Subject: [PATCH] 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. " --- examples/osggeometryshaders/osggeometryshaders.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/osggeometryshaders/osggeometryshaders.cpp b/examples/osggeometryshaders/osggeometryshaders.cpp index 45d2ccbed..a61aadb68 100644 --- a/examples/osggeometryshaders/osggeometryshaders.cpp +++ b/examples/osggeometryshaders/osggeometryshaders.cpp @@ -84,11 +84,12 @@ static const char* geomSource = { "#version 120\n" "#extension GL_EXT_geometry_shader4 : enable\n" "uniform float u_anim1;\n" -"varying vec4 v_color;\n" +"varying in vec4 v_color[];\n" +"varying out vec4 v_color_out;\n" "void main(void)\n" "{\n" " vec4 v = gl_PositionIn[0];\n" -" v_color = v;\n" +" v_color_out = v + v_color[0];\n" "\n" " gl_Position = v + vec4(u_anim1,0.,0.,0.); EmitVertex();\n" " gl_Position = v - vec4(u_anim1,0.,0.,0.); EmitVertex();\n" @@ -105,10 +106,10 @@ static const char* fragSource = { "#version 120\n" "#extension GL_EXT_geometry_shader4 : enable\n" "uniform float u_anim1;\n" -"varying vec4 v_color;\n" +"varying vec4 v_color_out;\n" "void main(void)\n" "{\n" -" gl_FragColor = v_color;\n" +" gl_FragColor = v_color_out;\n" "}\n" };