Open ptrgags opened 11 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.
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
lightFade(Out|In)Distance
, blend between unlit and diffuse lighting. (see the green curve in the diagram below)color = diffuse + groundAtmosphere * transmittance
)nightFade(Out|In)Distance
, blend between (diffuse + ground atmosphere) and the darkened color. This makes it so the night time shading only appears when you're zoomed out. (see the red curve in the diagram below)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:
lightingFadeOutDistance == nightFadeOutDistance = 1e7 m
), no diffuse lighting or nighttime shading is applied (note however that ground atmosphere is always applied)lightingFadeInDistance
, diffuse lighting is blended in quickly. The nighttime shading starts to be blended in, but slowerlightingFadeInDistance
and nightFadeInDistance
, the diffuse term is at maximum brightness, but the overall color is fading to the night-time colornightFadeInDistance
, 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:
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:
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 ofModel
's pipeline stages, I envision this being implemented as aGroundAtmospherePipelineStage
that's separate fromFogPipelineStage
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 theFrameState
and/orAutomaticUniforms
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.