Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the normal matrix when det < 0. #3105

Closed
wants to merge 1 commit into from
Closed

Fix the normal matrix when det < 0. #3105

wants to merge 1 commit into from

Conversation

prideout
Copy link
Contributor

This was tested by replacing the node 0 scale in BusterDrone with [-1, 1, 1].

Fixes #3001.

@prideout
Copy link
Contributor Author

For future reference, the following commit is when we switched from transpose(inverse()) to cof()

f728776

@@ -199,6 +199,12 @@ void FScene::updateUBOs(utils::Range<uint32_t> visibleRenderables, backend::Hand
mat3f m = mat3f::getTransformForNormals(model.upperLeft());
m *= mat3f(1.0f / std::sqrt(max(float3{length2(m[0]), length2(m[1]), length2(m[2])})));

// Since our "getTransformForNormals" matrix omits the divide-by-determinant step,
// it has the wrong sign when the determinant is negative.
if (sceneData.elementAt<REVERSED_WINDING_ORDER>(i)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do this in getTransformForNormals?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but if we move it then we will be computing the determinant twice, which is somewhat redundant. I'm on the fence. @pixelflinger : you made the original switch to cof(), what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note that getTransformForNormals is used in a couple other places, e.g. when determining dominant light direction. So yeah maybe we should make it slower and just add a divide-by-det in there.

Copy link
Contributor Author

@prideout prideout Sep 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dale Weiler's GitHub post makes the argument that we should just use the raw cofactor matrix, but I didn't understand one of the steps in his algebra. Moreover Lengyel never makes such a claim. In practice, dividing the cof by the det (which is exactly equivalent to the inverse-transpose) seems to fix this particular issue.

@prideout prideout force-pushed the pr/fixmirror branch 2 times, most recently from 37d4afe to 8eb0e05 Compare September 22, 2020 01:43
This was tested by replacing the node 0 scale in BusterDrone with
[-1, 1, 1].

For future reference, commit f728776 shows when we switched from
transpose(inverse()) to cof().

Fixes #3001.
@prideout
Copy link
Contributor Author

Actually, let me close and research this a little more. Using the cofactor matrix should be correct.

@prideout prideout closed this Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to mirror Camera around X-axis?
2 participants