-
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
Add ground atmosphere and day/night shading to Model and 3D Tiles #11765
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.
Some notes
I tried the OWT base globe, working nicely with styles and custom shaders! I am noticing the performance isn't the best for this example, but I'll have to see how much of that is due to the custom shader/styling and how much of that is the added overhead of atmosphere lighting. |
One of the specs in I stepped through the code with I checked the enum values in the uniform map and in the shader, they look correct. I also made sure the atmosphere object was propagated to the frame state. So not sure what's going on yet. |
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.
Some notes
// If the camera is inside the earth, skip rendering the ground atmosphere | ||
vec3 radii = czm_ellipsoidRadii; | ||
float minRadius = min(radii.x, min(radii.y, radii.z)); | ||
if (cameraHeight < minRadius) { | ||
return; | ||
} |
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.
A couple of specs were failing because a model at the center of the earth was rendering black. I'm guessing some of the lighting math breaks down near the origin.
I wasn't sure if this was the best way to filter out this corner case, but it sounds reasonable since the ground atmosphere is only shown when the camera is far outside the globe.
* @type {Cartesian2} | ||
* @default Cartesian2(1.0e7, 2.0e7) | ||
*/ | ||
this.lightingFadeRange = new Cartesian2(1.0e7, 2.0e7); |
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.
* @type {Cartesian2} | ||
* @default Cartesian2(5.0e7, 1.0e7) | ||
*/ | ||
this.nightFadeRange = new Cartesian2(1.0e7, 5.0e7); |
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.
Similarly, this is a rephrasing of [globe.nightFadeOutDistance, globe.nightFadeInDistance]
const float diffuseMultiplier = 5.0; | ||
const float vertexShadowDarkness = 0.3; | ||
float diffuseIntensity = clamp(lambert * diffuseMultiplier + vertexShadowDarkness, 0.0, 1.0); |
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.
Note: I wasn't sure how much globe.diffuseMultiplier
and globe.vertexShadowDarkness
are used, so I only implemented the default settings, not the vertex lighting in GlobeFS.glsl
.
Also note that these parameters could also be rephrased as "contrast" and "brightness" (i.e. a scale and shift of the intensity value)
// Use a dot product (similar to Lambert shading) to create a mask that's positive on the | ||
// daytime side of the globe and 0 on the nighttime side of the globe. | ||
// | ||
// Use this to select the diffuse + ground atmosphere on the daytime side of the globe, | ||
// and just the ground atmosphere (which is much darker) on the nighttime side. | ||
float dayNightMask = clamp(dot(normalWC, atmosphereLightDirectionWC), 0.0, 1.0); | ||
vec3 dayNightColor = mix(groundAtmosphereColor.rgb, diffuseAndGroundAtmosphere, dayNightMask); | ||
|
||
// Fade in the day/night color in as the camera height increases towards space. | ||
float nightFade = fade(cameraHeight, czm_atmosphereNightFadeRange, vec2(0.05, 1.0)); | ||
finalAtmosphereColor = mix(diffuseAndGroundAtmosphere, dayNightColor, nightFade); |
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.
in GlobeFS.glsl
, u_nightFadeDistance
, I found some of the variable names and usage a bit backwards to my understanding, so I rephrased it and documented the conventions I'm using.
It's mathematically equivalent, I just thought this way would be a little easier to understand.
I fixed it, basically the dark color was exactly black, I thought it was supposed to be slightly lighter than that, so I removed the one expectation. |
@ggetz @jjhembd I only briefly looked at performance of the OWT base globe with the FPS monitor. I would recommend doing more thorough performance testing, but here's my observations so far:
|
Thanks @ptrgags for all the work here! We are going to close this for now until we can dedicate someone to finishing up the work the testing an work you suggested here. |
Description
This PR adds ground atmosphere and day/night shading to the
AtmospherePipelineStage
for models and 3D Tiles. For world-scale datasets like P3DT, this will make it look a lot nicer!Issue number and link
Fixes #11717
Testing plan
Sandcastles for testing:
Author checklist
CONTRIBUTORS.md
CHANGES.md
with a short summary of my changeAtmospherePipelineStage
to the model rendering pipelineshowGroundAtmosphere
setting. Though think about how this will work betweenAtmosphere
andGlobe
.