Hi,

i need a little help with some lighting issues. the geometry, a roof, consists 
of a drawable with one primitive (DrawElement TRIANGLES) and associated normal 
vectors per vertex. the problem is, the resulting shading of the rendering is 
not what i have expected. 

[Image: http://www.spatiality.at/osg/roof_solid.png ]
[Image: http://www.spatiality.at/osg/roof_wire.png ]

face1 is like wanted, but face2 and face3 seem odd for me. 

is this caused by a to crude mesh?

Thank you very much!
Christian

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



#include <osgGA/StateSetManipulator>
#include <osg/StateSet>

#include <osg/Node>
#include <osg/Group>
#include <osg/Geode>
#include <osg/Geometry>
#include <osgViewer/Viewer>
#include <osgGA/TrackballManipulator>
#include <osg/ShadeModel> 

int main()
{
   osg::Group* root = new osg::Group();
   osg::Geode* polygonGeode = new osg::Geode;
   osg::Geometry* polygonGeometry = new osg::Geometry;
   polygonGeode->addDrawable(polygonGeometry);
   root->addChild(polygonGeode);

   osg::Vec3Array* polygonVertices = new osg::Vec3Array;
   polygonVertices->push_back( osg::Vec3(400, 400, 0) );
   polygonVertices->push_back( osg::Vec3(300, 400, 0) );
   polygonVertices->push_back( osg::Vec3(300, 300, 0) );
   polygonVertices->push_back( osg::Vec3(500, 300, 0) );
   polygonVertices->push_back( osg::Vec3(500, 500, 0) );
   polygonVertices->push_back( osg::Vec3(400, 500, 0) );
   polygonVertices->push_back( osg::Vec3(300, 350, 50) );
   polygonVertices->push_back( osg::Vec3(450, 350, 50) );
   polygonVertices->push_back( osg::Vec3(450, 500, 50) );
   polygonGeometry->setVertexArray(polygonVertices);

   osg::DrawElementsUInt* polygonBase = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
   polygonBase->push_back(1);
   polygonBase->push_back(2);
   polygonBase->push_back(6);
   polygonBase->push_back(2);
   polygonBase->push_back(3);
   polygonBase->push_back(6);
   polygonBase->push_back(6);
   polygonBase->push_back(3);
   polygonBase->push_back(7);
   polygonBase->push_back(3);
   polygonBase->push_back(4);
   polygonBase->push_back(7);
   polygonBase->push_back(7);
   polygonBase->push_back(4);
   polygonBase->push_back(8);
   polygonBase->push_back(4);
   polygonBase->push_back(5);
   polygonBase->push_back(8);
   polygonBase->push_back(5);
   polygonBase->push_back(7);
   polygonBase->push_back(8);
   polygonBase->push_back(5);
   polygonBase->push_back(0);
   polygonBase->push_back(7);
   polygonBase->push_back(7);
   polygonBase->push_back(0);
   polygonBase->push_back(6);
   polygonBase->push_back(0);
   polygonBase->push_back(1);
   polygonBase->push_back(6);
   polygonGeometry->addPrimitiveSet(polygonBase);

	//osg::StateSet* stateSet = root->getOrCreateStateSet();
	//osg::ShadeModel* shadeModel = new osg::ShadeModel;
	//shadeModel->setMode(osg::ShadeModel::FLAT);
	//stateSet->setAttribute(shadeModel);

//	osg::Vec3 lightPosition(-1.0, -1.0, 2.0);
//	osg::ref_ptr<osg::LightSource> lightSource = new osg::LightSource;
//	lightSource->setDataVariance(osg::Object::DYNAMIC);
//	lightSource->getLight()->setPosition(osg::Vec4(lightPosition, 0));
////	lightSource->getLight()->setAmbient(osg::Vec4(0.2, 0.2, 0.2, 1.0));
//	lightSource->getLight()->setDiffuse(osg::Vec4(0.4, 0.4, 0.4, 1.0));
////	root->addChild(lightSource);

   osg::Vec3Array* normals = new osg::Vec3Array;
   polygonGeometry->setNormalArray(normals);
   polygonGeometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
   { osg::Vec3 norm(-1, 0, 0); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(-1, 0, 0); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(-1, 0, 0); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(0, -1, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(0, -1, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(0, -1, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(0, -1, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(0, -1, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(0, -1, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(1, 0, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(1, 0, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(1, 0, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(1, 0, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(1, 0, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(1, 0, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(0, 1, 0); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(0, 1, 0); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(0, 1, 0); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(-1, 0, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(-1, 0, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(-1, 0, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(-1, 0, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(-1, 0, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(-1, 0, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(0, -1, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(0, -1, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(0, -1, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(0, -1, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(0, -1, 1); norm.normalize(); normals->push_back(norm); }
   { osg::Vec3 norm(0, -1, 1); norm.normalize(); normals->push_back(norm); }

   osgViewer::Viewer viewer;
   viewer.setSceneData( root );

   viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
	viewer.run();
}
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to