ForwardDecal: Allow custom alpha mode and fix using with OIT#21909
ForwardDecal: Allow custom alpha mode and fix using with OIT#21909beicause wants to merge 13 commits intobevyengine:mainfrom
Conversation
fa663eb to
a371938
Compare
| blend = None; | ||
| // TODO tail blending would need to return color in shader to do alpha blending | ||
| // Alpha blending is also needed by forward decals. | ||
| blend = Some(BlendState::ALPHA_BLENDING); |
There was a problem hiding this comment.
I'm a bit confused. This is only relevant when using forward decal with OIT right? But in pbr.wgsl you added a comment saying forward decal is incompatible with OIT.
Also, do we have a way to check here if this is for a forward decal or just a standard mesh?
There was a problem hiding this comment.
Forward decal is just a quad mesh and has no specific mesh key, so we can't check it here.
There was a problem hiding this comment.
OK, I added enable_oit to material as a way to opt out OIT. Let me known if you prefer that.
There was a problem hiding this comment.
I still don't understand why the blend mode of the OIT_ENABLED pipeline needs to change.
|
Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke! If it's expected, please add the M-Deliberate-Rendering-Change label. If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it. |
f85f5ee to
dc89206
Compare
| const MOTION_VECTOR_PREPASS = 1 << 3; | ||
| const DEFERRED_PREPASS = 1 << 4; | ||
| const OIT_ENABLED = 1 << 5; | ||
| const OIT_VIEW = 1 << 5; |
There was a problem hiding this comment.
I don't really understand what OIT_VIEW means here and why it isn't just OIT_ENABLED?
There was a problem hiding this comment.
It is used for mesh view binding when OIT is enabled on the camera, otherwise the shader bind groups will not match.
These bindings seem to be distinguished by camera, but not by material.
There was a problem hiding this comment.
I'd like to revert this change as I'm not convinced it's necessary or stable enough. IMO the rendering pipeline should just respect alpha_mode=blend for now, if OIT needs a separate alpha mode we can make changes in the future,.
c07dfe7 to
d11acc0
Compare
| fn alpha_mode() -> Option<AlphaMode> { | ||
| Some(AlphaMode::Blend) | ||
| fn enable_prepass() -> bool { | ||
| false // This is needed if alpha mode is `Opaque`. |
There was a problem hiding this comment.
I understand not forcing the use of alpha blending, but I don't get why setting enable_prepass to false is necessary.
There was a problem hiding this comment.
Forward decal requires the prepass depth of other opaque objects, while its own depth should not be included in the prepass.
Objective
Forward decal is not transparent unless I set the alpha mode of base material (StandardMaterial) to Blend. This is because the
MaterialExtension::alpha_modedoesn't override standard material flags, which is still follow theStandardMaterial::alpha_modeand is opaque and discards alpha by default.And ForwardDecalMaterialExt overrides alpha mode so it can only do alpha blending, which is an unnecessary restriction in my opinion. I think it makes sense to allow use alpha modes other than Blend for forward decals.
There is also an issue that if OIT enabled, forward decal will be wrongly culled by opaque objects.
Solution
Makes forward decal doesn't override alpha mode, and doesn't enter the code path of
OIT_ENABLEDso it can do alpha blending.Add.material::enable_oitto opt out OIT so forward decals can use regular alpha blendingDisables prepass for forward decal so it still works if alpha mode is Opaque or Mask (thought the depth fade factor won't have effect).
Disables shadow for forward decal as it generally shouldn't cast shadows.
Testing
Run the decal example:
With alpha mode Add:

With alpha mode Opaque:
