Skip to content

Conversation

@beicause
Copy link
Contributor

@beicause beicause commented Nov 22, 2025

Objective

Forward decal is not transparent unless I set the alpha mode of base material (StandardMaterial) to Blend. This is because the MaterialExtension::alpha_mode doesn't override standard material flags, which is still follow the StandardMaterial::alpha_mode and 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_ENABLED so 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:

屏幕截图_20251122_104851

Change alpah mode to Add:
屏幕截图_20251122_104822

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forward decal is just a quad mesh and has no specific mesh key, so we can't check it here.

@dloukadakis dloukadakis added the A-Rendering Drawing game state to the screen label Nov 22, 2025
@dloukadakis dloukadakis added S-Needs-Review Needs reviewer attention (from anyone!) to move forward D-Shaders This code uses GPU shader languages labels Nov 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen D-Shaders This code uses GPU shader languages S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants