Changing color of a TrackNode...

classic Classic list List threaded Threaded
1 message Options
2LR 2LR
Reply | Threaded
Open this post in threaded view
|

Changing color of a TrackNode...

I'm needing to change the color of a TrackNode object created with a greyscale image. Right now, I'm creating the TrackNode object with the following code:

osg::ref_ptr<osg::Image> srcImage = osgDB::readRefImageFile(ICON_URL);
osg::ref_ptr<osg::Image> image;
ImageUtils::resizeImage(srcImage.get(), ICON_SIZE, ICON_SIZE, image);
const SpatialReference* geoSRS = mapSRS->getGeographicSRS();
GeoPoint pos(geoSRS, lon, lat);
TrackNode* track = new TrackNode(pos, image.get(), schema);


My fragment shader to change the color of the image is as follows:

const char* tnFS =
                "#version " GLSL_VERSION_STR "\n"
                "in vec2 trackNode_texcoord; \n"
                "uniform sampler2D trackNode_tex; \n"
                "uniform vec4 trackNode_color; \n"
                "void trackNode_icon_FS(inout vec4 out_color) \n"
                "{ \n"
                "    vec4 color = texture(trackNode_tex, trackNode_texcoord); \n"
                "    out_color = color * trackNode_color; \n"
                "} \n";


My virtual program and injection points are:

osgEarth::VirtualProgram* vp = new osgEarth::VirtualProgram();
vp->setFunction("trackNode_icon_VS", tnVS, osgEarth::ShaderComp::LOCATION_VERTEX_MODEL);
vp->setFunction("trackNode_icon_FS", tnFS,
                          osgEarth::ShaderComp::LOCATION_FRAGMENT_COLORING);


I believe this should work. However, I'm not able to see where to find the Image object to add my uniform variables to change the color. If I do the following:

track->getStateSet()->addUniform(new osg::Uniform("trackNode_tex", 0));
track->getStateSet()->addUniform(new osg::Uniform("trackNode_color", osg::Vec4(0.0, 1.0, 0.0, 1.0)));


This just changes the color of the text associated with the trackNode, not the image used for the trackNode.

Can someone help me in how I can apply my shader to the image of the trackNode to change its color?

I'm using osgEarth 3.0 on Windows...

Thanks

Shayne