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.
1#import bevy_sprite::{
2 mesh2d_functions as mesh_functions,
3 mesh2d_view_bindings::view,
4 mesh2d_vertex_output::VertexOutput,
5}
7@group(#{MATERIAL_BIND_GROUP}) @binding(0) var tileset: texture_2d_array<f32>;
8@group(#{MATERIAL_BIND_GROUP}) @binding(1) var tileset_sampler: sampler;
9@group(#{MATERIAL_BIND_GROUP}) @binding(2) var tile_data: texture_2d<u32>;
11struct TileData {
12 tileset_index: u32,
13 color: vec4<f32>,
14 visible: bool,
17fn get_tile_data(coord: vec2<u32>) -> TileData {
18 let data = textureLoad(tile_data, coord, 0);
20 let tileset_index = data.r;
22 let color_r = f32(data.g & 0xFFu) / 255.0;
23 let color_g = f32((data.g >> 8u) & 0xFFu) / 255.0;
24 let color_b = f32(data.b & 0xFFu) / 255.0;
25 let color_a = f32((data.b >> 8u) & 0xFFu) / 255.0;
27 let color = vec4<f32>(color_r, color_g, color_b, color_a);
29 let visible = data.a != 0u;
31 return TileData(tileset_index, color, visible);
34@fragment
35fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
36 let chunk_size = textureDimensions(tile_data, 0);
37 let tile_uv = in.uv * vec2<f32>(chunk_size);
38 let tile_coord = clamp(vec2<u32>(floor(tile_uv)), vec2<u32>(0), chunk_size - 1);
40 let tile = get_tile_data(tile_coord);
42 if (tile.tileset_index == 0xffffu || !tile.visible) {
43 discard;
44 }
46 let local_uv = fract(tile_uv);
47 let tex_color = textureSample(tileset, tileset_sampler, local_uv, tile.tileset_index);
48 let final_color = tex_color * tile.color;
50 if (final_color.a < 0.001) {
51 discard;
52 }
54 return final_color;
Contents