Hey Art,
Im Joseba(the post's author), and i tryed osgPPU, but i had some crashes ussing 
the shaders (they started working well, but after some interaction, the app 
crashed). OsgPPU is a 'must have' in OSG, but at this moment my frame rate 
drops too much and i get these crashes...

I finally located the failure, it was that i attached the RTT texture state set 
to the Group node instead to the Drawable.

My problem now is a bit different.
The goal is to do a glow shader for some parts of the scene. For this, my 
approach was to create a very simple shader to 'mark' the parts of the screen 
that i want the glow applied and then use a post process to apply it.
The shader for marking the parts of the scene with glow, only has to output the 
color with an alpha value of 0 (using the texture coords to get the color and 
so)
In a small demo, i loaded the file "cow.osg" and tried to apply this shader to 
it, creating an uniform and attaching it to the cow's drawable stateset, but i 
get the cow an black (not textured).

Here is the code:


Code:

osg::ref_ptr<osg::Program> colorMultProgram = new osg::Program;
        colorMultProgram->setName("MultColor");
        osg::ref_ptr<osg::Shader> verShader = new osg::Shader( 
osg::Shader::VERTEX );
        osg::ref_ptr<osg::Shader> fragShader = new osg::Shader( 
osg::Shader::FRAGMENT );
        
verShader->loadShaderSourceFromFile("./Data/Shaders/vp_glow_alpha.glsl");
        
fragShader->loadShaderSourceFromFile("./Data/Shaders/fp_glow_alpha.glsl");
        colorMultProgram->addShader(verShader);
        colorMultProgram->addShader(fragShader);

...
// load cow.osg and find "cow.osg" geode
...

for(int i=0; i < geode->getNumDrawables(); ++i)
        {
                osg::ref_ptr<osg::StateSet> ss = 
geode->getDrawable(i)->getOrCreateStateSet();
                if(ss->getTextureAttributeList().size()!=0)
                {
                        osg::ref_ptr<osg::Uniform> textureUniform = new 
osg::Uniform();
                        textureUniform->setName("baseMap");
                        textureUniform->setType(osg::Uniform::SAMPLER_2D);
                        textureUniform->set(0);
                        ss->addUniform(textureUniform.get());
                }
                ss->setAttributeAndModes(colorMultProgram, 
osg::StateAttribute::ON); 
                        
        }

...
///// vertex and pixel shaders
...

varying vec2 Texcoord;

void main( void )
{
    gl_Position = ftransform();
    Texcoord    = gl_MultiTexCoord0.xy; 
}


uniform sampler2D baseMap;

varying vec2 Texcoord;

void main( void )
{
    gl_FragColor = vec4(texture2D( baseMap, gl_TexCoord[0].xy).rgb, 0.0);
}




------------------
Read this topic online here:
http://osgforum.tevs.eu/viewtopic.php?p=5812#5812





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to