Page 1 of 1

How to treat normals when transforming the vertices

Posted: Wed 6. Apr 2011, 08:21
by Joe
Hello,
I have created geometry with normals. The smooth-shading works fine.

Now, in some cases, I have to transform the vertices with a Matrix4d, before inserting them into the IndexedFaceSetFactory. The smooth-shading is broken. While rotating the geometry, strange shadows appear on the surface. Even if I apply the same transformation to the normals (before inserting them into the IndexedFaceSetFactory), the smooth shading isn't as beatiful as without the applied transformation.

I'm sure that this is a mathematical problem, but I have not enough experience and knowledge to fix this.
One solution could be to appley the transformation to the parent SceneGrapgComponent. But it would be easier for me, to just transform the vertices and adapt the normals.
Another solution is to let the normals be generated by jReality. But the normals, which I can provide, do look a little bit better.

Is this a know problem in computer graphics? What do I have to do with the normals, when transforming the vertices?

Re: How to treat normals when transforming the vertices

Posted: Wed 6. Apr 2011, 11:31
by steffen
If your matrix contains a translation, you need to make sure that you do not translate the normals. The easiest thing is to copy the matrix, and set the 4th column to {0, 0, 0, 1}. Then multiply each normal with that matrix.

Re: How to treat normals when transforming the vertices

Posted: Wed 6. Apr 2011, 22:13
by Joe
Thanks, it works perfectly.