Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Screen Space Multiple Scattering

Discussion in 'Works In Progress' started by OCASM, Dec 17, 2016.

  1. carlotta89

    carlotta89

    Joined:
    Dec 19, 2017
    Posts:
    4
    Hei, do you have an answer if it is compatible with LWRP?
     
  2. wetcircuit

    wetcircuit

    Joined:
    Jul 17, 2012
    Posts:
    1,234
    fwiw, there is a paid asset in the store with this effect that works with post process stack 2.
    SC Post Effects Pack
     
  3. camta005

    camta005

    Joined:
    Dec 16, 2016
    Posts:
    283
    Edit: See next post!

    As mentioned a few times in this thread there is a memory leak when in scene view, but not in play mode or build.

    One solution is to turn off the effect in scene view:
    I had a good look at the problem. It's caused by the render texture fogRT being created over and over again in scene view. It has something to do with the scene view camera being used for render textures.

    In play mode or build or even just switching to the game tab, the problem stops.

    The best solution I could find is to clean up the excess render textures as needed.

    At the bottom of SSMSGlobalFog.cs look for:
    Code (CSharp):
    1. if (!saveFogRT && fogRT != null){
    2.     fogRT.Release ();
    3. }
    and replace it with:
    Code (CSharp):
    1. if (fogRT != null && !Application.IsPlaying(cam)){
    2.     fogRT.Release ();
    3. }
    This will clean up the extra render textures in scene view, while not un-necessarily releasing fogRT in play mode or build.
     
    Last edited: Dec 20, 2019
    akareactor, StevenPicard and OCASM like this.
  4. camta005

    camta005

    Joined:
    Dec 16, 2016
    Posts:
    283
    I managed to fix the leak, no need to use the previous solution (don't use both).

    In SSMSGlobalFog.cs look for:

    Code (CSharp):
    1. //Create a new fog render texture
    2. if (saveFogRT && (fogRT == null || fogRT.height < source.height || fogRT.width < source.width))
    3. {
    4.     fogRT = new RenderTexture (source.width, source.height, 0, RenderTextureFormat.Default);
    5. }
    6.  
    7. Camera cam = GetComponent<Camera>();
    and replace it with:

    Code (CSharp):
    1. Camera cam = GetComponent<Camera>();
    2.  
    3. //Create a new fog render texture
    4. if (!createdFogRT && saveFogRT && (fogRT == null || fogRT.height < source.height || fogRT.width < source.width))
    5. {
    6.     fogRT = new RenderTexture (source.width, source.height, 0, RenderTextureFormat.Default);
    7.     createdFogRT = !Application.IsPlaying(cam);
    8. }
    createdFogRT is used to check if fogRT has already been created for the scene view case. It will need to be declared somewhere at the beginning of the class:

    Code (CSharp):
    1. bool createdFogRT = false;
    From my testing the effect now works properly in scene view and play mode with no memory leaks and no extra clean up.
     
    Last edited: Dec 20, 2019
    OCASM, wetcircuit and zyzyx like this.
  5. AlexanderElert

    AlexanderElert

    Joined:
    May 31, 2017
    Posts:
    30
    One of my fav asset for unity!
    Any chance to get it work on WEBGL using URP on 2020?
     
  6. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    279
    If there are screen space fog and bloom effects working on URP WEBGL then I guess it's possible.
     
unityunity