bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.83k stars 3.54k forks source link

Custom material always requires vertex position, normal and UV #5147

Open afonsolage opened 2 years ago

afonsolage commented 2 years ago

Bevy version

0.7

What you did

Created a custom material without using Vertex_UV attribute

What went wrong

The custom material requires vertex POSITION, NORMAL and UV attributes to be set on Mesh even if the custom material layout doesn't specifies so. This seems to be a requirement of the mesh pipeline.

Additional information

This was first reported and discussed here

superdump

This passes the mesh layout into the mesh pipeline specialization function: https://github.com/bevyengine/bevy/blob/9eb69282efe57b9e3922e66ade887e6239bff175/crates/bevy_pbr/src/material.rs#L263 Which requires these attributes: https://github.com/bevyengine/bevy/blob/9eb69282efe57b9e3922e66ade887e6239bff175/crates/bevy_pbr/src/render/mesh.rs#L576 So even if you want to override the vertex attributes and layout, that code already required them and if your mesh doesn’t have them, it will fail

cart

Gotcha that makes sense. Fixing that will probably require some design work. Ex: do we build an api to let people override vertex layouts (specifically), or add a lifecycle hook that allows people to specialize the mesh pipeline. Do we add another generic to MeshPipeline that lets users plug their custom logic in or take a more retroactive approach?

kulkalkul commented 2 years ago

I also encountered this, alternative to this is writing a pipeline, which is a lot boilerplate. Here it is for reference: https://discord.com/channels/691052431525675048/970964103516532746/970998522679816222

nicopap commented 1 year ago

Seems to be fixed in 0.10. Am I mistaken? in mesh.wgsl I see all vertex attributes are conditionally added.

struct Vertex {
#ifdef VERTEX_POSITIONS
    @location(0) position: vec3<f32>,
#endif
#ifdef VERTEX_NORMALS
    @location(1) normal: vec3<f32>,
#endif
#ifdef VERTEX_UVS
    @location(2) uv: vec2<f32>,
#endif
#ifdef VERTEX_TANGENTS
    @location(3) tangent: vec4<f32>,
#endif
#ifdef VERTEX_COLORS
    @location(4) color: vec4<f32>,
#endif
#ifdef SKINNED
    @location(5) joint_indices: vec4<u32>,
    @location(6) joint_weights: vec4<f32>,
#endif
};