ForwardDecal: Allow custom alpha mode and fix using with OIT #21909
+61
−12
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
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
Make forward decal doesn't override alpha mode, and doesn't enter the code path of
OIT_ENABLEDso it can do alpha blending.Disabled prepass for forward decal so it still works if alpha mode is Opaque or Mask (thought the depth fade factor won't have effect).
Disabled shadow for forward decal as it generally shouldn't cast shadows.
Testing
Run the decal example:
Change alpah mode to Add:
