Skip to content

Ability to add/replace shader and material properties for bevy_sprite #1738

Open
@recatek

Description

@recatek

What problem does this solve or what need does it fill?

The render pipeline for bevy_sprite is currently a bit rigid. In order to take advantage of the sprite sheet and other nice features of the crate, you currently need to commit to a hardcoded vertex and fragment shader. This limits your ability to control how your sprites are drawn. One use case of custom shaders on sprites is to dynamically recolor masked portions of the sprite for team colors. To achieve this right now you need to dig pretty deep into the sprite code to see how it builds its pipeline and render graph nodes, and either replace them or clone the crate with your own changes.

What solution would you like?

Ideally, a more surface-level way to customize/override the shader and material that the sprite system uses, while preserving its functionality for sprite sheets and other nice-to-haves, like sizing.

What alternative(s) have you considered?

You can fork bevy_sprite and use your own implementation, or reimplement portions of it piecemeal (like build_sprite_pipeline). You can override the material and the render_pipelines on the sprite entity with a custom bundle, but that severs you from the nice sprite functionality like automatic resizing and doesn't seem to be better than spawning a quad and going out on your own. See example gist.

Additional context

Reconciling user-custom shaders and materials with the requirements of how the sprite sheet system works will be tricky. I'm not sure how to do this at first glance other than clearly documenting what the user-provided shader needs to support and how in order to play nicely with sprite sheets.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-FeatureA new feature, making something new possibleC-UsabilityA targeted quality-of-life change that makes Bevy easier to use

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions