Advertisement

Fix normals on inverted scale matrix

Started by August 15, 2019 06:34 AM
5 comments, last by B-Real 5 years, 1 month ago

Hi,
sometimes a 3D file can contain some objects within its scene graph which can be inverted by a scale of -1, f.e. to mirror those objects. I have already disabled back face culling, but I am struggling to find a way to keep the normals outside.. Do don't really want to offer an user-option like "Invert Normals"..

Any Ideas?
Thx

I don't know if your approach with the inverted scale matrix is really a good solution since it generates other problems (disabling backface culling because of triangle winding order).

However, I am a little bit short on time, so I didn't think much about your problem and there is probably a smarter way but what should work is the following:

Calculate the normal of the triangle using the cross product. Make sure it points to the same side of the surface as your vertex normals. Maybe you need to invert the normal if it isn't the case.  Now calculate the rotation to align the triangles normal with an arbitrary axis. Apply this rotation to all vertex normals, flip signs on the chosen axis and rotate back. Now your normals should be fixed.

Since all the involved operations can be expressed by orthogonal matrices, the matrix product of the single step should also be an orthogonal matrix. This means that you can probably do the whole thing with a single reflection but I am not sure about the reflection axis/plane. Maybe one could see it if one does the math on paper. Otherwise you can try to google something like "normal reflections" or more generally "3d reflections".

Running out of time, so sorry if i told total BS.

Greetings

Advertisement
3 hours ago, B-Real said:

sometimes a 3D file can contain some objects within its scene graph which can be inverted by a scale of -1, f.e. to mirror those objects. I have already disabled back face culling, but I am struggling to find a way to keep the normals outside.. Do don't really want to offer an user-option like "Invert Normals"..

Any Ideas?

Are the normals imported from the file, or are you computing them yourself? (Based on what you said I'm guessing the latter, but it might be helpful to clarify.)

28 minutes ago, Zakwayda said:

Are the normals imported from the file, or are you computing them yourself? (Based on what you said I'm guessing the latter, but it might be helpful to clarify.)

Yes the normals are also imported from the file (FBX).

23 minutes ago, Zakwayda said:

Are the normals imported from the file, or are you computing them yourself? (Based on what you said I'm guessing the latter, but it might be helpful to clarify.)

I think he imports them. Problem is, that if you use an inverse scale, all normals need to be adjusted too, otherwise they point into the wrong direction.

However, wasn't sure about that the first time I posted and am still not sure, but the tool you need may be Householder reflexions:

https://en.wikipedia.org/wiki/Householder_transformation

https://de.wikipedia.org/wiki/Householdertransformation

Check the linked german wiki too, because it contains a nice picture which isn't in the English version. I am currently learning about this topic myself, so no guarantees for the correctness, but the transformation matrix you need to apply to all your normals might be:


T = I - 2 * v * transpose(v)

I is the identity matrix and v the normalized surface normal of your triangle stored as a column vector. So you need to calculate the transformation matrix for each triangle. Use the cross product to get the normal. I can't check it myself since I am in a hurry, but let me know if it worked.

Greetings

Okey, I got it solved with following approach:

While importing the 3D file
1. Calculate the surface normal of a given face
2. Sum and Normalize the Vertex Normals of this face
3. Once the dot product of those two normals is < 0 (180deg) its flipped

In this case I can change the order or flip the vertex normals.

Thanks for your help
 

This topic is closed to new replies.

Advertisement