 9b9d3d81cb
			
		
	
	
		9b9d3d81cb
		
			
		
	
	
	
	
		
			
			# Objective - Fixes #10909 - Fixes #8492 ## Solution - Name all matrices `x_from_y`, for example `world_from_view`. ## Testing - I've tested most of the 3D examples. The `lighting` example particularly should hit a lot of the changes and appears to run fine. --- ## Changelog - Renamed matrices across the engine to follow a `y_from_x` naming, making the space conversion more obvious. ## Migration Guide - `Frustum`'s `from_view_projection`, `from_view_projection_custom_far` and `from_view_projection_no_far` were renamed to `from_clip_from_world`, `from_clip_from_world_custom_far` and `from_clip_from_world_no_far`. - `ComputedCameraValues::projection_matrix` was renamed to `clip_from_view`. - `CameraProjection::get_projection_matrix` was renamed to `get_clip_from_view` (this affects implementations on `Projection`, `PerspectiveProjection` and `OrthographicProjection`). - `ViewRangefinder3d::from_view_matrix` was renamed to `from_world_from_view`. - `PreviousViewData`'s members were renamed to `view_from_world` and `clip_from_world`. - `ExtractedView`'s `projection`, `transform` and `view_projection` were renamed to `clip_from_view`, `world_from_view` and `clip_from_world`. - `ViewUniform`'s `view_proj`, `unjittered_view_proj`, `inverse_view_proj`, `view`, `inverse_view`, `projection` and `inverse_projection` were renamed to `clip_from_world`, `unjittered_clip_from_world`, `world_from_clip`, `world_from_view`, `view_from_world`, `clip_from_view` and `view_from_clip`. - `GpuDirectionalCascade::view_projection` was renamed to `clip_from_world`. - `MeshTransforms`' `transform` and `previous_transform` were renamed to `world_from_local` and `previous_world_from_local`. - `MeshUniform`'s `transform`, `previous_transform`, `inverse_transpose_model_a` and `inverse_transpose_model_b` were renamed to `world_from_local`, `previous_world_from_local`, `local_from_world_transpose_a` and `local_from_world_transpose_b` (the `Mesh` type in WGSL mirrors this, however `transform` and `previous_transform` were named `model` and `previous_model`). - `Mesh2dTransforms::transform` was renamed to `world_from_local`. - `Mesh2dUniform`'s `transform`, `inverse_transpose_model_a` and `inverse_transpose_model_b` were renamed to `world_from_local`, `local_from_world_transpose_a` and `local_from_world_transpose_b` (the `Mesh2d` type in WGSL mirrors this). - In WGSL, in `bevy_pbr::mesh_functions`, `get_model_matrix` and `get_previous_model_matrix` were renamed to `get_world_from_local` and `get_previous_world_from_local`. - In WGSL, `bevy_sprite::mesh2d_functions::get_model_matrix` was renamed to `get_world_from_local`.
		
			
				
	
	
		
			46 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			WebGPU Shading Language
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			WebGPU Shading Language
		
	
	
	
	
	
| #define_import_path bevy_sprite::mesh2d_functions
 | |
| 
 | |
| #import bevy_sprite::{
 | |
|     mesh2d_view_bindings::view,
 | |
|     mesh2d_bindings::mesh,
 | |
| }
 | |
| #import bevy_render::maths::{affine3_to_square, mat2x4_f32_to_mat3x3_unpack}
 | |
| 
 | |
| fn get_world_from_local(instance_index: u32) -> mat4x4<f32> {
 | |
|     return affine3_to_square(mesh[instance_index].world_from_local);
 | |
| }
 | |
| 
 | |
| fn mesh2d_position_local_to_world(world_from_local: mat4x4<f32>, vertex_position: vec4<f32>) -> vec4<f32> {
 | |
|     return world_from_local * vertex_position;
 | |
| }
 | |
| 
 | |
| fn mesh2d_position_world_to_clip(world_position: vec4<f32>) -> vec4<f32> {
 | |
|     return view.clip_from_world * world_position;
 | |
| }
 | |
| 
 | |
| // NOTE: The intermediate world_position assignment is important
 | |
| // for precision purposes when using the 'equals' depth comparison
 | |
| // function.
 | |
| fn mesh2d_position_local_to_clip(world_from_local: mat4x4<f32>, vertex_position: vec4<f32>) -> vec4<f32> {
 | |
|     let world_position = mesh2d_position_local_to_world(world_from_local, vertex_position);
 | |
|     return mesh2d_position_world_to_clip(world_position);
 | |
| }
 | |
| 
 | |
| fn mesh2d_normal_local_to_world(vertex_normal: vec3<f32>, instance_index: u32) -> vec3<f32> {
 | |
|     return mat2x4_f32_to_mat3x3_unpack(
 | |
|         mesh[instance_index].local_from_world_transpose_a,
 | |
|         mesh[instance_index].local_from_world_transpose_b,
 | |
|     ) * vertex_normal;
 | |
| }
 | |
| 
 | |
| fn mesh2d_tangent_local_to_world(world_from_local: mat4x4<f32>, vertex_tangent: vec4<f32>) -> vec4<f32> {
 | |
|     return vec4<f32>(
 | |
|         mat3x3<f32>(
 | |
|             world_from_local[0].xyz,
 | |
|             world_from_local[1].xyz,
 | |
|             world_from_local[2].xyz
 | |
|         ) * vertex_tangent.xyz,
 | |
|         vertex_tangent.w
 | |
|     );
 | |
| }
 |