Search Unity

Fog Volume 3

Discussion in 'Assets and Asset Store' started by DavidMiranda, Jan 30, 2014.

  1. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,521
    I see, I'll turn off the 3D Noise for now.

    For subtraction I'm sure I can work some tricks to get something close, such as blending some fog values based on distance from a trigger at the entrance/exit of an interior.

    Thanks for the feedback. =)
     
  2. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    The issue has been localized. I have to move certain stuff to the CPU because there are many shader combinations. Stay tuned and sorry for the inconveniences.
     
  3. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    Thanks for the report. The issue when duplicating the Fog Volume has been solved and will be available in the next update. Vertical grad is in the TODO list. Cheers.
     
  4. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    Hey David_MG, I'm working on a Night/Day Cycle and I'm trying to modify fog volume through script. I have tons of values my night/day component tracks so I've made a GUI for making references to values in the scene. My issue is that the FogVolume shader is special in that ShaderUtil.GetPropertyCount() return 0. Could it be because its a hidden shader? How do I make it not hidden? I haven't been able to figure it out. My script can also control other script but FogVolume.cs has all private variables.
     
  5. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    try replacing [SerializeField] with public in the script. First link the Fog Volume to your script and then, modify Fog Volume Values. Good luck!
     
    djweinbaum likes this.
  6. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    Thanks David_MG. I was able to get inscattering color and fogcolor. This may be enough for now.
     
  7. JonDadley

    JonDadley

    Joined:
    Sep 2, 2013
    Posts:
    139
    EDIT: I figured out this problem. Turns out I had HDR turned on on the right eye camera but not on the left eye which was what was causing the issue. The inscattering looks great in VR.

    Hi David. I'm using the fog volume in my VR project and it looks *amazing* - however there seems to be an issue with inscattering. For some reason the inscattering colour effect only seems to be being rendered in the right eye. It's a shame because the inscattering colour really adds a lot but in this state it is unusable. I've added a screenshot below.

    inscattering.PNG
     
    Last edited: Jul 9, 2014
  8. dreasgrech

    dreasgrech

    Joined:
    Feb 9, 2013
    Posts:
    205
    Hi David,
    What would be the best way how to apply the FogVolume plugin on a terrain that has houses in which the player can enter?

    My issue is of course that although I want the fog to appear outside, I don't want it to appear inside a house.

    The two methods I can currently think of doing at the moment are either somehow hiding the fog when the player is inside a house but that is not trivial since if the player is inside a house looking out, he needs to see the fog outside but not inside. I'm not quite sure how it can be done that way.

    The other way I guess would be to segment the big FogVolume object into multiple FogVolume objects but I'm afraid that won't do too well in terms of performance and it would require quite high maintenance segmenting the fog for each map.

    What are your thoughts on this?
     
  9. aegget_

    aegget_

    Joined:
    Oct 30, 2012
    Posts:
    33
    Hello there :) I just bought fog volume and I was wondering is it possible to get a softer edge/transition on the fog? I use the fog volume as ground fog and I get this semi hard edge at a distance. Would love, if possible, to be able to get that transition to be smoother. Thanks!
     
  10. bmccall1

    bmccall1

    Joined:
    Jul 28, 2013
    Posts:
    120
    I have a question. Is it possible to tween the fog visibility, or would I need to modify some of your code to do that?

    IE: If I want to fly into a planet, and I want to go from little to no atmosphere, to heavy dense atmosphere, could I tween those values over time?
     
  11. dreasgrech

    dreasgrech

    Joined:
    Feb 9, 2013
    Posts:
    205

    To simulate weather transitions with the fog, I lerped over the Fog Volume's FogColor property.

    Here are some snippets from my code:
    Code (CSharp):
    1. Color FogColor { get { return fogVolume.FogColor; } set { fogVolume.FogColor = value; } }
    2.  
    3. void ApplyFogProperties(FogProperties fogProperties, float transitionTime)
    4. {
    5.     // Check if we need to enable fog for this new weather
    6.     if (fogProperties.FogEnabled)
    7.     {
    8.        fogVolume.gameObject.SetActive(true);
    9.  
    10.        // Check if fog's already enabled for our current weather
    11.        if (FogColor.a == 0)
    12.        {
    13.         // Fog is currently not enabled, so we need to transition into it
    14.         StartCoroutine(Interpolate(FogColor.a, 1, transitionTime, Mathf.Lerp, v => { FogColor = FogColor.ChangeAlpha(v); }));
    15.        }
    16.  
    17.        // Transition-in the visibility of the fog
    18.        StartCoroutine(Interpolate(fogVolume.Visibility, fogProperties.Visibility, transitionTime, Mathf.Lerp, v => { fogVolume.Visibility = v; }));
    19.     } else
    20.     {
    21.        //// We need to disable the fog according to the new weather
    22.  
    23.        // Check if fog is enabled for the current weather
    24.        if (FogColor.a > 0)
    25.        {
    26.         // Fog is currently enabled, so we need to transition out of it
    27.         StartCoroutine(Interpolate(FogColor.a, 0, transitionTime, Mathf.Lerp, v => { FogColor = FogColor.ChangeAlpha(v); },() =>
    28.         {
    29.            fogVolume.gameObject.SetActive(false);
    30.         }));
    31.        }
    32.     }
    33. }

    And these are the two helper methods that I make use of in the above snippet:
    Code (CSharp):
    1. static IEnumerator Interpolate<T>(T start, T end, float time, Func<T, T, float, T> interpolate, Action<T> step, Action callback = null)
    2. {
    3.     float i = 0.0f, rate = (float) (1.0/time);
    4.     while (i < 1.0)
    5.     {
    6.        i += Time.deltaTime*rate;
    7.        step(interpolate(start, end, i));
    8.        yield return null;
    9.     }
    10.  
    11.     if (callback != null)
    12.     {
    13.        callback();
    14.     }
    15. }
    16.  
    17. static Color ChangeAlpha(this Color color, float alpha)
    18. {
    19.     return new Color(color.r, color.g, color.b, alpha);
    20. }
     
    Last edited: Jul 31, 2014
  12. bmccall1

    bmccall1

    Joined:
    Jul 28, 2013
    Posts:
    120
    Fantastic. Thanks much!
     
  13. HassanS

    HassanS

    Joined:
    May 31, 2013
    Posts:
    4
    Hi David,
    I have problem with the fog renders behind my objects.
    The floor in the picture is a diffuse material.
    It worked when I choose Sprite/diffuse but then I must pay attention to sortingOrders.
    There most be some other way around?

    Thanks on forehand // Gustaf
     
  14. aegget_

    aegget_

    Joined:
    Oct 30, 2012
    Posts:
    33
    Hi, I'm having some problem with fog volume. I get these warning messages after
    upgrading to Unity 4.5.2 and after including the fog volume as a child object in a prefab

    NullReferenceException: Object reference not set to an instance of an object
    FogVolume.OnEnable () (at Assets/FogVolume/FogVolume.cs:78)
    refering to: Camera.main.depthTextureMode |= DepthTextureMode.Depth;
     
  15. dreasgrech

    dreasgrech

    Joined:
    Feb 9, 2013
    Posts:
    205
    Make sure your camera is tagged as "MainCamera"; otherwise, Camera.main will return null.
     
  16. aegget_

    aegget_

    Joined:
    Oct 30, 2012
    Posts:
    33
    Yeah that's what I guessed. The player camera is set to main but noticed after I went over it all again that because I instantiate the player there is no main camera on level start so that's what caused the error messages. Now fixed! Thanks
     
  17. HassanS

    HassanS

    Joined:
    May 31, 2013
    Posts:
    4
    Anyone know how to fix my problem above?

    thanks.
     
  18. Mordakie

    Mordakie

    Joined:
    Apr 17, 2013
    Posts:
    13
    As soon as I press play the fog volume disappears. I've tried everything I could think of to fix it, but to no avail. The only other thing I could think of is maybe the fog shader doesn't support Skyshop?
     
  19. Skyfly

    Skyfly

    Joined:
    Jan 25, 2014
    Posts:
    110
    Any guess, when you can upload the fix for the VR render issue (seams along objects on one cam)?
     
  20. mittense

    mittense

    Joined:
    Jul 25, 2013
    Posts:
    168
    Does this still not work on mobile as noted in the OP?
     
  21. ErnstS

    ErnstS

    Joined:
    Aug 6, 2014
    Posts:
    1
    Bought your FogVolume from the Asset Store, very good asset by the way.
    But i have a problem. When i import your package in a new Project
    everything is fine as expected. But when i import it in my current project
    the noise effect doesn't work. Is there maybe something that could disturb the
    fogVolume to render the Noise Effect? I tried to reimport, doesn't work
    either.

    We are using Unity Pro 4.6.0b9

    Empty Project:

    MyProject but a New Scene


    My Project in Game Scene
     
  22. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    Hi guys,
    Sorry for not being active. I'll upload a new version soon. OculusVR seems to work fine. Copy-paste will be supported, shader variants warning won't appear anymore, and ErnstS, noise will work only #if SHADER_API_D3D11 || SHADER_API_OPENGL

    2014-10-01_18-34-54.jpg

    mittense, that's my next task, ill check if everything is fine for mobile.
     
  23. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    Vertical Gradient is currently done. It will read the data from a tiny texture. RGB for colors and A for opacity :)

    It'll be available for v1.09 soon.

    2014-10-02_17-18-36.jpg
     

    Attached Files:

  24. chronosapien

    chronosapien

    Joined:
    Feb 1, 2011
    Posts:
    73
    Looking great. When should I update the package?
     
  25. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    I can confirm it's working now on Windows, OSX and iOS, it will be available soon. I have updated the web player demo in case you want to check how it will look with the new feature: gradients. I have also recorded a video.

     
  26. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    It's ready now
     
  27. JohnRossitter

    JohnRossitter

    Joined:
    Dec 18, 2013
    Posts:
    1,027
    Edited:
    I just tried disableing some plugins and I see what the issue is.
    It will not work with Skyshop Skies.
    If I disable my global sky manager, it works fine.

    Hi David,

    Just purchased Fog Volume and looks great but am having a bit of a problem.
    It works fine in my editor in both scene and game view, but when I go into play mode, it stops working.
    This happens when I build as well.

    My setup is:
    Macbook Pro, Mavericks, NVidia GeForce GT 650M
    Unity Pro 4.5.4
    Alloy Shader (Standard Base Bump shader) and Skyshop IBL

    Thanks,
    John
     
    Last edited: Oct 12, 2014
  28. dreasgrech

    dreasgrech

    Joined:
    Feb 9, 2013
    Posts:
    205
    Hi David,
    What would be the best way how to apply the FogVolume plugin on a terrain that has houses in which the player can enter?

    My issue is of course that although I want the fog to appear outside, I don't want it to appear inside a house.

    The two methods I can currently think of doing at the moment are either somehow hiding the fog when the player is inside a house but that is not trivial since if the player is inside a house looking out, he needs to see the fog outside but not inside. I'm not quite sure how it can be done that way.

    The other way I guess would be to segment the big FogVolume object into multiple FogVolume objects but I'm afraid that won't do too well in terms of performance and it would require quite high maintenance segmenting the fog for each map.

    What are your thoughts on this?
     
  29. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    Yeah, I totally understand that need. I think I have a solution, at least in theory. You will have to wait until I finish some other vital things like finding a new and peaceful place to live, hehe. In the best scenary, you will have a solution within 2 months.
     
  30. Fishypants

    Fishypants

    Joined:
    Jan 25, 2009
    Posts:
    444
    Hey David,
    So I am getting this error message when trying to create a Fog Volume:

    Shader error in 'Hidden/FogVolume': GLSL vertex shader: 388: ERROR: 'SAMPLE_DEPTH_TEXTURE' : no
    matching overloaded function found at line 267


    And I am assuming because of this error, the fog box is pink / doesn't show the fog. I'm on Unity 4.3. Any idea what could be causing it?
     
  31. chilton

    chilton

    Joined:
    May 6, 2008
    Posts:
    564
    First off, awesome asset.

    I'm curious if there's a way to add particulates to the fog volume. This is for an underwater game, and the dark areas (noise) would be perfect if they were actually lighter instead of darker. I intentionally made the fog brighter so you can see the darker areas here.
    Any suggestions?

    -Chilton
     

    Attached Files:

  32. Skorpiuz

    Skorpiuz

    Joined:
    Jul 17, 2014
    Posts:
    2
    Hi David. Thanks for this great asset.
    I am having difficulties applying "3D noise" I don´t see any :/ . Is there a chance that you publish a demo-scene with in scattering and 3D noise applied so we can see it as example? Thanks!
     
  33. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    There is a demo
     
  34. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    Hey guys, are you having problems with 4.5.5?
     
  35. JohnRossitter

    JohnRossitter

    Joined:
    Dec 18, 2013
    Posts:
    1,027
    David,

    Can you assist me in the best approach to use fog volume to make realistic breath effects in a sci-fi level?
    I have tried all sorts of things with fog volume, but just cant seem to get it right.
    I want the fog to emit away from my character in a cone shape
     
  36. robert-nally

    robert-nally

    Joined:
    Mar 5, 2014
    Posts:
    76
    Hola,

    I seem to be having an issue with the fog volume in the Rift. I have the volume working in classical, standard fps mode.

    I've had the fog volume working with the Rift in the past so I think this issue might be related to the new or newer Oculus SDK that has come out. They changed the way their controller/viewer/camera rig is setup as compared to older sdk's/controllers/viewers in the past where I had the fog volume working. I'm not 100% sure this is the case, but it is my suspicion.

    So, I'm using the Oculus SDK v. 4.3 and Unity Pro v. 4.6

    I just saw a new Oculus SDK came out like 4 days ago so I will try that, but here are my issues below in the event they aren't related and perhaps someone can help me fix the issues I'm having.

    see fog issue 2 - I get this cutout that sticks to the camera/head/eyes of the player and it's the fog and it is cutout in a shape of whatever geometry there is when the game starts. For this issue I have the top level camera set to main. The individual eyes and center eye underneath it are untagged.

    If I don't tag something as main camera I get a recurring error about - see fog issue 3. So I get that I have to tag something as main camera and I saw that you were calling that a lot in the code.

    When I try and tag one of the eye cameras as main camera I get - see fog issue 8. That stencil effect is recurring on the left eye (tagged as main camera). The right eye is perfectly fine though. Also, this issue isn't as noticeable or problematic as fog issue 2. Check this out - see fog issue 7. Here I have main camera on the right eye. If you stay still the stencil issue is not immediately or badly apparent but if you can get close to objects you can tell something is off. Also when you move your head, the issue becomes more apparent like in fog issue 8. It's like there is a short lag and you can see it more when moving your head.

    Has anyone encountered this? Fixed this? Dealt with this? What are people tagging as Main Camera?
     

    Attached Files:

  37. stationx

    stationx

    Joined:
    Jul 9, 2012
    Posts:
    251
    is this a joke? The web player is a huge terrain and there is absolute no volume fog visible...
     
  38. stationx

    stationx

    Joined:
    Jul 9, 2012
    Posts:
    251

    Hello Robert,
    did you ever got to fix this? My fog doesn't even show up in the rift at all.
    Regards! Tom
     
  39. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    Im sorry, but the asset is not meant for that purpose
     
  40. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    Atmosphere and clouds are made with Fog Volume, no joke.
     
  41. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    Hola,
    Can you stay using the older version of Oculus? Maybe we should wait and see if this is caused by an error from them
     
  42. K0m1x

    K0m1x

    Joined:
    Aug 19, 2013
    Posts:
    30
    I have the same problem the other people who wanted to use marmoset skyshop. any chance you ll add skyshop support? otherwise I wont be able to use this asset and wasted 20€
     
  43. stationx

    stationx

    Joined:
    Jul 9, 2012
    Posts:
    251
    I have issues with the oculus too. Staying with a previous version is an absolute no-go.
     
  44. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    Ok, works now with Oculus. I was accessing to the camera by calling the tag "MainCamera". But of course that isn't a must in every case. What I did was just forcing the camera to create the depth texture. This is needed when rendering in forward. This can be done in any other place. ShaderForge includes a script to make this (EnableCameraDepthInForward). You can use it. Anyway, I have included a new field in the Fog interface to add your camera (if you need it to do the job in forward). In any case, here is Oculus 4.3 in Unity 4.5.5
    2014-11-24_13-05-21.jpg

    And about Skyshop, it works for me.

    2014-11-24_12-07-06.jpg

    I'll upload it now.
     
  45. K0m1x

    K0m1x

    Joined:
    Aug 19, 2013
    Posts:
    30
    is that the skybox in the background? it's mostly the skyshop sky that causes the fog to be invisible.
     
  46. K0m1x

    K0m1x

    Joined:
    Aug 19, 2013
    Posts:
    30
    also is there a way you can make the fog work thru the water surfaces? cause if looking thru a water it seems the fog isn't even there
     
  47. K0m1x

    K0m1x

    Joined:
    Aug 19, 2013
    Posts:
    30
    maybe you re using the old version of marmoset, they made changes to the skybox ... the skymanager
     
  48. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    Im using the latest one.
     
  49. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    Sure, just tweak the draw order.
    2014-11-26_23-06-30.jpg
     
  50. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    How are you doing with this? I use to check it works with the latest version of Unity, with no errors nor warnings. Its pretty hard to assure it will work in older ones.