Hi Geoffroy.
If you want smooth shading, why are you setting it to FLAT?
sm->setMode( osg::ShadeModel::FLAT );
should read:
sm->setMode( osg::ShadeModel::SMOOTH);
Hi,
I try to add smooth shading to my geometry but for the moment I do not have
real success.
I use this simple code
Code:
osg::Geode *geode = new osg::Geode;
osg::Group* root = new osg::Group();
std::vector<osg::Geometry*> VGeo( m_meshes.size() );
for ( size_t iObj=0; iObj<m_meshes.size(); ++iObj )
{
VGeo[iObj] = CreateTriangularGeometry( m_meshes[iObj], osg::Vec4(0.0f, 1.0f,
0.0f, 0.25f) );
// Create an array of four colors.
osg::ref_ptr<osg::Vec4Array> c = new osg::Vec4Array;
VGeo[iObj]->setColorArray( c.get() );
VGeo[iObj]->setColorBinding( osg::Geometry::BIND_PER_PRIMITIVE
);
for ( size_t i=0; i< m_meshes[iObj].n_faces(); ++i )
c->push_back( osg::Vec4( 1.f, 0.f, 0.f, 1.f ) );
// Create an array for the single normal.
osg::ref_ptr<osg::Vec3Array> n = new osg::Vec3Array;
VGeo[iObj]->setNormalArray( n.get() );
VGeo[iObj]->setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE
);
m_meshes[iObj].request_face_normals();
m_meshes[iObj].update_face_normals ( );
OM_Mesh::FaceIter f_it;
OM_Mesh::Point N;
for ( f_it=m_meshes[iObj].faces_begin();
f_it!=m_meshes[iObj].faces_end(); ++f_it )
{
N = m_meshes[iObj].normal ( f_it );
n->push_back( osg::Vec3( N[0], N[1], N[2] ) );
}
geode->addDrawable( VGeo[iObj] );
}
osg::StateSet* state = geode->getOrCreateStateSet();
osg::ShadeModel* sm = new osg::ShadeModel();
sm->setMode( osg::ShadeModel::FLAT );
state->setAttribute( sm );
geode->setStateSet( state );
root->addChild( geode );
I have tried to change from flat to smooth shading but I never seen any
difference. Is it the right way to obtain a flat shading?
Thank you!
Cheers,
Geoffroy[/code]
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=50844#50844
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org