Move the construction of LightingInput
in apply_pbr_lighting
into its own function.
#18489
+97
−133
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
Reduce duplication in the
bevy_pbr
shaders by using a function to createLightingInput
fromPbrInput
which can then be shared betweenapply_pbr_lighting
andssr::fragment
.Solution
I created a function
pbr_input_to_lighting_input
inpbr_lighting
to do this (lighting seemed the most logical place for it as that is whereLightingInput
lives and in a higher level language this would be a constructor). This also required movingcalculate_F0
andcalculate_diffuse_color
intopbr_lighting
to prevent a circular dependency (infinite load during shader compilation), this makes sense forcalculate_F0
as this is now the only thing that uses it butcalculate_diffuse_color
does still have another user file.Questions for reviewers
pbr_input_to_lighting_input
instead accept aptr
toPbrInput
, I don't feel like I have a sufficient grasp of shader optimisers to know whether this is better (or if we can trust this should always be inlined)?pbr_functions
which has the advantage of making this a non-breaking change (because no functions would have to move) but separates a constructor from its struct definition?Testing
I ran
ssr
andanisotropy
and checked them for visual issues/crashes and ran as much CI as I could before running out of disk space. I tried to testclearcoat
but that example is broken for me (#18104)Migration Guide
Shader function changes:
calculate_diffuse_color
andcalculate_F0
have been moved frombevy_pbr::pbr_functions
tobevy_pbr::lighting
.