Skip to content

Commit 4aca402

Browse files
hukasumockersf
authored andcommitted
Fix calculation of skybox rotation (#17476)
# Objective Fixes #16628 ## Solution Matrices were being applied in the wrong order. ## Testing Ran `skybox` example with rotations applied to the `Skybox` on the `x`, `y`, and `z` axis (one at a time). e.g. ```rust Skybox { image: skybox_handle.clone(), brightness: 1000.0, rotation: Quat::from_rotation_y(-45.0_f32.to_radians()), } ``` ## Showcase [Screencast_20250121_151232.webm](https://github.com/user-attachments/assets/3df68714-f5f1-4d8c-8e08-cbab525a8bda)
1 parent 1541727 commit 4aca402

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

crates/bevy_core_pipeline/src/skybox/skybox.wgsl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ fn coords_to_ray_direction(position: vec2<f32>, viewport: vec4<f32>) -> vec3<f32
3434
// Transforming the view space ray direction by the skybox transform matrix, it is
3535
// equivalent to rotating the skybox itself.
3636
var view_ray_direction = view_position_homogeneous.xyz / view_position_homogeneous.w;
37-
view_ray_direction = (uniforms.transform * vec4(view_ray_direction, 1.0)).xyz;
37+
view_ray_direction = (view.world_from_view * vec4(view_ray_direction, 0.0)).xyz;
3838

3939
// Transforming the view space ray direction by the view matrix, transforms the
4040
// direction to world space. Note that the w element is set to 0.0, as this is a
4141
// vector direction, not a position, That causes the matrix multiplication to ignore
4242
// the translations from the view matrix.
43-
let ray_direction = (view.world_from_view * vec4(view_ray_direction, 0.0)).xyz;
43+
let ray_direction = (uniforms.transform * vec4(view_ray_direction, 0.0)).xyz;
4444

4545
return normalize(ray_direction);
4646
}
@@ -63,14 +63,12 @@ struct VertexOutput {
6363
@vertex
6464
fn skybox_vertex(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
6565
// See the explanation above for how this works.
66-
let clip_position = vec4(
66+
let clip_position = vec2(
6767
f32(vertex_index & 1u),
6868
f32((vertex_index >> 1u) & 1u),
69-
0.25,
70-
0.5
71-
) * 4.0 - vec4(1.0);
69+
) * 4.0 - vec2(1.0);
7270

73-
return VertexOutput(clip_position);
71+
return VertexOutput(vec4(clip_position, 0.0, 1.0));
7472
}
7573

7674
@fragment

0 commit comments

Comments
 (0)