How to change the pointsymbol size with shader

classic Classic list List threaded Threaded
3 messages Options
justjane justjane
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to change the pointsymbol size with shader

I add a modellayer from a shapefile  in pointsymbol . I want to change the point size of this modellayer in runtime with code below,but it did not work. I want to know why and how? is it possible to change the point size with shader?

        char s_scaleShader[] =
                "uniform float scale;\n"
                "void scaleVert(inout vec4 vertexView)\n"
                "{\n"
                "glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);\n"
                "gl_PointSize = gl_PointSize *scale;\n"
                "}\n";

        osg::ref_ptr<VirtualProgram> vp = new VirtualProgram();

        vp->setFunction("scaleVert", s_scaleShader, ShaderComp::LOCATION_VERTEX_CLIP);

        node.getOrCreateStateSet()->setAttributeAndModes(vp, osg::StateAttribute::ON);

        node.getOrCreateStateSet()->getOrCreateUniform("scale", osg::Uniform::FLOAT)->set(20.0);
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to change the pointsymbol size with shader

Jane,
You cannot call glEnable() in GLSL. Instead in OSG you need to call

stateSet->setTextureAttribute(0, new osg::PointSprite());
stateSet->setMode(GL_VERTEX_PROGRAM_POINT_SIZE, osg::StateAttribute::ON);

Then you can use gl_PointSize in your shader.

Hope this helps.
Glenn Waldron / Pelican Mapping
justjane justjane
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to change the pointsymbol size with shader

Hi gwaldron, thanks so much for your advice. but it still did not work. but you give me an inspiration. I change the point size of modellayer in this way:

osg::Point *point = new osg::Point();

point->setSize(50);

osg::Node *layernode = layer->getOrCreateSceneGraph(_mainMap, _mainMap->getReadOptions(), 0L);

layernode ->getOrCreateStateSet()->setAttributeAndModes(point, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);

I take a very twists way to reach my destination. If someone needs,this may help. This method is easier than using shader maybe.
Loading...