[osg-users] Issue on sharing shaders between objects
Christian Heine
Hellhound at binary-revolution.org
Thu Jun 5 09:33:34 PDT 2008
Hello,
i've played arround with this issue, but i could solve it until now.
First i thought there may be a problem with the reusage of the
program, but when i copy it instead of sharing, nothing happends, i
got the same failure.
// finaly bind the program and activate it if it is user enabled
if(this->m_userEnabled){
for(uniforms_t::iterator uniIter = m_uniformCache.begin();
uniIter != m_uniformCache.end();
uniIter ++){
// add all uniforms from the list to the state
state->addUniform((*uniIter).second.get(),
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE |
osg::StateAttribute::PROTECTED);
}
/* fake for copy program
osg::ref_ptr<osg::Program> prg = new osg::Program;
prg->addBindAttribLocation("tangent",
osg::Drawable::ATTRIBUTE_6);
prg->addBindAttribLocation("binromal",
osg::Drawable::ATTRIBUTE_7);
boost::shared_ptr<OSGTechnique> technique =
this->getOSGTechnique(AbstractTechnique::VERSION_PS30);
// convert BinRev shader params to osg::Uniform and
osg::Attribute objects
for( unsigned int i = 0;
i < technique->getNumberOfShaders();
i++)
{
boost::shared_ptr<OSGGLSLShader> shader =
boost::dynamic_pointer_cast<OSGGLSLShader>(technique->getShader(i));
prg->addShader(shader->getShader().get());
}
*/
state->setAttributeAndModes(prg.get(),
osg::StateAttribute::ON);
}
// otherwise bind the program and deactivate it.
else{
state->setAttributeAndModes(m_program.get(),
osg::StateAttribute::OFF);
}
}
There is nothing realy special...
I've attached an image to show what's going wrong.
Has anyone a hint what could be going wrong? I'm running out of ideas..
Best regards,
Christian
hellhound at binary-revolution.org wrote:
> Hello,
>
> i've successfully implemented a simple dot3 object shading for my scene and
> it works fine with single objects. Now i try to share the shaders between
> different objects in the scene and got some trouble:
>
> To share the shaders i've one osg::Program, where i've added two osg::Shader
> objects. The osg::Program instance is shared between the objects and applied
> to their osg::StateSet objects. The required osg::Uniform objects are created
> explicit for each object and bind to their osg::StateSet in a separated process.
> So only the osg::Program and osg::Shader are Shared (later i will share the
> equal uniforms too).
>
> The shader works, but it's effected on all objects equals to the object where
> the osg::Program has applied first. I.e. i've added two normal mapped cubes in
> the scene. When i set the light between both cubes i expect that both cube faces
> are enlighted arround the light, but on the 2nd cube the thame face of the first
> cube is enlighted...
>
> Have i consider something special for the sharing of (object) shaders between
> objects?
>
> Best regards,
> Christian
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: failure.png
Type: image/png
Size: 200086 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080605/6f1ae253/attachment-0001.png>
More information about the osg-users
mailing list