-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix calculation of skybox rotation #17476
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, I also noticed this issue in main while trying to align a skybox and directional light. Thanks for fixing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes seem good and I've tested with the skybox example. But left a suggestion to update comments and variable names.
// Transforming the view space ray direction by the skybox transform matrix, it is | ||
// equivalent to rotating the skybox itself. | ||
var view_ray_direction = view_position_homogeneous.xyz / view_position_homogeneous.w; | ||
view_ray_direction = (uniforms.transform * vec4(view_ray_direction, 1.0)).xyz; | ||
view_ray_direction = (view.world_from_view * vec4(view_ray_direction, 0.0)).xyz; | ||
|
||
// Transforming the view space ray direction by the view matrix, transforms the | ||
// direction to world space. Note that the w element is set to 0.0, as this is a | ||
// vector direction, not a position, That causes the matrix multiplication to ignore | ||
// the translations from the view matrix. | ||
let ray_direction = (view.world_from_view * vec4(view_ray_direction, 0.0)).xyz; | ||
let ray_direction = (uniforms.transform * vec4(view_ray_direction, 0.0)).xyz; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the comments and variable names are now misleading? Should be something like:
// Transforming the view space ray direction by the skybox transform matrix, it is | |
// equivalent to rotating the skybox itself. | |
var view_ray_direction = view_position_homogeneous.xyz / view_position_homogeneous.w; | |
view_ray_direction = (uniforms.transform * vec4(view_ray_direction, 1.0)).xyz; | |
view_ray_direction = (view.world_from_view * vec4(view_ray_direction, 0.0)).xyz; | |
// Transforming the view space ray direction by the view matrix, transforms the | |
// direction to world space. Note that the w element is set to 0.0, as this is a | |
// vector direction, not a position, That causes the matrix multiplication to ignore | |
// the translations from the view matrix. | |
let ray_direction = (view.world_from_view * vec4(view_ray_direction, 0.0)).xyz; | |
let ray_direction = (uniforms.transform * vec4(view_ray_direction, 0.0)).xyz; | |
// Transforming the view space ray direction by the view matrix, transforms the | |
// direction to world space. Note that the w element is set to 0.0, as this is a | |
// vector direction, not a position, That causes the matrix multiplication to ignore | |
// the translations from the view matrix. | |
let view_ray_direction = view_position_homogeneous.xyz / view_position_homogeneous.w; | |
let world_ray_direction = (view.world_from_view * vec4(view_ray_direction, 0.0)).xyz; | |
// Transforming the world space ray direction by the skybox transform matrix, it is | |
// equivalent to rotating the skybox itself. | |
let ray_direction = (uniforms.transform * vec4(world_ray_direction, 0.0)).xyz; |
Objective
Fixes #16628
Solution
Matrices were being applied in the wrong order.
Testing
Ran
skybox
example with rotations applied to theSkybox
on thex
,y
, andz
axis (one at a time).e.g.
Showcase
Screencast_20250121_151232.webm