3 meshlet_cluster_meshlet_ids, 5 meshlet_cluster_instance_ids, 6 meshlet_instance_uniforms, 7 meshlet_raster_clusters, 8 meshlet_visibility_buffer, 10 get_meshlet_triangle_count, 11 get_meshlet_vertex_id, 12 get_meshlet_vertex_position, 14 mesh_functions::mesh_position_local_to_world, 16#import bevy_render::maths::affine3_to_square 17var<push_constant> meshlet_raster_cluster_rightmost_slot: u32; 22 @builtin(position) position: vec4<f32>, 23#ifdef MESHLET_VISIBILITY_BUFFER_RASTER_PASS_OUTPUT 24 @location(0) @interpolate(flat) packed_ids: u32, 29fn vertex(@builtin(instance_index) instance_index: u32, @builtin(vertex_index) vertex_index: u32) -> VertexOutput { 30 let cluster_id = meshlet_raster_clusters[meshlet_raster_cluster_rightmost_slot - instance_index]; 31 let meshlet_id = meshlet_cluster_meshlet_ids[cluster_id]; 32 var meshlet = meshlets[meshlet_id]; 34 let triangle_id = vertex_index / 3u; 35 if triangle_id >= get_meshlet_triangle_count(&meshlet) { return dummy_vertex(); } 36 let index_id = (triangle_id * 3u) + (vertex_index % 3u); 37 let vertex_id = get_meshlet_vertex_id(meshlet.start_index_id + index_id); 39 let instance_id = meshlet_cluster_instance_ids[cluster_id]; 40 let instance_uniform = meshlet_instance_uniforms[instance_id]; 42 let vertex_position = get_meshlet_vertex_position(&meshlet, vertex_id); 43 let world_from_local = affine3_to_square(instance_uniform.world_from_local); 44 let world_position = mesh_position_local_to_world(world_from_local, vec4(vertex_position, 1.0)); 45 let clip_position = view.clip_from_world * vec4(world_position.xyz, 1.0); 49#ifdef MESHLET_VISIBILITY_BUFFER_RASTER_PASS_OUTPUT 50 (cluster_id << 7u) | triangle_id, 56fn fragment(vertex_output: VertexOutput) { 57 let depth = bitcast<u32>(vertex_output.position.z); 58#ifdef MESHLET_VISIBILITY_BUFFER_RASTER_PASS_OUTPUT 59 let visibility = (u64(depth) << 32u) | u64(vertex_output.packed_ids); 61 let visibility = depth; 63 textureAtomicMax(meshlet_visibility_buffer, vec2<u32>(vertex_output.position.xy), visibility); 66fn dummy_vertex() -> VertexOutput { 68 vec4(divide(0.0, 0.0)), 69#ifdef MESHLET_VISIBILITY_BUFFER_RASTER_PASS_OUTPUT 76fn divide(a: f32, b: f32) -> f32 {