-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Atmosphere LUT parameterization improvements #17555
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
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.
Just a bit of clarification on top of alice's, otherwise lgtm. Did some additional testing, I'll post a video showing the from-space view of the sun disc correctly dropping below the planet edge rather than the 0 degree zenith.
orbital.sunset.mp4 |
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.
few small nits that could use clarification, otherwise lgtm :)
After some more discussions, this discovery points to an issue in how the sample points are calculated. Therefore in order to remove the 0.5 texel offset in the sampling function, we need to fix the math that compute the sample positions. I will work on that tomorrow. |
I've corrected the quadratic sampling in the sky view lut, reverted that to linear to recover the numerical accuracy. I've added a constant variable for the I posted the test scene and the raymarched reference code in the |
minor fixes
// where in the segment that sample is taken (0.0 = start, 0.5 = middle, 1.0 = end). | ||
// We use 0.3 to sample closer to the start of each segment, which better approximates | ||
// the exponential falloff of atmospheric density. | ||
const MIDPOINT_RATIO: f32 = 0.3; |
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.
This could be exposed as a uniform variable, since it can differ depending on the scale height of the scatterers in the atmosphere.
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.
possibly, if it doesn't add more complexity to the user-facing api. Alternatively we could also just do the integration differently, for example piecewise linearly or quadratically (trapezoid rule vs simpson's rule)
Okay great! I think I've addressed everything and this PR is ready for the merge queue @alice-i-cecile |
Great cleanup and bug fixes; thanks a ton <3 |
# Objective - Fix the atmosphere LUT parameterization in the aerial -view and sky-view LUTs - Correct the light accumulation according to a ray-marched reference - Avoid negative values of the sun disk illuminance when the sun disk is below the horizon ## Solution - Adding a Newton's method iteration to `fast_sqrt` function - Switched to using `fast_acos_4` for better precision of the sun angle towards the horizon (view mu angle = 0) - Simplified the function for mapping to and from the Sky View UV coordinates by removing an if statement and correctly apply the method proposed by the [Hillarie paper](https://sebh.github.io/publications/egsr2020.pdf) detailed in section 5.3 and 5.4. - Replaced the `ray_dir_ws.y` term with a shadow factor in the `sample_sun_illuminance` function that correctly approximates the sun disk occluded by the earth from any view point ## Testing - Ran the atmosphere and SSAO examples to make sure the shaders still compile and run as expected. --- ## Showcase <img width="1151" alt="showcase-img" src="https://github.com/user-attachments/assets/de875533-42bd-41f9-9fd0-d7cc57d6e51c" /> --------- Co-authored-by: Emerson Coskey <[email protected]>
# Objective - Fix the atmosphere LUT parameterization in the aerial -view and sky-view LUTs - Correct the light accumulation according to a ray-marched reference - Avoid negative values of the sun disk illuminance when the sun disk is below the horizon ## Solution - Adding a Newton's method iteration to `fast_sqrt` function - Switched to using `fast_acos_4` for better precision of the sun angle towards the horizon (view mu angle = 0) - Simplified the function for mapping to and from the Sky View UV coordinates by removing an if statement and correctly apply the method proposed by the [Hillarie paper](https://sebh.github.io/publications/egsr2020.pdf) detailed in section 5.3 and 5.4. - Replaced the `ray_dir_ws.y` term with a shadow factor in the `sample_sun_illuminance` function that correctly approximates the sun disk occluded by the earth from any view point ## Testing - Ran the atmosphere and SSAO examples to make sure the shaders still compile and run as expected. --- ## Showcase <img width="1151" alt="showcase-img" src="https://github.com/user-attachments/assets/de875533-42bd-41f9-9fd0-d7cc57d6e51c" /> --------- Co-authored-by: Emerson Coskey <[email protected]>
Objective
Solution
fast_sqrt
functionfast_acos_4
for better precision of the sun angle towards the horizon (view mu angle = 0)ray_dir_ws.y
term with a shadow factor in thesample_sun_illuminance
function that correctly approximates the sun disk occluded by the earth from any view pointTesting
Showcase