osgpcl::SurfelFactory<PointT, NormalT>::SurfelFactory(float radius) { const char *vertShader = { "#version 120\n" "void main(){\n" " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" " gl_FrontColor = gl_Color;\n" " gl_TexCoord[0] = gl_MultiTexCoord0;\n" "}\n" }; const char *geomShader = { "#version 120\n" "#extension GL_EXT_geometry_shader4 : enable\n" "#define PI_6 3.1456/6\n" "#define PI_3 3.1456/3\n" "#define PI2 3.1456*2\n" "uniform float radius;\n" "void main( void )\n" "{\n" "for( int i = 0 ; i < 1 ; i++ ){\n" "vec4 center = gl_PositionIn [ i ]; \n" "gl_FrontColor = gl_FrontColorIn[ i ]; \n" "gl_TexCoord[0] = gl_TexCoordIn [ i ][ 0 ];\n" "gl_Position = center;\n" "EmitVertex();\n" "gl_Position = center+ gl_ModelViewProjectionMatrix*vec4(1.0 , 0.0,0,0)*radius;\n" "EmitVertex();\n" "gl_Position = center+ gl_ModelViewProjectionMatrix*vec4(0.866025403784 , 0.5 ,0, 0)*radius;\n" "EmitVertex();\n" "for(float theta = PI_3; theta <= PI2; theta+= PI_6){\n" " gl_Position = center;\n" " EmitVertex();\n" " gl_Position = center+ gl_ModelViewProjectionMatrix*vec4(cos(theta) , sin(theta) , 0,0)*radius;\n" " EmitVertex();\n" "}\n" "}\n" "}\n" }; osg::ref_ptr<osg::Program> surfel_program = new osg::Program; surfel_program->setName("Surfel"); surfel_program->addShader(new osg::Shader(osg::Shader::VERTEX, vertShader)); surfel_program->addShader(new osg::Shader(osg::Shader::GEOMETRY, geomShader)); surfel_program->setParameter(GL_GEOMETRY_VERTICES_OUT_EXT, 3 + 24); surfel_program->setParameter(GL_GEOMETRY_INPUT_TYPE_EXT, GL_POINTS); surfel_program->setParameter(GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_TRIANGLE_STRIP); stateset_ = new osg::StateSet; stateset_->setAttribute(surfel_program); osg::Uniform *uradius(new osg::Uniform("radius", radius)); stateset_->addUniform(uradius); stateset_->setMode(GL_LIGHTING, osg::StateAttribute::OFF); }
osgpcl::SurfelFactoryI<PointT, NormalT, IntensityT>::SurfelFactoryI(float radius) { const char* vertShader = { "#version 120\n" "varying out vec3 normpt;\n" "void main(){\n" " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" " gl_FrontColor = gl_Color;\n" " gl_TexCoord[0] = gl_MultiTexCoord0;\n" " normpt=gl_NormalMatrix * gl_Normal;\n" "}\n" }; const char* geomShader = { "#version 120\n" "#extension GL_EXT_geometry_shader4 : enable\n" "#define PI_6 3.1456/6\n" "#define PI_3 3.1456/3\n" "#define PI2 3.1456*2\n" "uniform float radius;\n" "varying in vec3 normpt[1];\n" "void main( void )\n" "{\n" "vec3 normal = normpt[0];\n" "mat4 nrot; nrot[0]= vec4(1,0,0,0); nrot[1] =vec4(0,1,0,0); nrot[2]= vec4(0,0,1,0); nrot[3]= vec4(0,0,0,1);\n" "nrot[2][0]=normal[0]; nrot[2][1]=normal[1]; nrot[2][2]=normal[2];\n" "vec3 ax ; if (abs(normal[0])>0.5) { ax =vec3(0,1,0) ;} else ax = vec3(1,0,0); \n" "ax = normalize( ax -normal*dot(ax,normal)); nrot[0][0]=ax[0]; nrot[0][1]=ax[1]; nrot[0][2]=ax[2];\n" "ax = normalize(cross(normal,ax)); nrot[1][0]=ax[0]; nrot[1][1]=ax[1]; nrot[1][2]=ax[2];\n" "for( int i = 0 ; i < 1 ; i++ ){\n" "vec4 center = gl_PositionIn [ i ]; \n" "gl_FrontColor = gl_FrontColorIn[ i ]; \n" "gl_TexCoord[0] = gl_TexCoordIn [ i ][ 0 ];\n" "gl_Position = center;\n" "EmitVertex();\n" "gl_Position = center+ nrot*vec4(1.0 , 0.0,0,0)*radius;\n" "EmitVertex();\n" "gl_Position = center+ nrot*vec4(0.866025403784 , 0.5 ,0, 0)*radius;\n" "EmitVertex();\n" "for(float theta = PI_3; theta <= PI2; theta+= PI_6){\n" " gl_Position = center;\n" " EmitVertex();\n" " gl_Position = center+ nrot*vec4(cos(theta) , sin(theta) , 0,0)*radius;\n" " EmitVertex();\n" "}\n" "}\n" "}\n" }; osg::ref_ptr<osg::Program> surfel_program = new osg::Program; surfel_program->setName( "Surfel" ); surfel_program->addShader( new osg::Shader( osg::Shader::VERTEX, vertShader ) ); surfel_program->addShader( new osg::Shader( osg::Shader::GEOMETRY, geomShader ) ); surfel_program->setParameter( GL_GEOMETRY_VERTICES_OUT_EXT, 3+24 ); surfel_program->setParameter( GL_GEOMETRY_INPUT_TYPE_EXT, GL_POINTS ); surfel_program->setParameter( GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_TRIANGLE_STRIP ); stateset_ = new osg::StateSet; stateset_->setAttribute(surfel_program); osg::Uniform* uradius( new osg::Uniform( "radius", radius ) ); stateset_->addUniform( uradius ); stateset_->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); }