Re: [osg-users] Smooth shading
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::vectorosg::Geometry* VGeo( m_meshes.size() ); for ( size_t iObj=0; iObjm_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_ptrosg::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_ptrosg::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 osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Smooth shading
Hi, you are right. In the code it is set to flat but I have also tried to set to SMOOTH but I never see difference between results. With the smooth setting I still see the face edges ... Thank you! Cheers, Geoffroy -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50858#50858 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Smooth shading
In order to get correct shading results, you have to create correct normals. There is also a smoothing visitor which you could try: osgUtil::SmoothingVisitor sm; model-accept(sm); cheers Sebastian Hi, you are right. In the code it is set to flat but I have also tried to set to SMOOTH but I never see difference between results. With the smooth setting I still see the face edges ... Thank you! Cheers, Geoffroy -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50858#50858 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Smooth shading
Is this method is efficient ( computation time ) or is it a better avenue to use a GLSL frag and vertex shader -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50861#50861 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Smooth shading
Am 29.10.2012 15:38, schrieb Geoffroy Rivet-Sabourin: Is this method is efficient ( computation time ) or is it a better avenue to use a GLSL frag and vertex shader What do you mean? It might be as well a O(n) algorithm, but as long as you do not try if it is suitable for you, you should not question performance. Have you tried it? Usually you run the visitor once per loaded/created model. You cannot simply do this in the vertex shader as you don't have any information about the topology there. I'd stick to simply try and measure it. Another option if you are creating your geometry on your own would be to create correct normals in the first place. cheers Sebastian -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50861#50861 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Smooth shading
it works perfectly Thank you -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50873#50873 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org