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_pbr::{
2 mesh_functions,
3 view_transformations::position_world_to_clip
4}
6@group(2) @binding(0) var texture: texture_2d<f32>;
7@group(2) @binding(1) var texture_sampler: sampler;
9struct Vertex {
10 @builtin(instance_index) instance_index: u32,
11 @location(0) position: vec3<f32>,
12};
14struct VertexOutput {
15 @builtin(position) clip_position: vec4<f32>,
16 @location(0) world_position: vec4<f32>,
17 @location(1) color: vec4<f32>,
18};
20@vertex
21fn vertex(vertex: Vertex) -> VertexOutput {
22 var out: VertexOutput;
24 // Lookup the tag for the given mesh
25 let tag = mesh_functions::get_tag(vertex.instance_index);
26 var world_from_local = mesh_functions::get_world_from_local(vertex.instance_index);
27 out.world_position = mesh_functions::mesh_position_local_to_world(world_from_local, vec4(vertex.position, 1.0));
28 out.clip_position = position_world_to_clip(out.world_position.xyz);
30 let tex_dim = textureDimensions(texture);
31 // Find the texel coordinate as derived from the tag
32 let texel_coord = vec2<u32>(tag % tex_dim.x, tag / tex_dim.x);
34 out.color = textureLoad(texture, texel_coord, 0);
35 return out;
38@fragment
39fn fragment(
40 mesh: VertexOutput,
41) -> @location(0) vec4<f32> {
42 return mesh.color;
Contents