[osg-users] VRML Normal Issue

Ben Axelrod baxelrod at coroware.com
Wed Mar 25 17:05:15 PDT 2009

Thanks for the info.

I took a look at the code.  Adding crease angle support does seem tricky since I think we would have to create new vertex points on the fly to accommodate 2 or more different normal vectors at that point.  Here is some off the cuff pseudo code.

for (int i = 0; i != *it; ++i) // line 268 of IndexedFaceSet.cpp
    float angle = acos((*normals)[indices[index + i]] * normal);

    if (angle <= creaseAngle)
        (*normals)[indices[index + i]] += normal;
        // clone this vertex so we can give it 2 normals
        coords.push_back(coords[indices[index + i]]);

        // give it the new normal

        // now point this face at the new vertex
        indices[index + i] = coords.size() - 1;

I am not sure if modifying the vertex and normal array on the fly is wise, possible, or even if that is how it's done.  But like I said, it is pseudo code.

What do you think?

-----Original Message-----
From: osg-users-bounces at lists.openscenegraph.org [mailto:osg-users-bounces at lists.openscenegraph.org] On Behalf Of Jan Ciger
Sent: Wednesday, March 25, 2009 4:43 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] VRML Normal Issue

Hash: SHA1

Ben Axelrod wrote:
> Just to clarify, the way the normals *should* work is sketched in the
> attached image.  Please verify.
> When the angle between 2 faces is sharper than the crease angle,
> there is one normal per face, and when the angle is smoother than the
> crease angle, the normal is averaged.

Correct - what I had in mind was the angle between the normals, not the
faces. The end result would be the same, but this is how the VRML spec
specifies it and it is easier to calculate:

> The creaseAngle field, used by the ElevationGrid, Extrusion, and
> IndexedFaceSet nodes, affects how default normals are generated. If
> the angle between the geometric normals of two adjacent faces is less
> than the crease angle, normals shall be calculated so that the faces
> are smooth-shaded across the edge; otherwise, normals shall be
> calculated so that a lighting discontinuity across the edge is
> produced. For example, a crease angle of .5 radians means that an
> edge between two adjacent polygonal faces will be smooth shaded if
> the geometric normals of the two faces form an angle that is less
> than .5 radians. Otherwise, the faces will appear faceted. Crease
> angles must be greater than or equal to 0.0.


However, as I said - right now the loader will average *always*,
regardless of the crease angle. This is even documented in the code:

IndexedFaceSet.cpp, line 241:
> // GvdB: So I ended up computing the smoothing normals myself. Also,
> I might add support for "creaseAngle" if a big need for it rises. //
> However, for now I can perfectly live with the fact that all edges
> are smoothed despite the use of a crease angle.



Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org

osg-users mailing list
osg-users at lists.openscenegraph.org

More information about the osg-users mailing list