mirror of
https://github.com/bevyengine/bevy
synced 2024-12-19 01:23:09 +00:00
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`.
35 lines
1.5 KiB
WebGPU Shading Language
35 lines
1.5 KiB
WebGPU Shading Language
#import bevy_pbr::forward_io::VertexOutput
|
|
#import bevy_pbr::irradiance_volume
|
|
#import bevy_pbr::mesh_view_bindings
|
|
|
|
struct VoxelVisualizationIrradianceVolumeInfo {
|
|
world_from_voxel: mat4x4<f32>,
|
|
voxel_from_world: mat4x4<f32>,
|
|
resolution: vec3<u32>,
|
|
// A scale factor that's applied to the diffuse and specular light from the
|
|
// light probe. This is in units of cd/m² (candela per square meter).
|
|
intensity: f32,
|
|
}
|
|
|
|
@group(2) @binding(100)
|
|
var<uniform> irradiance_volume_info: VoxelVisualizationIrradianceVolumeInfo;
|
|
|
|
@fragment
|
|
fn fragment(mesh: VertexOutput) -> @location(0) vec4<f32> {
|
|
// Snap the world position we provide to `irradiance_volume_light()` to the
|
|
// middle of the nearest texel.
|
|
var unit_pos = (irradiance_volume_info.voxel_from_world *
|
|
vec4(mesh.world_position.xyz, 1.0f)).xyz;
|
|
let resolution = vec3<f32>(irradiance_volume_info.resolution);
|
|
let stp = clamp((unit_pos + 0.5) * resolution, vec3(0.5f), resolution - vec3(0.5f));
|
|
let stp_rounded = round(stp - 0.5f) + 0.5f;
|
|
let rounded_world_pos = (irradiance_volume_info.world_from_voxel * vec4(stp_rounded, 1.0f)).xyz;
|
|
|
|
// `irradiance_volume_light()` multiplies by intensity, so cancel it out.
|
|
// If we take intensity into account, the cubes will be way too bright.
|
|
let rgb = irradiance_volume::irradiance_volume_light(
|
|
mesh.world_position.xyz,
|
|
mesh.world_normal) / irradiance_volume_info.intensity;
|
|
|
|
return vec4<f32>(rgb, 1.0f);
|
|
}
|