[osg-users] Howto perform a dynamic number of shader passes in a osgFX::Effect

paulo paulo.jnkml at gmail.com
Sat Mar 21 11:31:51 PDT 2009


Hi,

I'm trying to control the number of "passes" that I need for my particular objective.
please consider the code for the traversal of the only technique:

void DefaultTechnique::traverse(osg::NodeVisitor& nv, osgFX::Effect* fx) {
    osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv);

    if(!cv) {
        osgFX::Technique::traverse(nv, fx);
        return;
    }

    //TODO: where? once here or once for every loop step?
    //cv->pushStateSet(getPassStateSet(0));
    osg::Node* override = getOverrideChild(0);

    const uint num_passes(computeNeededPasses());

    for(uint i(0); i != num_passes; ++i) {
        cv->pushStateSet(getPassStateSet(0));
		
        //This tech uses a shader. (just as an example we do some assignments here)
        uniform_a->set(i + 2.0f);
        uniform_b->set(i * 2.0f);

        if(override) override->accept(*cv);
        else fx->inherited_traverse(*cv);

        cv->popStateSet();
    }

    //cv->popStateSet();
}

Not only I don't really know where to place the push and pop of the sate, but I also don't know if this is overall correct.

Should I place the state's push and pop inside or outside of the loop? 
If neither, then where?

Both inside and outside I get:
Warning: detected OpenGL error 'invalid operation' after RenderBin::draw(,)

I can't use the callbacks, since I need to update the uniforms once per pass, and I don't know how many passes I will have to do since it's a user parameter changed interactively.

I would appreciate you help please.
It would avoid me digging code for hours to try to understand how to use the osgFX passes.

Thank you

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=8882#8882








More information about the osg-users mailing list