Search across packages, versions, files, declarations, and comments. Use multiple terms to narrow results (AND), and add @vertex, @fragment, or @compute to filter by shader stage.
1import bevy_sprite_render::mesh2d::vertex_output::VertexOutput;
2import bevy_sprite_render::mesh2d::bindings::mesh;
3import bevy_render::bindless::{bindless_samplers_filtering, bindless_textures_2d};
4// we can import items from shader modules in the assets folder with a relative path
5import super::custom_material_import::COLOR_MULTIPLIER;
7struct Color {
8 base_color: vec4<f32>,
9}
11/// This structure is a mapping from bindless index to the index in the
12/// appropriate slab
13struct MaterialBindings {
14 material: u32, // 0
15 color_texture: u32, // 1
16 color_texture_sampler: u32, // 2
19@if(BINDLESS) {
20@group(constants::MATERIAL_BIND_GROUP) @binding(0) var<storage> materials: array<MaterialBindings>;
21@group(constants::MATERIAL_BIND_GROUP) @binding(10) var<storage> material_color: binding_array<Color>;
23@else {
24@group(constants::MATERIAL_BIND_GROUP) @binding(0) var<uniform> material_color: Color;
25@group(constants::MATERIAL_BIND_GROUP) @binding(1) var material_color_texture: texture_2d<f32>;
26@group(constants::MATERIAL_BIND_GROUP) @binding(2) var material_color_sampler: sampler;
29@fragment
30fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
31 @if(BINDLESS) {
32 let slot = mesh[in.instance_index].material_bind_group_slot;
33 let base_color = material_color[materials[slot].material].base_color;
34 let texture = bindless_textures_2d[materials[slot].color_texture];
35 let color_sampler = bindless_samplers_filtering[materials[slot].color_texture_sampler];
36 }
37 @else {
38 let base_color = material_color.base_color;
39 let texture = material_color_texture;
40 let color_sampler = material_color_sampler;
41 }
42 return base_color * textureSampleLevel(
43 texture,
44 color_sampler,
45 in.uv,
46 0.0
47 );
Contents