Skip to content

Rendering artifacts with overlapping transparent sprites #1422

Open
@someguynamedjosh

Description

Bevy version

0.4.0 from crates.io, also reproduced with 3475a64

Operating system & version

KUbuntu 20.04

What you did

  • Create two sprites such that a fully transparent portion of the first sprite clips into the second sprite.
  • Create a camera viewing them at an angle (ideally with keyboard controls)

What you expected to happen

Both sprites are correctly drawn

What actually happened

The transparent area of the first sprite will sometimes occlude the second sprite:
Screenshot_20210208_152921
(The red area is supposed to be a square but is occluded by the transparent area of the triangle's sprite.)

Additional information

I've temporarily solved this by replacing the default SPRITE_RENDER_PIPELINE with one where the fragment shader has this additional line:

    if (color.a < 0.5) discard;

which functions like the 'cutout' shaders found in other game engines. It resolves the problem by not writing to the depth buffer when a pixel is transparent enough. However, it causes decreased performance for sprites which do not need this effect. I wanted to mention this to anyone who might know how to better incorporate this change into the engine. I would assume a good approach would be to create another rendering pipeline for sprites that need this cutout effect that runs after the main sprite pipeline. Then there could be added either a CutoutSpriteBundle::default() or SpriteBundle::cutout() to easily create a bundle using this pipeline.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions