Skip to content
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

Unlit materials don't seem to respect AlphaMode::Mask #4479

Closed
JohnEmhoff opened this issue Apr 15, 2022 · 1 comment
Closed

Unlit materials don't seem to respect AlphaMode::Mask #4479

JohnEmhoff opened this issue Apr 15, 2022 · 1 comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior

Comments

@JohnEmhoff
Copy link

Bevy version

0.6.1

Operating system & version

Ubuntu 21.10

What you did

Using a StandardMaterial with unlit: true seems to ignore AlphaMode::Mask.

I'm rendering a reticle as a cube with a mostly transparent texture. Using this material:

let ret_mat = materials.add(StandardMaterial {
        base_color_texture: Some(reticle_texture),
        unlit: false,
        alpha_mode: AlphaMode::Mask(0.9),
        ..Default::default()
    });

...renders like this:

Screenshot from 2022-04-14 23-05-57

But using this material:

let ret_mat = materials.add(StandardMaterial {
        base_color_texture: Some(reticle_texture),
        unlit: true,  // this is the only change
        alpha_mode: AlphaMode::Mask(0.9),
        ..Default::default()
    });

...renders like this:

Screenshot from 2022-04-14 23-05-40

What you expected to happen

The black area in the latter image should be transparent. For whatever reason AlphaMode::Blend does work with both lit and unlit, but it has the side effect of messing with depth ordering. (This is reasonable, right? It doesn't seem crazy that when blending nothing writes to the depth buffer)

What actually happened

unlit: true causes AlphaMode::Mask to be ignored

Additional information

It's entirely possible this is behaving as expected for some interesting reason that I'm just not aware of. If so I apologize and appreciate the opportunity to learn something :)

@JohnEmhoff JohnEmhoff added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Apr 15, 2022
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Apr 16, 2022
@LoopyAshy
Copy link
Contributor

This issue has been causing me quite a bit of grief recently, I imagine the issue however is within the standard shader.

I may have a look later but my shader knowledge is very hit and miss.

bors bot pushed a commit that referenced this issue Sep 28, 2022
# Objective

- Alpha mask was previously ignored when using an unlit material. 
- Fixes #4479

## Solution

- Extract the alpha discard to a separate function and use it when unlit is true

## Notes
I tried calling `alpha_discard()` before the `if` in pbr.wgsl, but I had errors related to having a `discard` at the beginning before doing the texture sampling. I'm not sure if there's a way to fix that instead of having the function being called in 2 places.
@bors bors bot closed this as completed in 197392a Sep 28, 2022
james7132 pushed a commit to james7132/bevy that referenced this issue Oct 19, 2022
# Objective

- Alpha mask was previously ignored when using an unlit material. 
- Fixes bevyengine#4479

## Solution

- Extract the alpha discard to a separate function and use it when unlit is true

## Notes
I tried calling `alpha_discard()` before the `if` in pbr.wgsl, but I had errors related to having a `discard` at the beginning before doing the texture sampling. I'm not sure if there's a way to fix that instead of having the function being called in 2 places.
james7132 pushed a commit to james7132/bevy that referenced this issue Oct 28, 2022
# Objective

- Alpha mask was previously ignored when using an unlit material. 
- Fixes bevyengine#4479

## Solution

- Extract the alpha discard to a separate function and use it when unlit is true

## Notes
I tried calling `alpha_discard()` before the `if` in pbr.wgsl, but I had errors related to having a `discard` at the beginning before doing the texture sampling. I'm not sure if there's a way to fix that instead of having the function being called in 2 places.
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective

- Alpha mask was previously ignored when using an unlit material. 
- Fixes bevyengine#4479

## Solution

- Extract the alpha discard to a separate function and use it when unlit is true

## Notes
I tried calling `alpha_discard()` before the `if` in pbr.wgsl, but I had errors related to having a `discard` at the beginning before doing the texture sampling. I'm not sure if there's a way to fix that instead of having the function being called in 2 places.
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 C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants