The most common question we receive about the SilverLining Sky, 3D Cloud, and Weather SDK is how to properly handle reduced visibility conditions. SilverLining offers a lot of flexibility in how fog and haze are handled, but it can be complex and confusing. Our documentation covers the topic, but I’ll try and explain from a higher level in this post.
Telling SilverLining About Visibility
First, understand that normally you tell SilverLining how to fog the sky and clouds. SilverLining is not responsible for fogging your terrain, objects, or whatever else is in your scene. It’s up to you to decide what sort of visibility you want to simulate, tell SilverLining about it, and fog the rest of your scene consistently.
SilverLining allows you to fog the sky and clouds separately. Let’s cover the different API calls that exist for handling visibility:
AtmosphericConditions::SetVisibility() – This causes clouds to fog out and fade out at the given visibility distance. It does not affect the sky itself. If you have an exponential fog density value, you can convert that to a visibility distance using the relationship visibility = 3.912 / density. Note that fog is usually thicker at the ground than up where the clouds are, so it may be appropriate to set a higher visibility value with SilverLining than what you are using for the rest of your scene.
Atmosphere::SetHaze – This exists to let you blend the sky to a solid color at the horizon. Often, this is needed for seamless blending of the sky with fog on your distant terrain. It allows you to set a fog color, density, and height – the height parameter controls how far up the sky box the fog effect reaches. It doesn’t matter what the altitude of the camera is; this is always relative to the horizon. You can use this to apply fog to the sky itself that looks volumetric in nature. You’ll still need to call AtmosphericConditions::SetVisibility() as well, in order to fog out the clouds consistently.
AtmosphericConditions::SetFog – This method applies exponential fog only to the clouds, not the sky, with a specific fog color. It may be appropriate for unusual situations like thick smoke, where you want to apply dense fog to the clouds with a particular color. You’ll still need to use SetHaze() to color the skybox itself.
Under normal circumstances, using SetVisibility() to affect the cloud visibility and SetHaze() to affect the sky colors generally produces the best results.
Fog Inside Clouds
There are some cases where SilverLining will recommend a given fog density and color to be applied to the rest of your scene. One such case is when the camera is inside of a stratus cloud.
If your camera could be inside the clouds, then each frame you’ll want to call Atmosphere::GetFogEnabled(). If it comes back as true, then you must query Atmosphere::GetFogSettings() to retrieve the fog color and density that should be applied to the rest of your scene. This will ensure consistent fogging with the cloud itself, and give you smooth effects as the camera enters and exits the cloud.
Fog Inside Precipitation
If the camera is inside rain, sleet, or snow, Atmosphere::GetFogEnabled() will also return true, and Atmosphere::GetFogSettings() will give you realistic visibility for the precipitation rate you are simulating.
Many customers prefer to manage visibility inside precipitation on their own, and find it confusing when the clouds are no longer directly visible when it’s raining. To disable this effect, open up the file Resources/SilverLining.config in a text editor, and look for the setting enable-precipitation-visibility-effects. Set this to “no”, and SilverLining will no longer indicate fog when inside precipitation.
Choosing a Fog Color
SilverLining can help to choose a realistic color to use when fogging the rest of your scene. Atmosphere::GetHorizonColor() will return the simulated color of the sky near the horizon. This is usually an appropriate color to use when fogging your terrain and other objects, and it’s also appropriate for using as a color if you’re calling Atmosphere::SetHaze().
Atmospheric scattering is a big, complex topic, and SilverLining’s model is actually rather simple. I hope this article de-mystifies handling fog and visibility in SilverLining somewhat.