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

Add notes on calculating normals for non-uniformly scaled meshes #9922

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KiSetsuFu-PuLiN
Copy link

This PR adds notes on manually calculating normals in the spatial shader for non-uniformly scaled meshes

@skyace65 skyace65 added enhancement area:manual Issues and PRs related to the Manual/Tutorials section of the documentation topic:shaders labels Sep 7, 2024
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

This functionally does the same thing as render_mode ensure_correct_normals. I think it would be better to recommend ensure_correct_normals

@KiSetsuFu-PuLiN
Copy link
Author

This functionally does the same thing as render_mode ensure_correct_normals. I think it would be better to recommend ensure_correct_normals

I tried it, but I didn't get the rendering results expected.
Actually I don't quite understand how to use the render mode ensure_correct_normals. Maybe I'm using it incorrectly?

image

@AThousandShips AThousandShips changed the title Adds notes on calculating normals for non-uniformly scaled meshes Add notes on calculating normals for non-uniformly scaled meshes Sep 9, 2024
@clayjohn
Copy link
Member

clayjohn commented Sep 9, 2024

This functionally does the same thing as render_mode ensure_correct_normals. I think it would be better to recommend ensure_correct_normals

I tried it, but I didn't get the rendering results expected. Actually I don't quite understand how to use the render mode ensure_correct_normals. Maybe I'm using it incorrectly?

image

Yes, you are using it incorrectly. You need to use MODELVIEW_NORMAL_MATRIX for normals.

That being said, as I looked into the details I noticed that I was wrong in my response above. ensure_correct_normals doesn't do anything anymore. We detect when a mesh is scaled non-uniformly and automatically fix the normal matrix like so:

if (bool(model_flags & uint(FLAGS_NON_UNIFORM_SCALE))) {
	model_normal_matrix = transpose(inverse(mat3(model_matrix)));
} else {
	model_normal_matrix = mat3(model_matrix);
}

So the docs should just use MODELVIEW_NORMAL_MATRIX!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:manual Issues and PRs related to the Manual/Tutorials section of the documentation enhancement topic:shaders
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants