#Cannot map rust struct to shader uniform struct

7 messages · Page 1 of 1 (latest)

radiant saffron
#

Hey folks, I'm flummoxed here. I've got the following rust material and it's corresponding shader. For some reason I get the following error, and I'm not sure how to debug it. From what I can tell the rust struct and the shader uniform definition match up.

I'm hazy on what the exact role of the different values for group and binding mean so if anyone could help enlighten me there that would help me a lot 🙂

    In Device::create_render_pipeline
      note: label = `transparent_mesh2d_pipeline`
    error matching FRAGMENT shader requirements against the pipeline
    shader global ResourceBinding { group: 1, binding: 0 } is not available in the layout pipeline layout
    buffer structure size 16, added to one element of an unbound array, if it's the last field, ended up greater than the given `min_binding_size```

Material Def:
```rs
#[derive(AsBindGroup, Clone, TypeUuid, Debug)]
#[uuid = "e0285780-cb09-46a0-9b59-8e449e737193"]
pub struct RadialMiningIndicatorMaterial {
    // #[uniform(0)]
    // pub inner_radius: f32,

    // #[uniform(1)]
    // pub thickness: f32,
    #[uniform(0)]
    pub threshold_1: f32,

    #[uniform(1)]
    pub threshold_2: f32,

    /// A value encapsulating the currentTemp/topOfMiningRange
    #[uniform(2)]
    pub value: f32,

    #[uniform(3)]
    pub color_low: Color,

    #[uniform(4)]
    pub color_mid: Color,

    #[uniform(5)]
    pub color_high: Color,
}

impl Material2d for RadialMiningIndicatorMaterial {
    fn fragment_shader() -> ShaderRef {
        "shaders/radial_mining.wgsl".into()
    }
}
#

Shader:

#import bevy_pbr::mesh_view_bindings

//https://github.com/bevyengine/bevy/blob/c2da7800e3671ad92e775529070a814d0bc2f5f8/crates/bevy_sprite/src/mesh2d/mesh2d.wgsl
struct VertexOutput {
    @builtin(position) clip_position: vec4<f32>,
    @location(0) world_position: vec4<f32>,
    @location(1) world_normal: vec3<f32>,
    @location(2) uv: vec2<f32>,
};

struct MiningWidget{
  threshold_1: f32,
  threshold_2: f32,
  value: f32,
  color_low: vec4<f32>,
  color_mid: vec4<f32>,
  color_high: vec4<f32>
}

@group(1) @binding(0)
var<uniform> widget: MiningWidget;


fn map (value:f32, min1:f32, max1:f32, min2:f32, max2:f32) -> f32{
  return min2 + (value - min1) * (max2 - min2) / (max1 - min1);
}

@fragment
fn fragment(
    @builtin(position) position: vec4<f32>,
    #import bevy_pbr::mesh_vertex_output
) -> @location(0) vec4<f32> {
  return widget.color_low;
}```
#

Cannot map rust struct to shader uniform struct

still dragon
#

All the struct fields on the rust side with uniform attributes should be #[uniform(0)] if you want those to be in a single struct binding in the shader

radiant saffron
#

That did it

#

Thanks!

#

I guess I could map different fields in the material to different structs within the shader that way, that's kind of cool