Search Unity

Time of Day - Dynamic Sky Dome

Discussion in 'Assets and Asset Store' started by andererandre, Mar 4, 2013.

  1. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,808
    I seem to have this same problem. I can manually change the weather and cloud cover but then it seems to never change after that, even if I set everything on custom. Is there something we need to do to have random cloud and weather changes? I don't want to always have a cloudy sky. Thanks.

    Oh, and I realize weather is just a sky change, not particle effects. :)
     
  2. GXMark

    GXMark

    Joined:
    Oct 13, 2012
    Posts:
    421
    Any chance of Instance access on all the Components under Sky Dome not just TOD_Sky ?
     
  3. GXMark

    GXMark

    Joined:
    Oct 13, 2012
    Posts:
    421
    Did the shader incompatible issue between TOD and Suimono ever get fixed?
     
  4. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    680
    You have to randomize the weather state yourself. You assign the "Clouds" and "Weather" enums of TOD_Weather to a new one in certain intervals. Check out UnityEngine.Random in the Unity docs.

    This is already possible: TOD_Sky.Instance.Components.XXX, where XXX can for example be "Time" or "Weather".

    I changed the rendering order some sky dome components in 3.0.1 and 3.0.2 to be 100% in line with the Unity policies to ensure compatibility with as many other plugins as possible. This assures compatibility with plugins like Horizon[ON] and various third party water assets. I don't know if those changes fixed the compatibility issue with Suimono, but everything from this point on will have to be looked at by the author of Suimono.
     
  5. gbv30

    gbv30

    Joined:
    Apr 15, 2015
    Posts:
    11
    Hi,
    Any chance for beginners to have an example? Many thanks in any case.
     
  6. Arcanor

    Arcanor

    Joined:
    Nov 4, 2009
    Posts:
    264
    Here you go gbv30.

    Create a new C# script (call it anything you like, for example 'WeatherController.cs'), and put this function inside it. Create a new empty object and put it into your scene, and drag the script into it. Then drag your scene's Sky object into the public variable 'sky'. Then call the function SetRandomWeather() on your new object whenever you want to change the weather randomly.

    Code (CSharp):
    1.     public GameObject sky;
    2.  
    3.     public void SetRandomWeather()
    4.     {
    5.         TOD_Weather weather = sky.GetComponent<TOD_Weather>();
    6.  
    7.         // since there are 5 possible (non-custom) values of TOD_CloudType, pick an appropriate number:
    8.         int cloudSelection = Random.Range(1, 5);
    9.         switch (cloudSelection)
    10.         {
    11.             case 1:
    12.                 weather.Clouds = TOD_CloudType.Broken;
    13.                 break;
    14.             case 2:
    15.                 weather.Clouds = TOD_CloudType.Few;
    16.                 break;
    17.             case 3:
    18.                 weather.Clouds = TOD_CloudType.None;
    19.                 break;
    20.             case 4:
    21.                 weather.Clouds = TOD_CloudType.Overcast;
    22.                 break;
    23.             case 5:
    24.                 weather.Clouds = TOD_CloudType.Scattered;
    25.                 break;
    26.             default:
    27.                 Debug.LogWarning("Unknown random cloud type.");
    28.                 break;
    29.         }
    30.  
    31.         // since there are 4 possible (non-custom) values of TOD_WeatherType, pick an appropriate number:
    32.         int weatherSelection = Random.Range(1, 4);
    33.         switch (weatherSelection)
    34.         {
    35.             case 1:
    36.                 weather.Weather = TOD_WeatherType.Clear;
    37.                 break;
    38.             case 2:
    39.                 weather.Weather = TOD_WeatherType.Dust;
    40.                 break;
    41.             case 3:
    42.                 weather.Weather = TOD_WeatherType.Fog;
    43.                 break;
    44.             case 4:
    45.                 weather.Weather = TOD_WeatherType.Storm;
    46.                 break;
    47.             default:
    48.                 Debug.LogWarning("Unknown random weather type.");
    49.                 break;
    50.         }
    51.     }
    52.  
    I hope this helps.
     
    gbv30 and Whippets like this.
  7. gbv30

    gbv30

    Joined:
    Apr 15, 2015
    Posts:
    11
    Dear Arcanor,

    Many thanks for your help and script. That's great! I followed the several steps like you explained. If I place the SetRandomWeather() function in a start, it works. However, I don't understand how to call it once a day or on a periodical period in the day as sort to change the weather continuously. I tried this function below next to the others:

    Code (CSharp):
    1. void RenewWeather() {
    2.         InvokeRepeating("SetRandomWeather", 2, 3.0F);
    3.     }
     
    Last edited: Apr 17, 2015
  8. Arcanor

    Arcanor

    Joined:
    Nov 4, 2009
    Posts:
    264
    For something linked to your in-game time, you would use the events fired by ToD (after version 3.0). Here's a link to a prior post in this thread giving a (very short) example: http://forum.unity3d.com/threads/time-of-day-dynamic-sky-dome.172763/page-19#post-2016840

    So, if you wanted to change the weather at 11am every game day, let's say, you might do something like this (in C#) :
    Code (CSharp):
    1.     private void Start()
    2.     {
    3.         TOD_Sky.Instance.Components.Time.OnHour += OnHourHandler;
    4.     }
    5.  
    6.     private void OnHourHandler()
    7.     {
    8.         if (Mathf.Approximately(TOD_Sky.Instance.Cycle.Hour, 11f))
    9.         {
    10.             SetRandomWeather();
    11.         }
    12.     }
    Make sure you update to a recent version of Time Of Day, after 3.0, or these events will not be implemented.

    Please note that I have not tested this code! There may be bugs, so use at your own risk. ;)
     
    gbv30 likes this.
  9. Black-Spirit

    Black-Spirit

    Joined:
    Sep 14, 2013
    Posts:
    56
    Cheers for this. Was wondering how to do this. Could also use it for my streetlights to turn at certain hours.

    Though, it does not seem to work. No errors, but nothing happens.
     
  10. Arcanor

    Arcanor

    Joined:
    Nov 4, 2009
    Posts:
    264
    If you want to test it more often, change from the above to something like this, which should trigger every minute:

    Code (CSharp):
    1.  private void Start()
    2.     {
    3.         TOD_Sky.Instance.Components.Time.OnMinute += OnMinuteHandler;
    4.     }
    5.     private void OnMinuteHandler()
    6.     {
    7.         YourLightsFunction();
    8.     }
     
    Black-Spirit likes this.
  11. DivergenceOnline

    DivergenceOnline

    Joined:
    Apr 19, 2015
    Posts:
    244
    No offense but that answer isn't going to cut it. ToD on the asset store said it worked with Unity 4, it didn't say "it partially works with Unity 4". The issue is that your scattering shader(s) conflict with unity's internal fog effects, so the only viable sollution is to either help us fix the problem, or issue refunds to those accounts that bought the product.

    In response to your last question; Enabling global fox in the main camera makes no visual change to anything, other than adding fog.
     
  12. Black-Spirit

    Black-Spirit

    Joined:
    Sep 14, 2013
    Posts:
    56
    This does work. From what I can replicate, if I use the below, using OnHour, or OnMinute

    if (Mathf.Approximately(TOD_Sky.Instance.Cycle.Hour, 11f))

    the script stops.
     
  13. Arcanor

    Arcanor

    Joined:
    Nov 4, 2009
    Posts:
    264
    That part is just a check to see if the Hour variable (which is a float) is equal to 11. It's possible your time is running so quickly that it never actually becomes exactly 11:00 in your game. In any case, it was just an example, and that bit wasn't a particularly important part of the code.
     
  14. Black-Spirit

    Black-Spirit

    Joined:
    Sep 14, 2013
    Posts:
    56
    Cheers for the reply.

    I have tried that, and patiently waiting with time set to 300, not once does any hour fall exactly :00 . Surely there must be a way to do this, but I cant figure it out. Lol, I don't know, my coding is priddy average.

    Can I set it so its between a range, like 20.1 - 20.8?
     
  15. Arcanor

    Arcanor

    Joined:
    Nov 4, 2009
    Posts:
    264
    Sure, it's just a float.
    Code (CSharp):
    1. if (TOD_Sky.Instance.Cycle.Hour > 20.1f && TOD_Sky.Instance.Cycle.Hour < 20.8f)
    2. {
    3.     DoSomething();
    4. }
     
  16. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    680
    First of all, the TOD_Scattering image effect has been added 2 updates ago as a free new feature for Unity 5 users. It's neither in the demo scene nor on any screenshots on the Asset Store. It's also by no means required to use Time of Day - it's entirely optional. What you're doing here is complain about something I provided for free to my Unity 5 customers. Now back to the technical background of this issue.

    I'd love to support Unity 4 in the TOD_Scattering image effect, but it's simply not possible. Let's look at the default Unity 4 global fog image effect together.

    Let's start with a simple test scene in Unity 4, the botton cube and the cube in the back are using the default opaque shader and the cube in the front is using the default transparent shader with an opacity of 1. Everything's rendering correctly.



    Now if I add the global fog image effect from the Unity 4 Standard Assets you can see that the transparent shader breaks since the fog renders after transparent objects.



    If I add "@ImageEffectOpaque" to the global fog image effect it renders correctly again. The transparent object just doesn't receive the global fog.



    However, if I move the transparent object behind any opaque object it'll still render in front of it. This means that all transparent objects will render in front of all opaque objects.



    This is exactly what happens with TOD_Scattering in Unity 4. You can either remove "[ImageEffectOpaque]" to have it incorrectly override transparent objects or leave it in and have all transparent objects render in front of all opaque objects. If you cannot live with either of those issues you'll have to upgrade to Unity 5 or use Time of Day without the TOD_Scattering image effect.
     
  17. gbv30

    gbv30

    Joined:
    Apr 15, 2015
    Posts:
    11
    Hello Arcanor,

    I try to use your function to update the weather each time the cycle is renewed. My TOD cycle lasts 10 minutes. I included a Debug.Log() to check if the function is triggered with the condition, but nothing happens.
    I included all the code in the same file (C#), the private Start and OnHourHandler are next to the setRandomWeather() function.
    Thank you for your help. I really would like to do that weather change.

     
  18. Arcanor

    Arcanor

    Joined:
    Nov 4, 2009
    Posts:
    264
    Try removing the "if" statement (take out the whole line). It seems that ToD isn't setting that value to exactly 11, so you'd need to use a wider value range.
     
  19. Black-Spirit

    Black-Spirit

    Joined:
    Sep 14, 2013
    Posts:
    56
    @Arcanor - Cheers for all the suggestions so far. Though none seem to have any impact on calling a event at a certain time(OnHour works, but cant narrow it done to a single hour daily.)

    @plzdiekthxbye - any ideas mate? must be something so simple.
     
  20. dempseyg

    dempseyg

    Joined:
    Oct 30, 2013
    Posts:
    4
    Hi, really enjoying TOD using both the older and newer version.

    Working with the previous build at the moment and I wondered does TOD account for Daylight Savings Time, I know it calls from the world.UTC time zone which is 0 for my country but it does not seem to account for DST - I have added a slider to control the TOD which works fine, but have noticed that the sunset can be off according to DST time. is this something that can be fixed or worked around ?
     
  21. Arcanor

    Arcanor

    Joined:
    Nov 4, 2009
    Posts:
    264
    @Black Spirit - I'd suggest adding a debug line to see exactly what the value is, given your specific time setup. Just put something like this in your OnHourHandler():

    Code (CSharp):
    1. Debug.Log("ToD says the hour is currently: " + TOD_Sky.Instance.Cycle.Hour);
     
    Black-Spirit likes this.
  22. Black-Spirit

    Black-Spirit

    Joined:
    Sep 14, 2013
    Posts:
    56
    aha, yes this works cheers!
     
  23. Arcanor

    Arcanor

    Joined:
    Nov 4, 2009
    Posts:
    264
    So tell us, what values are coming out?
     
  24. Black-Spirit

    Black-Spirit

    Joined:
    Sep 14, 2013
    Posts:
    56
    i reduced my day length to 30 minutes for a quick test, and tested the hours I was looking for.

    the below worked.

    Code (CSharp):
    1.  
    2.     private void OnHourLightOn()
    3.     {
    4.        
    5.         if (Mathf.Approximately (TOD_Sky.Instance.Cycle.Hour, 18.99987f)) {
    6.            
    7.             TowerLightOn();
    8.             Debug.Log("Light On");
    9.         }
    10.  
    11.     }
    12.  
    13.     private void OnHourLightOff()
    14.     {
    15.         if (Mathf.Approximately (TOD_Sky.Instance.Cycle.Hour, 19.9999f)) {
    16.            
    17.             TowerLightOff();
    18.             Debug.Log("Light Off");
    19.         }
    20.  
    21.     }
     
  25. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    680
    The TOD_Sky time property doesn't take DST into account to prevent having to jump forwards and backwards on the transitional days. DST / time zone transitions are borderline insane, so if you plan on doing them make sure to utilize the C# DateTime struct and only do so when displaying the time to the user, not for internal time measurements. DateTime stores a ton of DST and time zone related info, including historical time zone changes of certain countries.
     
    hopeful likes this.
  26. dempseyg

    dempseyg

    Joined:
    Oct 30, 2013
    Posts:
    4

    Thanks for the reply - We've been discussing it and think that we may be able to display the time +- one hour on the slider based on the time of year/month Hopefully this will solve the function we need, it does sound complicated talking with the other coders in the office. Thanks again.
     
  27. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    680
    A quick update on the development of Time of Day: I'm planning to release 3.1.0 with a number of major changes in the near future.

    I was finally able to find enough time to implement support for real-life star constellations with a visual quality on par with the Crysis and Arma game series. Time of Day will ship with data for over 9000 stars that can be seen from Earth. You can also feed it custom star data if you prefer that - all you need is a text file with right ascension, declination and magnitude of the stars you want to use.

    The second big improvement will be a revamped cloud system that I'm currently working on. This means cloud layers will finally be volumetric and their new shading uses physically based scattering equations. The way I'm tracing their density is highly efficient and comes with extremely fast fallbacks for very old mobile devices. I also converted cloud shadows to an image effect with vastly superior performance over the previously used Unity projector.

    As always you can look forward to various other tweaks and adjustments, but I won't go into more details for now.
     
    Sir-Spunky, elbows, OnePxl and 8 others like this.
  28. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,001
    I have a question
    Should we add a directional light to scene or Time of Day has it owns?
     
  29. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    680
    Time of Day has its own light source on the "Light" child object. You can adjust all parameters of the light source directly on the object except for the light intensity and color, which depend on the time of day and therefore have to be adjusted on the TOD_Sky script.
     
  30. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    680
    Must be a configuration issue. Try an empty scene with just the sky dome and add some objects to it to see if they're correctly lit. If that's not the case, try a full reimport (delete Time of Day folder, restart Unity, reimport Time of Day). Also make sure static lightmapping is disabled in your scene lighting settings if you're using a dynamic day / night cycle.
     
    ksam2 likes this.
  31. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,001
    Sorry, my mistake. I have one more question is there any parameter for "Exposure"?
    In the Usky there was a exposure parameter that was really handy
     
  32. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    680
    Yes, use Atmosphere.Brightness / Atmosphere.Contrast for this.
     
    ksam2 likes this.
  33. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,001
    I have one more question. Why you set Directional light on "Mixed" and not "Realtime"? What's the difference?
    Thanks.
     
  34. Aurecon_Unity

    Aurecon_Unity

    Joined:
    Jul 6, 2011
    Posts:
    237
    I'd love to use the SE Natural Bloom Dirty Lens plugin in conjunction with Time of Day. Problem is I'm not too sure how it works - it seems to scale the strength of the bloom from the brightest material in the scene. Is there any way to introduce a self illumination slider into the sun shader? Currently the plugin applies bloom equally across the entire sky, whereas I have a feeling if we could crank up the brightness of the sun shader it would then only apply the bloom to the sun object.

    The reason I think this is that I created a text scene with just a ToD sky, and it applied bloom evenly across the sky. But if I added a sphere with the SE Natural Bloom self illumination shader and cranked up the brightness, the bloom would then only apply to the sphere and not the sky anymore.

    I realise I'm not making this easy :p, but I guess what I'm asking is have you thought about being able to manipulate the illumination strength of the sun shader to work nicely with bloom type image effects?
     
  35. NorthernVisionStudio

    NorthernVisionStudio

    Joined:
    Oct 18, 2013
    Posts:
    60
    First, I'd like to say that this plugin is outstanding. A pleasure to work with and beautiful results.

    Two things for this post:

    1. I notice that when I undo a color ramp change, it doesn't update the Editor UI. To see the reversion, I must deselect and re-select the Sky Dome.

    2. How can I receive notice about your update to the stars and cloud subsystem? Those are exactly the features I was needing. Are they included for current customers as an Asset Store update?

    Thank you!
     
  36. Mogulbasher

    Mogulbasher

    Joined:
    Feb 26, 2014
    Posts:
    11
    Many thanks for this plugin, I have a quick question if I may

    If I want to programatically change the Rayleigh Multiplier based on cloud cover how would I do that.
     
  37. huynhke

    huynhke

    Joined:
    Jul 9, 2014
    Posts:
    15
    So i've been trying some things out and looking around but I can't seem to find a way to make my distance fog match the shifting TOD. The project we're working on shifts through TOD over a span of years, our distance fog does change when it becomes day and becomes night, but the colors of the skybox change and lerp so much that I can't seem to find a way to make the fog ALWAYS match the skybox. Is there something that i'm missing in the tools??
     
  38. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    680
    It's simply set to the default setting, which is "mixed", i.e. both static and dynamic lightmapping is enabled. For more details see the Unity docs.

    Increase Sun.MeshBrightness and Moon.MeshBrightness to make sure most bloom is coming from those objects. Also make sure HDR is enabled and your tonemapping image effect is applied after the bloom image effect. From that point on it's just a matter of tweaking the parameters. If you want a cutoff value for the bloom in the way classic bloom effects were using it you'll have to contact the author of the "SE Natural Bloom Dirty Lens" plugin.

    That's easy: TOD_Sky.Instance.Atmosphere.RayleighMultiplier.

    Are you using the default Unity fog? That will never perfectly match the sky dome as it's using a constant color for the entire scene. Setting Fog.Mode on the sky dome to directional is the best approximation you can get with a single global fog color. For better results you'll have to use per-pixel fog - check out the TOD_Scattering image effect.
     
  39. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    335
    Hi, I am new to ToD and like it a lot! :)

    Anyway, I have a problem with ToD_Scattering and unity tree billboards which simply are not affected by the scattering effect. I assume it is render queue problem, hope it can be fixed easily?!
     

    Attached Files:

  40. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    680
    That's sadly a limitation of the Unity 4 tree billboards and cannot be fixed on my end. You can either get hacky and manually make the tree billboards write to depth or switch to SpeedTree trees, which are supported in Unity 5 or later and don't have this issue. If you can't do either of those things you won't be able to use the TOD_Scattering image effect in your project and will have to use the good old Unity fog, which of course is also supported by Time of Day.
     
  41. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    335
    That's too bad! Could you please describe the hacky manually way? How can I make them write to depth (using Unity 5) / which render queue number is needed? I plan to use AFS tree billboard shader...
     
    Last edited: Apr 29, 2015
  42. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    680
    You are correct that you need billboards that write to depth, but please understand that I can't help you with finding a suitable shader or implementing it. There just aren't enough hours in a day for me to help people with their custom shaders in such a detailed manner - all I can do is to point you in the right direction.
     
  43. huynhke

    huynhke

    Joined:
    Jul 9, 2014
    Posts:
    15
    Is there an example scene that we can access somewhere? Or maybe it's just a simple answer -- I can't find instructions for applying the TOD_Scattering, so I attached it to the camera but it makes my scene look wrong.

    Here's an image of what I started with, and the 2nd image is what it became after I added TOD_Scattering to the camera.
    ScatteringPhoto.jpg
     
  44. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    335
    Fortunately larsbertram1 (developer of AdvancedFoliageShader) could help me out here with a modified tree billboard shader. It works great! If someone has problems with ToD scattering and Unity tree billboards, just get AdvancedFoliageShader4!

    AFS_billboard_ToD.jpg
    AFS_billboard_ToD2.jpg
     
  45. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    680
    This is because the current preview version of TOD_Scattering forces HDR output on your sky, so you have to use it together with tonemapping (see the Unity standard assets). The final version of TOD_Scattering, which will be part of the 3.1.0 update, will also support LDR output. I'll also add more information on it to the docs as soon as the image effect is final.

    This is great news! I might even add it to the FAQ section of the docs.
     
    Olander and Tethys like this.
  46. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,045
    I wrote about the shimmering on the previous page. I'm not using reflection probes, so that's not the cause (I assume).

    Weirdly, it does not occur on Macs, but does consistently on Windows -- all sorts of Windows computers, with both integrated and decent dedicated graphics cards. I've got a screen cap video showing it -- I'll pm you the link (project is not public yet).

    thanks
    Dave
     
  47. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    680
    First thing that comes to mind are cloud shadows. Cloud shadows are broken right now and will be replaced with a new, higher performance system in 3.1.0 - do you have cloud shadows enabled by any chance?

    If that's not it, can you disable individual sky dome child objects to check which one causes this? It could be self-shadowing artifacts, in which case toggling the light object would fix it - in that case what you probably want to do is adjust your shadow bias property on the light component. If that' not it - are you using TOD_Scattering or TOD_Rays? Does it disappear when you remove either of those?
     
  48. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,045
    Thanks for the tips. Where do I disable cloud shadows? In the "Clouds" section of the main inspector, "Shadow Strength" is zero -- is that it, or is there a toggle somewhere? Ah, is it "Projector"? The Projector component is toggled off on the Projector object.

    Since I can't repro the problem on my Mac, I have to do a Windows build and move it to another computer for testing -- so I can't toggle anything at runtime. What would I toggle off to remove possible self-shadowing artifacts? And where do I see if I'm using TOD_Scattering or _Rays? (I'm mainly using the stock Sky Dome prefab, with tweaks only to the lighting levels.)
     
  49. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    680
    In that case you're not using cloud shadows.

    If toggling shadow casting in either the project or on the light child object of the sky dome it's very likely the issue is caused by self-shadowing artifacts. To fix it tweak the shadow bias parameter on the light child object of the sky dome. Start with a very high value and see if that fixes the issue, then slowly dial it back. This isn't really related to Time of Day at all - all of the light properties are from Unity - so you'll find a good deal of information about this on the forums and in the manual.

    If you haven't added those components to your camera you're not using them - they're not added automatically.
     
  50. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    975
    For some reason A and D are controlling the cycle/hour. Is this possible? I certainly didn't set that up. Could a conflict with another asset be controlling this? Thanks.
     
unityunity