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 package::mesh2d::{
2 view_bindings::view,
3 bindings::{mesh, metadata},
4};
5import bevy_render::mesh::metadata_types::MeshMetadata;
6import bevy_render::maths::{affine3_to_square, mat2x4_f32_to_mat3x3_unpack};
8fn get_world_from_local(instance_index: u32) -> mat4x4<f32> {
9 return affine3_to_square(mesh[instance_index].world_from_local);
12fn mesh2d_position_local_to_world(world_from_local: mat4x4<f32>, vertex_position: vec4<f32>) -> vec4<f32> {
13 return world_from_local * vertex_position;
16fn mesh2d_position_world_to_clip(world_position: vec4<f32>) -> vec4<f32> {
17 return view.clip_from_world * world_position;
20// NOTE: The intermediate world_position assignment is important
21// for precision purposes when using the 'equals' depth comparison
22// function.
23fn mesh2d_position_local_to_clip(world_from_local: mat4x4<f32>, vertex_position: vec4<f32>) -> vec4<f32> {
24 let world_position = mesh2d_position_local_to_world(world_from_local, vertex_position);
25 return mesh2d_position_world_to_clip(world_position);
28fn mesh2d_normal_local_to_world(vertex_normal: vec3<f32>, instance_index: u32) -> vec3<f32> {
29 return mat2x4_f32_to_mat3x3_unpack(
30 mesh[instance_index].local_from_world_transpose_a,
31 mesh[instance_index].local_from_world_transpose_b,
32 ) * vertex_normal;
35fn mesh2d_tangent_local_to_world(world_from_local: mat4x4<f32>, vertex_tangent: vec4<f32>) -> vec4<f32> {
36 return vec4<f32>(
37 mat3x3<f32>(
38 world_from_local[0].xyz,
39 world_from_local[1].xyz,
40 world_from_local[2].xyz
41 ) * vertex_tangent.xyz,
42 vertex_tangent.w
43 );
46fn get_tag(instance_index: u32) -> u32 {
47 return mesh[instance_index].tag;
50fn get_metadata(instance_index: u32) -> MeshMetadata {
51@if(METADATA_USE_UNIFORM_BUFFERS)
52 return metadata;
53@else
54 return metadata[mesh[instance_index].metadata_index];
Contents