How to treat normals when transforming the vertices

Have jReality programming problems or questions? Post them here.
Post Reply
Joe
Posts: 61
Joined: Fri 11. Jul 2008, 19:29

How to treat normals when transforming the vertices

Post by Joe » Wed 6. Apr 2011, 08:21

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?

User avatar
steffen
Posts: 186
Joined: Fri 16. Jun 2006, 13:30
Location: TU Berlin
Contact:

Re: How to treat normals when transforming the vertices

Post by steffen » Wed 6. Apr 2011, 11:31

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.

Joe
Posts: 61
Joined: Fri 11. Jul 2008, 19:29

Re: How to treat normals when transforming the vertices

Post by Joe » Wed 6. Apr 2011, 22:13

Thanks, it works perfectly.

Post Reply