bevyengine / bevyengine/bevy

Dynamic vertex attribute shader definition

Open
#8,397 4 comments 0 reactions 0 assignees View on GitHub
A-Rendering C-Feature S-Needs-Design
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

Bevy's shader `Vertex` struct — the input type for vertex shaders ­— is messy, extending the mesh pipeline with new attributes is error prone. You have to keep track of the `@location(x) attribute_name: attribute_type` of each of bevy's attributes and your own custom attributes.

## What solution would you like?

Bevy currently defines its `Vertex` through a series of `#ifdef`, neither ideal or the most readable.

What about dynamically defining this struct based on the attributes existing in the `Mesh` struct?

`MeshVertexAttribute` already contains everything we need to know about an attribute: its name and its type. We should be able to generate the `Vertex` struct based on them.

Advantages are:

* No need to keep track of `location(x)`, fully handled by bevy
* Avoid noisy definitions like the current `#ifdef` bag we use
* Avoid duplication, no need to specify `Vertex` means no need to duplicate the specification of `Vertex`.

## Additional context

This idea came as I was thinking about how it could be possible to extend the [morph targets] feature to support arbitrary vertex attributes, including user-supplied ones.

[morph targets]: https://github.com/bevyengine/bevy/pull/8158

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.