Skip to content
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

skybox.wgsl: Fix precision issues #9909

Merged
merged 3 commits into from
Sep 23, 2023

Conversation

superdump
Copy link
Contributor

Objective

Solution

  • At large translations (a few thousand units), the precision of calculating the ray direction from the fragment world position and camera world position seems to break down. Sampling the cubemap only needs the ray direction. As such we can use the view space fragment position, normalise it, rotate it to world space, and use that.

Changelog

  • Fixed: Jittery skybox at large translations.

crates/bevy_core_pipeline/src/skybox/skybox.wgsl Outdated Show resolved Hide resolved
1.0,
1.0
);
let view_position = view_position_homogeneous.xyz / view_position_homogeneous.w;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

view_position_homogeneous.w is constant 1.0 from above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, copy pasta.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually no. This was wrong. The vec4 position is multiplied by the inverse projection matrix, so the resulting w is not guaranteed to be 1.0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops right

crates/bevy_core_pipeline/src/skybox/skybox.wgsl Outdated Show resolved Hide resolved
@superdump superdump added this pull request to the merge queue Sep 23, 2023
Merged via the queue into bevyengine:main with commit 22dfa9e Sep 23, 2023
21 checks passed
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this pull request Jan 9, 2024
# Objective

- Fixes bevyengine#9707 

## Solution

- At large translations (a few thousand units), the precision of
calculating the ray direction from the fragment world position and
camera world position seems to break down. Sampling the cubemap only
needs the ray direction. As such we can use the view space fragment
position, normalise it, rotate it to world space, and use that.

---

## Changelog

- Fixed: Jittery skybox at large translations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bevy Skybox Jittering/Pixelating at Medium/Large Translations
3 participants