-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Switch normal mapping to shader flag instead of shaderdef #8106
base: main
Are you sure you want to change the base?
Conversation
The original wasn't actually branchless, and the funky math just confused the compiler into emitting *more* code.
This allows custom shaders to modify the source of the normal map while reusing the normal mapping calculations
This better align with the other types of textures and makes it easier to reuse the normal mapping function in other shaders.
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is an improvement. The current apply_normal_mapping
function is odd and requires a lot of #ifdef
conditionals at the function call site. Why? Well, mostly to avoid the user a normalize(pbr_input.world_normal)
. This reduces complexity a fair bit.
Oops sorry for that nicopap. I should resolve the conflicts first. |
I feel like this one is behind enough at this point that the conflicts are bigger than the actual work. I'd probably put this one up for adoption or turn it into an issue again to help the rendering backlog. |
Objective
Solution
#ifdef
calls are replaced by if statements (does not measurably impact performance, uniform branches are ~free on reasonably modern hardware)apply_normal_mapping
into the shader main to match the other texturescc @superdump
Changelog
Changed
Migration Guide
If you have custom shaders that use
apply_normal_mapping
,prepare_world_normal
, or#define STANDARDMATERIAL_NORMAL_MAP
, they must be adjusted as follows:Pass the material flags directly instead of only checking for double sidedness
replace
#ifdef STANDARDMATERIAL_NORMAL_MAP
with flag checksWhen normal mapping is used, sample the texture yourself.
If you are not using a normal map, simply replace the call to
apply_normal_mapping
withnormalize