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

feat: vertex attribute validation for Material #6334

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dataphract
Copy link
Member

Objective

Fixes #6128. (Original suggestion from #6127 (review)).

Solution

This PR adds a new trait method, Material::required_vertex_attributes, which allows implementors to specify a list of vertex attributes that are required for the Material to function.

A new system has been added to MaterialPlugin which emits an error message when an entity is found to have a Mesh that lacks required vertex attributes for its Material.


Changelog

Added

  • Added Material::required_vertex_attributes trait method, allowing implementors to specify the vertex attributes required for a Material.
  • Added verify_material_mesh_attributes() system to MaterialPlugin. Errors are now emitted if a Material is applied to a Mesh missing required attributes.
  • Added name() and id() methods on MeshVertexAttribute to retrieve the name and unique ID.

@dataphract dataphract added A-Rendering Drawing game state to the screen C-Usability A simple quality-of-life change that makes Bevy easier to use A-Diagnostics Logging, crash handling, error reporting and performance analysis labels Oct 22, 2022
@DGriffin91
Copy link
Contributor

@dataphract Cool idea! Do you think one of the examples (maybe shader_material.rs) should implement required_vertex_attributes() to show the feature?

@dataphract
Copy link
Member Author

Cool idea! Do you think one of the examples (maybe shader_material.rs) should implement required_vertex_attributes() to show the feature?

Definitely a good idea, just want to get consensus on how the interface should look before updating examples. Those could be in one or more follow-up PRs.

Copy link
Contributor

@superdump superdump left a comment

Choose a reason for hiding this comment

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

I love the overall idea. Left a couple of high-level comments and marking request changes for now.

crates/bevy_pbr/src/material.rs Outdated Show resolved Hide resolved
crates/bevy_pbr/src/material.rs Outdated Show resolved Hide resolved
This adds a new trait method, `Material::required_vertex_attributes`,
which allows implementors to specify a list of vertex attributes that
are required for the `Material` to function.

A new system has been added to `MaterialPlugin` which emits an error
message when an entity is found to have a `Mesh` that lacks required
vertex attributes for its `Material`.
@dataphract
Copy link
Member Author

This ended up being a surprisingly difficult system to write due to the distinction @superdump pointed out -- it needs to detect changes to the mesh assets themselves and not just the handles. This requires a lot of bookkeeping (did this entity's mesh change? did it change its mesh? has this mesh already been validated?) but ultimately it still runs linearly in the number of entities and doesn't require new allocations on every invocation.

The new error message looks like this:

ERROR bevy_pbr::material: Entity 1v0: mesh with ID `Id(8ecbac0f-f545-4473-ad43-e1f4243af51e, 8621032393721330913)` is missing vertex attribute `Vertex_Normal`, which is required by `bevy_pbr::pbr_material::StandardMaterial`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Diagnostics Logging, crash handling, error reporting and performance analysis A-Rendering Drawing game state to the screen C-Usability A simple quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add vertex attribute validation to Material trait
4 participants