-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Improve sky atmosphere #8866
Improve sky atmosphere #8866
Conversation
Thanks for the pull request @lilleyse!
Reviewers, don't forget to make sure that:
|
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. I liked how most of the lighting calculations have moved to their own file. Main issue is the edge artifact (screenshots inside). This is a tricky problem because you don't want the atmosphere to get ultra bright like it used to, but you also don't want it to fade to the more neutral blue color too early either, which is what's happening in those screenshots.
Source/Shaders/SkyAtmosphereFS.glsl
Outdated
#ifdef PER_FRAGMENT_ATMOSPHERE | ||
vec3 mieColor; | ||
vec3 rayleighColor; | ||
calculateMieColorAndRayleighColor(v_outerPositionWC, 1.0, mieColor, rayleighColor); |
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.
At the horizon it can show a thin sliver where the atmosphere starts to transition back to blue. This is because the globe triangles dip slightly below the pixel-perfect ray ellipsoid intersection. Changing the 1.0 to 1.003 fixes the problem
There is also a small difference when zoomed out due to lower detail triangles which might force the constant to be even bigger:
@IanLilleyT updated |
Got per-vertex rendering to look a lot better, almost as good as per-fragment. It's good enough that I'm switching back to per-vertex by default and not taking the performance hit. The trick was to align the ellipsoid geometry so it always faces the same direction as the camera. So wherever you're looking the tessellation should look the same. Another thing that helps is 1409f1d adds a smoother gradient falloff. I'm still deciding whether this is better than doing the original approach. |
It's possible the results are system dependent. The early discard check |
While digging deep into the atmosphere code I noticed that the sky atmosphere gets yellow-er the further you are from the equator which has always bothered me and doesn't really physically make sense. The atmosphere start position now takes into account the camera's height from the ellipsoid rather than a straight up Somewhere in AlaskaSomewhere in the Amazon near the equator |
b023803
to
42d08d5
Compare
109da35
to
1234027
Compare
@IanLilleyT updated. This also includes a fix to a globe lighting / ground atmosphere crash in master. |
One (future) idea for fixing artifacts when the view is pointing through the ellipsoid and the globe isn't visible is to find a tangent line to the ellipsoid from the camera's position and run the atmosphere calculations relative to that. This will (hopefully) make the horizon color consistent throughout the center of the earth and will let use remove some hacks like clamping strength, fading to alpha, etc. The tangent line could come from intersecting a plane containing the camera view and up vectors against the ellipsoid, giving an ellipse which will have only two tangent lines, and pick one of the two tangent lines based on which is closer to the view direction. Not sure how this should work if the camera is below the ellipsoid... |
Looks good, thanks @lilleyse ! |
This PR tweaks a few things about how the sky atmosphere is rendered so that there's less artifacts. These artifacts usually show up as white/black (and sometimes red/yellow) patches below the horizon point.
The two main changes are
Both the per-fragment and per-vertex code paths look nearly identical when the globe is rendered. The per-vertex path still has some stair-step artifacts that become more obvious when globe tiles are loading in or the globe is hidden. The code defaults to per-fragment shading because it looks good all the time. The code always uses per-fragment shading when the globe is translucent in
globe-alpha
.There is small runtime cost. On my 2015 Macbook, with
viewer.browserRecommendedResolution = false
there is a 2-3 fps between per-fragment and per-vertex. Performance critical applications can setviewer.scene.skyAtmosphere.perFragmentAtmosphere
tofalse
.Comparison of the different modes:
master
per-vertex
per-fragment
master
per-fragment
(Note the camera is momentarily considered underground while tiles are loading which causes the globe to look dark, this is a separate problem)
Sandcastle for testing