CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
12.66k stars 3.43k forks source link

Visualize ground atmosphere for 3D TIles/Models #11717

Open ptrgags opened 8 months ago

ptrgags commented 8 months ago

Splitting up #4196 into smaller tasks

This task is closely related to #11716, but it focuses on ground atmosphere rather than fog.

In GlobeFS.glsl, the globe shader handles both fog and ground atmosphere. In the spirit of Model's pipeline stages, I envision this being implemented as a GroundAtmospherePipelineStage that's separate from FogPipelineStage

Also, see https://github.com/CesiumGS/cesium/issues/11681#issuecomment-1865080064 for the proposed scene.groundAtmosphere object that will make it easier to propagate settings via the FrameState and/or AutomaticUniforms

One detail to note: Some details like computing the atmosphere color would be expensive to duplicate if both fog and ground atmosphere are needed for the same model, so it's best to avoid that.

ptrgags commented 8 months ago

One note from #11744: right now the FogStageFS (and eventually FogStageVS) calls the atmosphere functions. To avoid computing the color twice, it may make sense to move some calls up a level and pass the colors into the scattering function.

Another question is should ground atmosphere be a separate pipeline stage at all? it mainly adds a bit of shader code and at most a couple more uniforms.

Maybe renaming the pipeline stage to AtmosphereEffectsPipelineStage would be sufficient here.

ptrgags commented 7 months ago

After exploring the globe shader a bit, ground atmosphere and daynight shading are starting to make more sense. The fading logic is a bit complex, so here's a quick summary from GlobeFS

The default fading is a little non-obvious so here's a diagram of the fading curves with increasing camera height from the earth's surface:

image

  1. Near the earth's surface (below lightingFadeOutDistance == nightFadeOutDistance = 1e7 m), no diffuse lighting or nighttime shading is applied (note however that ground atmosphere is always applied)
  2. As the camera approaches lightingFadeInDistance, diffuse lighting is blended in quickly. The nighttime shading starts to be blended in, but slower
  3. between lightingFadeInDistance and nightFadeInDistance, the diffuse term is at maximum brightness, but the overall color is fading to the night-time color
  4. Above nightFadeInDistance, only the night-time shading is applied.

Finally, a note about the variable names. It is a bit confusing that we use "fade in/out" as the terminology, though I haven't thought of a better name yet. In practice, they work like this:

ptrgags commented 7 months ago

Oh it looks like I missed one line at the end of GlobeFS, after all of that blending described above, you blend again between the diffuse term (no ground atmosphere) and the lit term (result of algorithm above), based on the lighting fade distance curve.

So the 4 regions of the diagram are really:

  1. unlit only
  2. nonlinear blend from unlit -> diffuse -> start of day-night lighting
  3. linear blend to day/night lighting
  4. day/night lighting only