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#define_import_path bevy_sprite::mesh2d_functions
3#import bevy_sprite::{
4 mesh2d_view_bindings::view,
5 mesh2d_bindings::mesh,
6}
7#import bevy_render::maths::{affine3_to_square, mat2x4_f32_to_mat3x3_unpack}
9fn get_world_from_local(instance_index: u32) -> mat4x4<f32> {
10 return affine3_to_square(mesh[instance_index].world_from_local);
13fn mesh2d_position_local_to_world(world_from_local: mat4x4<f32>, vertex_position: vec4<f32>) -> vec4<f32> {
14 return world_from_local * vertex_position;
17fn mesh2d_position_world_to_clip(world_position: vec4<f32>) -> vec4<f32> {
18 return view.clip_from_world * world_position;
21// NOTE: The intermediate world_position assignment is important
22// for precision purposes when using the 'equals' depth comparison
23// function.
24fn mesh2d_position_local_to_clip(world_from_local: mat4x4<f32>, vertex_position: vec4<f32>) -> vec4<f32> {
25 let world_position = mesh2d_position_local_to_world(world_from_local, vertex_position);
26 return mesh2d_position_world_to_clip(world_position);
29fn mesh2d_normal_local_to_world(vertex_normal: vec3<f32>, instance_index: u32) -> vec3<f32> {
30 return mat2x4_f32_to_mat3x3_unpack(
31 mesh[instance_index].local_from_world_transpose_a,
32 mesh[instance_index].local_from_world_transpose_b,
33 ) * vertex_normal;
36fn mesh2d_tangent_local_to_world(world_from_local: mat4x4<f32>, vertex_tangent: vec4<f32>) -> vec4<f32> {
37 return vec4<f32>(
38 mat3x3<f32>(
39 world_from_local[0].xyz,
40 world_from_local[1].xyz,
41 world_from_local[2].xyz
42 ) * vertex_tangent.xyz,
43 vertex_tangent.w
44 );
47fn get_tag(instance_index: u32) -> u32 {
48 return mesh[instance_index].tag;
Contents