-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
pbr shader cleanup #10105
pbr shader cleanup #10105
Conversation
} | ||
|
||
// apply alpha discard | ||
// ------------------- | ||
// note even though this is based on the unlit color, it must be done after all texture samples for uniform control flow |
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 don't think this is really just for unlit as it also allows lit alpha mask materials to discard. I'm not sure why it wasn't previously used in both conditions, but I think that was probably a mistake. Ahh, I see now that it discards at the top of fn pbr()
for lit materials.
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.
it discards at the top of fn pbr() for lit materials
it used to, yes
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.
The discard should really be done as soon as possible otherwise there is unnecessary fragment shader work being done. We should instead calculate the uv gradient in uniform control flow and pass it into later sampling functions.
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.
Yes. it is the same place that it was though (plus or minus a couple of assignments). I just want to get this done so I can update the other 0.12 prs though
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 still need to review the changes to pbr.wgsl in more detail in a second pass. It does look much cleaner if it is all correct and consolidating vertex output and fragment input is a good thing for sure.
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.
LGTM
I tested a bunch of examples and they all seemed to work as expected and I like the changes overall
# Objective #10105 changed the ssao input color from the material base color to white. i can't actually see a difference in the example but there should be one in some cases. ## Solution change it back.
# Objective - The refactoring in #10105 missed including the frag_coord and normal in pbr_input. ## Solution - Add them back
# Objective cleanup some pbr shader code. improve shader stage io consistency and make pbr.wgsl (probably many people's first foray into bevy shader code) a little more human-readable. also fix a couple of small issues with deferred rendering. ## Solution mesh_vertex_output: - rename to forward_io (to align with prepass_io) - rename `MeshVertexOutput` to `VertexOutput` (to align with prepass_io) - move `Vertex` from mesh.wgsl into here (to align with prepass_io) prepass_io: - remove `FragmentInput`, use `VertexOutput` directly (to align with forward_io) - rename `VertexOutput::clip_position` to `position` (to align with forward_io) pbr.wgsl: - restructure so we don't need `#ifdefs` on the actual entrypoint, use VertexOutput and FragmentOutput in all cases and use #ifdefs to import the right struct definitions. - rearrange to make the flow clearer - move alpha_discard up from `pbr_functions::pbr` to avoid needing to call it on some branches and not others - add a bunch of comments deferred_lighting: - move ssao into the `!unlit` block to reflect forward behaviour correctly - fix compile error with deferred + premultiply_alpha ## Migration Guide in custom material shaders: - `pbr_functions::pbr` no longer calls to `pbr_functions::alpha_discard`. if you were using the `pbr` function in a custom shader with alpha mask mode you now also need to call alpha_discard manually - rename imports of `bevy_pbr::mesh_vertex_output` to `bevy_pbr::forward_io` - rename instances of `MeshVertexOutput` to `VertexOutput` in custom material prepass shaders: - rename instances of `VertexOutput::clip_position` to `VertexOutput::position`
# Objective bevyengine#10105 changed the ssao input color from the material base color to white. i can't actually see a difference in the example but there should be one in some cases. ## Solution change it back.
# Objective - The refactoring in bevyengine#10105 missed including the frag_coord and normal in pbr_input. ## Solution - Add them back
# Objective cleanup some pbr shader code. improve shader stage io consistency and make pbr.wgsl (probably many people's first foray into bevy shader code) a little more human-readable. also fix a couple of small issues with deferred rendering. ## Solution mesh_vertex_output: - rename to forward_io (to align with prepass_io) - rename `MeshVertexOutput` to `VertexOutput` (to align with prepass_io) - move `Vertex` from mesh.wgsl into here (to align with prepass_io) prepass_io: - remove `FragmentInput`, use `VertexOutput` directly (to align with forward_io) - rename `VertexOutput::clip_position` to `position` (to align with forward_io) pbr.wgsl: - restructure so we don't need `#ifdefs` on the actual entrypoint, use VertexOutput and FragmentOutput in all cases and use #ifdefs to import the right struct definitions. - rearrange to make the flow clearer - move alpha_discard up from `pbr_functions::pbr` to avoid needing to call it on some branches and not others - add a bunch of comments deferred_lighting: - move ssao into the `!unlit` block to reflect forward behaviour correctly - fix compile error with deferred + premultiply_alpha ## Migration Guide in custom material shaders: - `pbr_functions::pbr` no longer calls to `pbr_functions::alpha_discard`. if you were using the `pbr` function in a custom shader with alpha mask mode you now also need to call alpha_discard manually - rename imports of `bevy_pbr::mesh_vertex_output` to `bevy_pbr::forward_io` - rename instances of `MeshVertexOutput` to `VertexOutput` in custom material prepass shaders: - rename instances of `VertexOutput::clip_position` to `VertexOutput::position`
# Objective bevyengine#10105 changed the ssao input color from the material base color to white. i can't actually see a difference in the example but there should be one in some cases. ## Solution change it back.
# Objective - The refactoring in bevyengine#10105 missed including the frag_coord and normal in pbr_input. ## Solution - Add them back
Objective
cleanup some pbr shader code. improve shader stage io consistency and make pbr.wgsl (probably many people's first foray into bevy shader code) a little more human-readable. also fix a couple of small issues with deferred rendering.
Solution
mesh_vertex_output:
MeshVertexOutput
toVertexOutput
(to align with prepass_io)Vertex
from mesh.wgsl into here (to align with prepass_io)prepass_io:
FragmentInput
, useVertexOutput
directly (to align with forward_io)VertexOutput::clip_position
toposition
(to align with forward_io)pbr.wgsl:
#ifdefs
on the actual entrypoint, use VertexOutput and FragmentOutput in all cases and use #ifdefs to import the right struct definitions.pbr_functions::pbr
to avoid needing to call it on some branches and not othersdeferred_lighting:
!unlit
block to reflect forward behaviour correctlyMigration Guide
in custom material shaders:
pbr_functions::pbr
no longer calls topbr_functions::alpha_discard
. if you were using thepbr
function in a custom shader with alpha mask mode you now also need to call alpha_discard manuallybevy_pbr::mesh_vertex_output
tobevy_pbr::forward_io
MeshVertexOutput
toVertexOutput
in custom material prepass shaders:
VertexOutput::clip_position
toVertexOutput::position