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

expose new scalar to change the visual density of fog #12248

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

jjspace
Copy link
Contributor

@jjspace jjspace commented Oct 10, 2024

Description

  • Add a new property to adjust the visual density of fog relative to the "actual" density which also affects culling
  • change the default visual scalar from 0.15 to 0.4 which should make the densest fog possible right around where tiles are culled
Old default 0.15 New default 0.4
download (41) download (42)
download (43) download (44)
Density function details

These graphs show the density function values. The y value between 0 and 1 is used to determine the percentage for mixing the original color and the fog color. mix(originalColor, fogColor, percent)
ie. closer to 1 means more fog color

Any tile with a value greater than 1 is culled and thus not rendered
Any tile or model with a value less than 0.001 does not get any fog color at all to aid in performance, the fog would be negligible.

The red line is the "true" fog function that is calculated without any scalar. This is the one used for culling
The purple line is the fog function with the modifier included. The purple area is where fog is actually being displayed

This is the before value with a modifier of 0.15

2024-10-10_12-07

This is the same functions with a modifier of 0.4. As you can see the fog (purple) much closer matches reaching 1 around the same time the red fog function does. This means it's visually most dense at around the same distance tiles are culled.

2024-10-10_12-07_1

The density is cranked up way higher than normal to make seeing the curves clearer
Desmos link if you want to play with the values yourself
(the v value is there to exaggerate the graphs visually so you can still see the curves even if you stretch the density out really far)

Issue number and link

Part of #12126

Testing plan

  • Open the updated Fog sandcastle and play around with the visual density scalar value
    • Modify the actual density with different scalar values to see how they affect each other.

Author checklist

  • I have submitted a Contributor License Agreement
  • I have added my name to CONTRIBUTORS.md
  • I have updated CHANGES.md with a short summary of my change
  • I have added or updated unit tests to ensure consistent code coverage
  • I have updated the inline documentation, and included code examples where relevant
  • I have performed a self-review of my code

@jjspace jjspace requested a review from ggetz October 10, 2024 16:13
Copy link

Thank you for the pull request, @jjspace!

✅ We can confirm we have a CLA on file for you.

@ggetz
Copy link
Contributor

ggetz commented Oct 11, 2024

This is the same functions with a modifier of 0.4. As you can see the fog (purple) much closer matches reaching 1 around the same time the red fog function does. This means it's visually most dense at around the same distance tiles are culled.

Good explanation! So for the default, we wouldn't want to go any less that 0.4 from the sound of it.

I was playing around with GE as a point of comparison, and their fog appears much denser, even than visual density equivalent of 1.0 in our system (which I think is the maximum, based on the function visualizations). What are your thoughts?

image

Copy link
Contributor

@ggetz ggetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jjspace. A few comments on the code.

Please also add a unit test and update CHANGES.md.

packages/engine/Source/Core/Math.js Outdated Show resolved Hide resolved
packages/engine/Source/Renderer/AutomaticUniforms.js Outdated Show resolved Hide resolved
packages/engine/Source/Scene/Fog.js Outdated Show resolved Hide resolved
packages/engine/Source/Scene/Fog.js Outdated Show resolved Hide resolved
@jjspace
Copy link
Contributor Author

jjspace commented Oct 11, 2024

I was playing around with GE as a point of comparison, and their fog appears much denser, even than visual density equivalent of 1.0 in our system (which I think is the maximum, based on the function visualizations). What are your thoughts?

I actually think the density of our fog is about the same. But ours is much darker. Maybe this has to do with some of the atmosphere values?

This is approximately the same location in CesiumJS (with 0.4) and Google Earth. (I just noticed GE seems to put a touch of a fish eye effect on the fov?)
2024-10-11_16-26
2024-10-11_16-27

This is that same view with the visualDensityScalar set to 1.0. I think this looks much more dense than GE's so i'm surprised to hear you say the opposite. does this match with what you saw?
2024-10-11_16-27_1

Edit (immediate follow up...):
I did just notice our fog seems inconsistently applied as we zoom in and out and very close to the ground it's not applied at all which I think might be the cause of your previous comment about it not being as dense as GE. They seem to apply fog consistently across all zoom levels. Not sure the cause for this.

simplescreenrecorder-2024-10-11_16.33.51.mp4
simplescreenrecorder-2024-10-11_16.36.30.mp4

@ggetz
Copy link
Contributor

ggetz commented Oct 14, 2024

I did just notice our fog seems inconsistently applied as we zoom in and out and very close to the ground it's not applied at all which I think might be the cause of your previous comment about it not being as dense as GE. They seem to apply fog consistently across all zoom levels. Not sure the cause for this.

Yes, I was looking at a horizon few similar to this one. This is what prompted my question. I agree that from your more "aerial" screenshots, the density does read correctly at a value of 0.4.

My guess for what is causing this may be the atmosphere scattering code returning transparent colors for fog when close to the ground. Perhaps try stubbing out the atmosphere color function with one that returns a solid color for the sake of debugging. Once we identify the cause, we can figure out an implementation plan, and if it's scope.

If that's not the case, my shot in the dark is that this may be related to #11922. The horizon angle is what's jumping out to me as similar.

But ours is much darker. Maybe this has to do with some of the atmosphere values?

I agree. I assume that will be out of scope for this PR. I believe the reasons for this are documented in #11717 (comment).

CHANGES.md Show resolved Hide resolved
@jjspace
Copy link
Contributor Author

jjspace commented Oct 21, 2024

@ggetz I fixed up the couple docs issues and moved the fog sandcastle as discussed offline.

That said I'm still confused what's causing the fog to be basically non-existant close to the ground and have such a massive spike in density at a certain height. I tried swapping the fog color out for a static magenta 1, 0, 1 instead of the atmosphere color and still observe the same issues. I'm thinking it might have something to do with the depth/distance calculations? I made a slightly modified sandcastle to easily reproduce the zoom.

simplescreenrecorder-2024-10-21_15.39.28.mp4

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

Successfully merging this pull request may close these issues.

2 participants