[osg-users] Possible bug in pragmatic shader composition and optimizers
Sebastian Messerschmidt
sebastian.messerschmidt at gmx.de
Tue Jul 14 01:14:27 PDT 2015
Me again,
I've attached a minimal example which illustrates the problem.
It seems the combination
osgUtil::Optimizer::SHARE_DUPLICATE_STATE |
osgUtil::Optimizer::STATIC_OBJECT_DETECTION
causes the both geometries to be rendered as if the define was not set.
If the optimizer is not run the geometries are rendered as expected.
Cheers
Sebastian
> Hi,
>
> I've got some code, where I set up a define inside for an
> osg::Geometry via
>
> geometry.getOrCreateStateSet()->setDefine("MY_DEFINE")
>
> The geometry is a sibling to another geometry not setting the define.
> It works well if I don't run an osg::Optimizer, but running it
> effectively removes the define.
> Since I don't have the source code at hand, I cannot inspect this
> issue right now.
>
> The optimizer is set up to use the SHARE_DUPLICATE_STATE, so I suspect
> the problem to be inside the logic which determines if two statesets
> are equal.
> I'm using OSG 3.3.9 on Windows 7 64bit
>
> cheers
> Sebastian
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
-------------- next part --------------
#include "osgViewer/Viewer"
#include <osg/PositionAttitudeTransform>
#include <osgDB/ReadFile>
#include <osgUtil/Optimizer>
std::string vert_source =
"void main()\n \
{\n\
gl_Position = ftransform();\n\
}\n\
";
std::string frag_source =
"void main()\n \
{\n\
#pragma import_defines ( TEST_DEFINE )\n\
#ifdef TEST_DEFINE\n\
gl_FragColor = vec4(1,0,0,1);\n\
#else\n\
gl_FragColor = vec4(0,1,0,1);\n\
#endif\n\
}\n\
";
void applyShader(const std::string& vert_source, const std::string& frag_source, osg::StateSet* ss)
{
osg::Program* program = new osg::Program;
osg::Shader* vertex_shader = new osg::Shader(osg::Shader::VERTEX);
vertex_shader->setShaderSource(vert_source);
osg::Shader* fragment_shader = new osg::Shader(osg::Shader::FRAGMENT);
fragment_shader->setShaderSource(frag_source);
program->addShader(vertex_shader);
program->addShader(fragment_shader);
ss->setAttributeAndModes(program, osg::StateAttribute::ON);
}
int main(int argc, char** argv)
{
osg::ref_ptr<osg::Group> scene_root = new osg::Group;
osgViewer::Viewer viewer;
viewer.getCamera()->setDefaults();
osg::Node* axes = osgDB::readNodeFile("axes.osgt");
if (!axes)
{
std::cout << "Didn't find axes.osgb" << std::endl;
exit(1);
}
osg::PositionAttitudeTransform* pat_1 = new osg::PositionAttitudeTransform;
osg::PositionAttitudeTransform* pat_2 = new osg::PositionAttitudeTransform;
pat_1->setPosition(osg::Vec3(-5,0,0));
pat_2->setPosition(osg::Vec3(5,0,0));
pat_1->addChild(axes);
pat_2->addChild(axes);
scene_root->addChild(pat_2);
scene_root->addChild(pat_1);
applyShader(vert_source, frag_source, pat_1->getOrCreateStateSet());
applyShader(vert_source, frag_source, pat_2->getOrCreateStateSet());
pat_2->getOrCreateStateSet()->setDefine("TEST_DEFINE");
osgUtil::Optimizer opt;
opt.optimize(scene_root,
osgUtil::Optimizer::SHARE_DUPLICATE_STATE | osgUtil::Optimizer::STATIC_OBJECT_DETECTION
);
//opt.optimize(scene_root);
viewer.setSceneData(scene_root);
viewer.setUpViewInWindow(10,10,255,255,0);
viewer.run();
}
More information about the osg-users
mailing list