Files
bevy/assets/shaders/bindless_material.wgsl
charlotte 🌸 e6ec2c181d Material bind group shader def (#20069)
Use a shader def for the material bind group index to make it easier for
when we want to switch back to group 2 in the future without breaking
everyone again.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: atlas dostal <rodol@rivalrebels.com>
2025-08-06 05:09:12 +00:00

47 lines
1.6 KiB
WebGPU Shading Language

#import bevy_pbr::forward_io::VertexOutput
#import bevy_pbr::mesh_bindings::mesh
#import bevy_render::bindless::{bindless_samplers_filtering, bindless_textures_2d}
struct Color {
base_color: vec4<f32>,
}
// This structure is a mapping from bindless index to the index in the
// appropriate slab
struct MaterialBindings {
material: u32, // 0
color_texture: u32, // 1
color_texture_sampler: u32, // 2
}
#ifdef BINDLESS
@group(#{MATERIAL_BIND_GROUP}) @binding(0) var<storage> materials: array<MaterialBindings>;
@group(#{MATERIAL_BIND_GROUP}) @binding(10) var<storage> material_color: binding_array<Color>;
#else // BINDLESS
@group(#{MATERIAL_BIND_GROUP}) @binding(0) var<uniform> material_color: Color;
@group(#{MATERIAL_BIND_GROUP}) @binding(1) var material_color_texture: texture_2d<f32>;
@group(#{MATERIAL_BIND_GROUP}) @binding(2) var material_color_sampler: sampler;
#endif // BINDLESS
@fragment
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
#ifdef BINDLESS
let slot = mesh[in.instance_index].material_and_lightmap_bind_group_slot & 0xffffu;
let base_color = material_color[materials[slot].material].base_color;
#else // BINDLESS
let base_color = material_color.base_color;
#endif // BINDLESS
return base_color * textureSampleLevel(
#ifdef BINDLESS
bindless_textures_2d[materials[slot].color_texture],
bindless_samplers_filtering[materials[slot].color_texture_sampler],
#else // BINDLESS
material_color_texture,
material_color_sampler,
#endif // BINDLESS
in.uv,
0.0
);
}