Author Topic: Multiple fog of war layers  (Read 2773 times)

frozenempire

  • Full Member
  • ***
  • Posts: 233
    • View Profile
    • The Frozen Empire
Re: Multiple fog of war layers
« Reply #15 on: October 28, 2019, 12:06:13 AM »
Additional potential bugfix that was preventing darkening of fog under shadow
See what you think...

VolumetricFog.cginc

Code
#if FOG_SUN_SHADOWS_ON
...snip...
ng.rgb  *= lerp(1.0, shadowAtten, _VolumetricFogSunShadowsData.x * 0.9);       <== remove sum.a
fgCol.a *= lerp(1.0, shadowAtten, _VolumetricFogSunShadowsData.z );
...snip...
#endif
« Last Edit: October 28, 2019, 12:08:31 AM by Frozenempire »

frozenempire

  • Full Member
  • ***
  • Posts: 233
    • View Profile
    • The Frozen Empire
Re: Multiple fog of war layers
« Reply #16 on: October 28, 2019, 12:27:36 AM »
Final tweak which was needed to allow the directional light cookie to affect both fog instances (otherwise it was only affecting the main VFM instance)

VolumetricFog.cs

Quote
...snip...
            // [AS] set light matrix and other cookie params (moved from elsewhere)
#pragma warning disable 0162
#pragma warning disable 0429    // [AS]
            if (USE_DIRECTIONAL_LIGHT_COOKIE) {
                if (sunLight != null) {   // [AS]
                    lightMatrix = Matrix4x4.TRS(sunLight.gameObject.transform.position, sunLight.gameObject.transform.rotation, Vector3.one).inverse;   // [AS]
                    fogMat.SetMatrix("_VolumetricFogLightMatrix", lightMatrix);
                    fogMat.SetTexture("_VolumetricFogLightCookie", sunLight.cookie);   // [AS]
                }
            if (sunLight != null && sunLight.cookieSize > 0) {
               fogMat.SetFloat ("_VolumetricFogCookieSize", 1f / sunLight.cookieSize);
            }
            }
#pragma warning restore 0429    // [AS]
#pragma warning restore 0162
...snip...

The setting of the above params in 2 other places was commented out...

frozenempire

  • Full Member
  • ***
  • Posts: 233
    • View Profile
    • The Frozen Empire
Re: Multiple fog of war layers
« Reply #17 on: October 28, 2019, 12:32:55 AM »
With the above mods and tweaks, I now have 2 VFM instances each with their own Fog of War masks, and both being shadowed via unity directional shadows and light cookie...

Perfect solution and many thanks for your support ;)

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6642
    • View Profile
Re: Multiple fog of war layers
« Reply #18 on: October 28, 2019, 05:37:01 PM »
Cool. Glad you full-filled your requirements using Volumetric Fog & Mist.
I'll check your changes in case they can be included in a future update for sure!

I hope you can share some screenshots or footage of your project sometime in the future :)

Regards