[SOLVED] Mesh Normals get wrong with rotation

Crystal Hammer

23-10-2012 19:12:49

I tried to have diffuse lighting on leaves and I found this issue.
Then I tested with sphere (Ogre's geosphere4500.mesh),
here is the result:
Every next instance gets rotated by 30 degrees. I'm showing normal vector as color.
It's a sphere so they all should look the same. Same as the spheres on road which are not rotated meshes).
This looks like some distortion, it gets worse on tree meshes.
Can't do proper lighting with this, not to mention specular or bump mapping.
Do you know what's wrong ? Can it be fixed ?

Crystal Hammer

30-10-2012 10:56:37

OK I have fixed it.
Edit in both files: BatchedGeometry.cpp line 891, and WindBatchedGeometry.cpp line 285

// rotate vector by matrix. Ogre::Matrix3::operator* (const Vector3&) is not fast
destPtr[0] = float(mat[0] * sourcePtr[0] + mat[1] * sourcePtr[1] + mat[2] * sourcePtr[2]); // x
destPtr[1] = float(mat[3] * sourcePtr[0] + mat[4] * sourcePtr[1] + mat[5] * sourcePtr[2]); // y
destPtr[2] = float(mat[6] * sourcePtr[0] + mat[6] * sourcePtr[1] + mat[6] * sourcePtr[2]); // z

Of course the last line has to be so:

destPtr[2] = float(mat[6] * sourcePtr[0] + mat[7] * sourcePtr[1] + mat[8] * sourcePtr[2]); // z

So 6 7 8 not 6 6 6.
Lol guys, that's a TYPO. :shock:
Did satan :twisted: mess around here ? :lol:


14-01-2017 05:42:20

thanks for posting this!!!