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

showcasing the Material2d abtraction with a new example: 2d/mesh2d_material.rs #3610

Closed
wants to merge 10 commits into from

Conversation

eliotbo
Copy link

@eliotbo eliotbo commented Jan 9, 2022

Objective

  • There are currently no resources to learn how to use the Material2d trait, and this PR fixes this issue by adding a related example to the examples/2d folder.

Solution

The new 2d/mesh2d_material example is a modified version of the shader/shader_material example, where the Material trait is replaced by the Material2d trait. In the new example, users will be able to add fields to the Custom2dMaterial struct without having to change the Material2d and RenderAsset implementations, provided that bevy_crevice supports the type of said fields. This is achieved by 1) deriving AsStd140 on Custom2dMaterial, 2) setting the binding size with Custom2dMaterial::std140_size_static(), and 3) converting the entirety of the Custom2dMaterial data into std140 format with the derived as_std140() method. Of course, as users modify the Custom2dMaterial struct, they must also change the corresponding struct inside the shader script, but this exercise is left to them.

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Jan 9, 2022
examples/2d/mesh2d_material.rs Outdated Show resolved Hide resolved
examples/2d/mesh2d_material.rs Outdated Show resolved Hide resolved
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Examples An addition or correction to our examples and removed S-Needs-Triage This issue needs to be labelled labels Jan 9, 2022
Copy link
Contributor

@jakobhellermann jakobhellermann left a comment

Choose a reason for hiding this comment

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

Looks good to me!

examples/2d/mesh2d_material.rs Outdated Show resolved Hide resolved
@Nilirad
Copy link
Contributor

Nilirad commented May 3, 2022

This PR adds a new example. Adding module and item level doc comments, as described in:

would be really useful to those who will browse examples.

@IceSentry
Copy link
Contributor

@eliotbo would you be interested in updating this PR to the newer Material api using AsBindGroup. We do get people asking about 2d materials from time to time so having an example could be useful instead of just telling them to copy the 3d version.

@mockersf
Copy link
Member

done in #10542

@mockersf mockersf closed this Jan 10, 2024
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-Examples An addition or correction to our examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants