Skip to content
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

Visualize ground atmosphere for 3D TIles/Models #11717

Open
ptrgags opened this issue Dec 21, 2023 · 3 comments
Open

Visualize ground atmosphere for 3D TIles/Models #11717

ptrgags opened this issue Dec 21, 2023 · 3 comments

Comments

@ptrgags
Copy link
Contributor

ptrgags commented Dec 21, 2023

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 #11681 (comment) 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
Copy link
Contributor Author

ptrgags commented Jan 9, 2024

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
Copy link
Contributor Author

ptrgags commented Jan 12, 2024

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

  • Start with the raw color of the globe from imagery, globe materials, etc. (or in the case of 3D Tiles, it'll just be the computed color at that point in the shader)
  • Compute a Lambert diffuse term for the globe. Note that while this dims the color of the globe, it's only medium-dark, night-time shading happens later.
  • Depending on the camera height in relation to lightFade(Out|In)Distance, blend between unlit and diffuse lighting. (see the green curve in the diagram below)
  • The atmosphere scattering function computes:
    • a ground atmosphere color. Note that this is bright near the sun, and near black on the night-time side of the globe.
    • a transmittance value. This represents how the circumference of the earth looks brighter since light has to travel through more atmosphere there.
  • Use these atmosphere values to brighten up the globe around the edges (color = diffuse + groundAtmosphere * transmittance)
  • We want to darken the night-time side of the globe. So compute another diffuse-like term, but this time use it to select between the ground atmosphere on the night-time side (remember the ground atmosphere color is close to black there) and the diffuse + ground atmosphere term. This has the effect of darkening the night-time side of the globe which was mid-brightness before.
  • Depending on the camera height in relation to 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:

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:

  • "fade in" -- above these values, a lighting effect starts to be applied
  • "fade out" -- below these values, a lighting effect starts to be removed

@ptrgags
Copy link
Contributor Author

ptrgags commented Jan 12, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants