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

Fixed sprite transparency artifacts #2428

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/bevy_sprite/src/render/sprite.frag
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ void main() {
sampler2D(ColorMaterial_texture, ColorMaterial_texture_sampler),
v_Uv);
# endif
if(color.a < 0.5) discard;
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe I read somewhere that discard hurts performance.

Copy link
Author

Choose a reason for hiding this comment

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

This is hardware dependent (source). In any case, the performance hit shouldn't be noticeable.

Copy link
Member

Choose a reason for hiding this comment

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

Why a cutout value of 0.5? Isn't that high?

Copy link
Author

Choose a reason for hiding this comment

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

That's the "standard" default value from my experience. I'm looking into making it customisable, but we'll see if time permits.


o_Target = color;
}
6 changes: 5 additions & 1 deletion crates/bevy_sprite/src/render/sprite_sheet.frag
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ layout(set = 1, binding = 2) uniform texture2D TextureAtlas_texture;
layout(set = 1, binding = 3) uniform sampler TextureAtlas_texture_sampler;

void main() {
o_Target = v_Color * texture(
vec4 color = v_Color * texture(
sampler2D(TextureAtlas_texture, TextureAtlas_texture_sampler),
v_Uv);

if(color.a < 0.5) discard;

o_Target = color;
}