From 64642fbd3cd196ee64280cbba2ba5e8f0bb01202 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Mon, 28 Nov 2022 13:15:03 +0000 Subject: [PATCH] Remove unnecessary struct in Material AsBindGroup example (#6701) # Objective - Reduce confusion around uniform bindings in materials. I've seen multiple people on discord get confused by it because it uses a struct that is named the same in the rust code and the wgsl code, but doesn't contain the same data. Also, the only reason this works is mostly by chance because the memory happens to align correctly. ## Solution - Remove the confusing parts of the doc ## Notes It's not super clear in the diff why this causes confusion, but essentially, the rust code defines a `CustomMaterial` struct with a color and a texture, but in the wgsl code the struct with the same name only contains the color. People are confused by it because the struct in wgsl doesn't need to be there. You _can_ have complex structs on each side and the macro will even combine it for you if you reuse a binding index, but as it is now, this example seems to confuse more than help people. --- crates/bevy_pbr/src/material.rs | 6 +----- crates/bevy_render/src/render_resource/bind_group.rs | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/crates/bevy_pbr/src/material.rs b/crates/bevy_pbr/src/material.rs index 2dc0e0f3ed..5c0a749cb2 100644 --- a/crates/bevy_pbr/src/material.rs +++ b/crates/bevy_pbr/src/material.rs @@ -100,12 +100,8 @@ use std::marker::PhantomData; /// In WGSL shaders, the material's binding would look like this: /// /// ```wgsl -/// struct CustomMaterial { -/// color: vec4, -/// } -/// /// @group(1) @binding(0) -/// var material: CustomMaterial; +/// var color: vec4; /// @group(1) @binding(1) /// var color_texture: texture_2d; /// @group(1) @binding(2) diff --git a/crates/bevy_render/src/render_resource/bind_group.rs b/crates/bevy_render/src/render_resource/bind_group.rs index a8d4a06e17..9511817d46 100644 --- a/crates/bevy_render/src/render_resource/bind_group.rs +++ b/crates/bevy_render/src/render_resource/bind_group.rs @@ -93,12 +93,8 @@ impl Deref for BindGroup { /// In WGSL shaders, the binding would look like this: /// /// ```wgsl -/// struct CoolMaterial { -/// color: vec4, -/// }; -/// /// @group(1) @binding(0) -/// var material: CoolMaterial; +/// var color: vec4; /// @group(1) @binding(1) /// var color_texture: texture_2d; /// @group(1) @binding(2)