Just try this and see how it works: geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
Brian This is a PRIVATE message. If you are not the intended recipient, please delete without copying and kindly advise us by e-mail of the mistake in delivery. NOTE: Regardless of content, this e-mail shall not operate to bind CSC to any order or other contract unless pursuant to explicit written agreement or government initiative expressly permitting the use of e-mail for such purpose. [email protected] wrote: ----- To: OpenSceneGraph Users <[email protected]> From: Werner Modenbach <[email protected]> Sent by: [email protected] Date: 08/26/2010 07:08AM Subject: Re: [osg-users] Issue with normal vectors Thanks Robert, I get closer to it. Just for verification: If I have i.e. 10 vertexes and I get 20 calls to the callback method each defining a triangle. Each call gives me 3 indexes, 3 normals and 3 texcoords. Right now I just push everything into the corresponding arrays and at the end I call: geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, osgVertexIndices->size())); You say this will not work because: 1) geometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET); expects just 1 normal for the whole thing (?) 2) Texture coordinates are allways bound per vertex? In this case I have to: 1) initialize a normal array with Vec3(0.0, 0.0, 0.0) for each triangle callback I have to look on each vertex index , if the indexes normal is 0 if yes: just set it if no: duplicate the vertex at the end of the vertexes and push_back the normal 2) do something comparable on the texcoords Is that your recommendation? Is there any way to bind normals to the vertex indexes? Thanks in advance! - Werner - Am Donnerstag, 26. August 2010 12:06:34 schrieb Robert Osfield: > Hi Werner, > > > BIND_PER_PRIMITIVE_SET will mean that you'll have one of the > associated attribute (i.e. colour, normal) per osg::PrimitiveSet > attached the osg::Geometry, so if you have one osg::DrawElementsUShort > used for the triangles then you'll need just one of the associated > attribute for it. > > BIND_PER_PRIMITIVE will apply the attribute per primitive in you case > per triangle. > > Tex coords in the OSG are always bound per vertex, there isn't a > control to alter this. > > If you have a vertex array and indices for your triangles the natural > thing to do would be to use a osg::DrawElementsUShort(GL_TRIANGLES) > then use push_back(tri.p1) for each index on each triangle. > > I would suggest binding the normals per vertex, you'll have to do this > for the tex coords as well. If a single vertex will have multiple tex > coords or multiple normals associated with it due to differences in > the triangles then you'll need to duplicate the vertices and remap the > indices on the triangles to fit this. > > Robert. > > On Thu, Aug 26, 2010 at 10:38 AM, Werner Modenbach > > <[email protected]> wrote: > > Thank you Paul for your response. > > > > Yes, you are right, the solution isn't perfect at all. But I'm > > integrating some external code which is just giving me a vertex array > > and a per triangle callback with vertex indexes and normal and texture > > coords. > > > > And further more I need some screenshots very urgently for a customer > > presentation. > > > > The performance improvement has to wait :-( > > > > So I try to analyse why it's not working. And I detected something I > > don't understand. > > In my opinion it should give the same result having: > > 1) one normal per triangle an binding PER_PRIMITIVE > > 2) 3 times the same normal and binding PER_PRIMITIVE_SET > > > > But it doesn't. So I'm confused. > > > > Thanks for further hints. > > > > - Werner - > > > > Am Mittwoch, 25. August 2010 22:41:14 schrieb Paul Martz: > >> Werner Modenbach wrote: > >> > Maybe someone can give me some explanation on my stupid little > >> > problem. > >> > > >> > I have a geometry being composed of TRIANGLES. > >> > I have a vertex-array, a verted-index-array and a normal-array > >> > assigned to my geometry. > >> > >> Off-topic: Do you need to use the vertex-index-array? It is deprecated: > >> /** deprecated - forces OpenGL slow path, just kept for > >> backwards compatibility.*/ > >> void setVertexIndices(IndexArray* array); > >> > >> > 3 indexes and 3 normals per Triangle. > >> > Normal binding is set to BIND_PER_PRIMITIVE_SET. > >> > > >> > Unfortunately the rendering shows the geometry flat in curious dark > >> > colors and some unexpected light behaviour. > >> > For analysis purpose I set the normal binding to BIND_PER_PRIMITIVE > >> > and pushed just 1 normal per TRIANGLE. > >> > Everything looks good except I see the triangles and the geometry > >> > isn't smooth. > >> > The next test is pushing the same normal vector 3 times and setting > >> > the binding back to BIND_PER_PRIMITIVE_SET. > >> > In my understanding this should give the same optical result as > >> > before. Unfortunately it doesn't and everything is dark again. > >> > > >> > I guess, I misunderstand something with the normal bindings. > >> > > >> > Any hint is highly appreciated. Thanks in advance > >> > >> I'm not sure why you don't use BIND_PER_VERTEX, as you stated above that > >> your normal array contains 3 normals per triangle, so you have one > >> normal per vertex, right? > >> > >> BIND_PER_PRIMITIVE would result in flat shading (only one normal used > >> for each triangle -- which, by the way, also forces OpenGL down the > >> slow path), and BIND_PER_PRIMITIVE_SET would be even more granular: one > >> normal used for each PrimitiveSet you add to the Geometry. This would > >> make all triangles in the PrimitiveSet either uniformly dark or > >> uniformly lit, depending on the direction of the one normal used for > >> the whole group. > >> > >> For analysis purposes, I suggest using the normals pseudoloader: > >> > osgviewer dumptruck.osg.normals > >> > >> Hope that helps, > >> -Paul > >> > >> _______________________________________________ > >> osg-users mailing list > >> [email protected] > >> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or > >> g > > > > -- > > TEXION Software Solutions > > > > TEXION GmbH - Rotter Bruch 26a - D 52068 Aachen - HRB 14999 Aachen > > Fon: +49 241 475757-0, Fax: +49 241 475757-29, web: http://www.texion.eu > > > > Geschäftsführer/Managing Director: Werner Modenbach > > _______________________________________________ > > 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 -- TEXION Software Solutions TEXION GmbH - Rotter Bruch 26a - D 52068 Aachen - HRB 14999 Aachen Fon: +49 241 475757-0, Fax: +49 241 475757-29, web: http://www.texion.eu Geschäftsführer/Managing Director: Werner Modenbach _______________________________________________ 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

