Author Topic: Fog colour varying by depth  (Read 170 times)

Frozenempire

  • Full Member
  • ***
  • Posts: 183
    • View Profile
    • The Frozen Empire
Fog colour varying by depth
« on: June 08, 2019, 07:01:15 AM »
Hi again!

Is there any way to achieve this with the current parameters?
I was thinking not hence why Iím posting it under feature requests.

Basically my scene fogs quite heavily into the horizon using Enviro.
The VFM fog is uniformly bright from front of the scene to back

Can we in effect fog the fog so that it gets darker in the distance, or perhaps less dense in the distance so that it fades better into the horizon colouring. Iím not talking about distance falloff, but colouring of the remaining fog in the distance after using falloff

Regards

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 4662
    • View Profile
Re: Fog colour varying by depth
« Reply #1 on: June 08, 2019, 11:00:56 AM »
Try reducing the Depth slider in Sky Haze section and setting an opaque color for sky haze. That will bring the background fog to the front eventually blending with the volumetric fog.

Frozenempire

  • Full Member
  • ***
  • Posts: 183
    • View Profile
    • The Frozen Empire
Re: Fog colour varying by depth
« Reply #2 on: June 08, 2019, 11:21:35 AM »
Not using VFM sky haze
all the sky and weather is done with Enviro
Enabling VFM sky haze just seems to interfere with it...


Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 4662
    • View Profile
Re: Fog colour varying by depth
« Reply #3 on: June 08, 2019, 11:38:44 AM »
Sky haze can work as a depth based fog which fills the gap between the volumetric fog at max distance and the skybox.
How does your scene look without sky haze? Can you post a screenshot - not sure to understand what you want to do.

Frozenempire

  • Full Member
  • ***
  • Posts: 183
    • View Profile
    • The Frozen Empire
Re: Fog colour varying by depth
« Reply #4 on: June 09, 2019, 12:49:40 AM »
Sure

Here is the Fog of War demo scene to demonstrate what I'm trying to achieve.

Top screen is the demo as it comes, from a high vantage point. You can see that the fog ends abruptly in the far distance. I know that you can use the distance falloff to soften this, but I'm looking for a different effect...

Bottom screen shows what I'm looking for - a fade of the fog colour into the skybox/horizon. To achieve what you see I made a temporary shader mod at the end of the  getFogColor function:

Code
// Fade into distance
float fFadeStartDist = 500.0;
float fFadeEndDist = 1000.0;
float fFadeFactor = saturate((adir.w - fFadeStartDist)/(fFadeEndDist - fFadeStartDist)); // adir.w
sum *= max(1.0-fFadeFactor,0.1);

return sum;

However I'm sure this is not the right way to achieve this effect, since it does create some depth artefacts when looking at the fog at lower heights and the fog is in front and behind of geometry. It looks fine when looking from above as in the screenshot.

But hopefully gives you an idea of what I'm trying to achieve.
No need to use sky haze or additional features, just a simple blend out.

Thanks

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 4662
    • View Profile
Re: Fog colour varying by depth
« Reply #5 on: June 10, 2019, 03:21:42 AM »
Try beta 2.
If you need to tweak it, the new shader code is around line 418:

Code
     // distance blending
     voidAlpha *= saturate(pow((_FogDistance.z - distanceToFog) / _FogDistance.w, 4));

Frozenempire

  • Full Member
  • ***
  • Posts: 183
    • View Profile
    • The Frozen Empire
Re: Fog colour varying by depth
« Reply #6 on: June 10, 2019, 03:41:58 AM »
Many thanks... will check it out tonight

Frozenempire

  • Full Member
  • ***
  • Posts: 183
    • View Profile
    • The Frozen Empire
Re: Fog colour varying by depth
« Reply #7 on: June 10, 2019, 02:21:16 PM »
Very very close...

Is there any way to make the fade independent of camera height ?

ie based on the xz distance between fog and camera

 

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 4662
    • View Profile
Re: Fog colour varying by depth
« Reply #8 on: June 10, 2019, 02:25:33 PM »
Replace distanceToFog by distance(wsCameraPos.xz, fogCeilingCut.xz).

Frozenempire

  • Full Member
  • ***
  • Posts: 183
    • View Profile
    • The Frozen Empire
Re: Fog colour varying by depth
« Reply #9 on: June 10, 2019, 02:40:30 PM »
Great, spot on!

I think I exhausted all my requests for the moment :)

Big thanks for your excellent responsive support.

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 4662
    • View Profile
Re: Fog colour varying by depth
« Reply #10 on: June 10, 2019, 03:04:34 PM »
Youíre welcome - thanks for helping making this asset better.