Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. 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

Time of Day - Dynamic Sky Dome

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

  1. PanicEnsues

    PanicEnsues

    Joined:
    Jul 17, 2014
    Posts:
    132
    That gradient lets you set the light color based on where the sun is in the sky; left side is when it's at its zenith (noon), right side is when it's at the horizon (sunrise/sunset).
    So with the default gradient, it should be tinting the ground yellow when the sun is very low on the horizon, and leaving the ground at its texture color when the sun is all the way up.

    You can certainly adjust the gradient, but if you want things to look at least somewhat realistic, you should keep at least some color gradient.

    I don't think there's a way to change that color directly through code (TOD_Sky.LightColor is read-only), but you shouldn't change it directly through code anyways since it's always changing itself as time progresses.
     
  2. DreamerYinYu

    DreamerYinYu

    Joined:
    Apr 14, 2018
    Posts:
    21
    OK,Thank you very much
     
  3. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    66
    Also note that if your ground texture is from a photograph, it will include the colour of the sunlight at the time of capture - so it would be good to adjust the white balance of your ground textures to remove any colouring from the sun.
     
  4. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    66
    @andererandre It's my understanding that Rust is working on HDRP, can you give any kind of estimate when TOD will be updated? We want to move to HDRP asap so if it's going to be multiple months then we'll probably just trying porting it ourselves...
     
  5. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,018
    Great looking system, very powerful indeed. The question I have is it possible to have the system generate a Unity skybox from the settings at the start and then apply those light and skybox settings and have the rest of the system turned off. I would love to be able to have the correct time of day lighting and cloud when the player starts my game but I don't need any of the overhead of realtime changes to any of the settings or the extra processing to render the sky dome.
     
  6. PanicEnsues

    PanicEnsues

    Joined:
    Jul 17, 2014
    Posts:
    132
    Looking at the code, it appears that even if you turn off time advancing, all of the Update calls will still happen every frame.

    That said, the full source code is included, so it would be very easy to go to TOD_Sky.cs/LateUpdate() and comment out or if-wrap all of the update calls.

    -Scott
     
  7. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    66
    I'm trying to update our integration of TOD with global post processing volumes, has anyone tried this?
    I have an "underwater" global volume that I need to blend fog with the day/night fog of TOD. This seems complicated as TOD is driving the global fog directly. Has anyone worked around this?
     
  8. unity_cH5CKv09zTBfWA

    unity_cH5CKv09zTBfWA

    Joined:
    Feb 23, 2020
    Posts:
    3
    Hi,

    I want to implement a milky way that is in sync with sky rotation ? Anybody had implemented this ? Also I have some other questions:

    1 - The sky is very blue and bright near horizon. I want a more black night from zenith to horizon. No matter how I adjust sky and illumination it stays blue and bright. Any hint ?

    2 - I want to create a fixed brightness near horizon simulating the lights of a city far away. Is there any texture that I can edit ?

    Thanks
     
  9. Salvador-Romero

    Salvador-Romero

    Joined:
    Jan 21, 2014
    Posts:
    51
    Hi!
    0.- Have a look at the object 'space'. It is there for that purpose. It rotates with the sky.
    1.- In the object Sky Dome, the 'Day' and 'Night' sections have some gradients to control that. In the middle of the night with no moon you should have a very dark sky with default values, anyway. Perhaps try to change the hour of the day and see how this works for you, then edit the gradients. On sunset and sunrise night and day gradients mix.
    2. Have a look to the Billboards object, although they might rotate if there is wind. Other than that, no, you just have to do that yourself.

    Cheers!
     
  10. unity_cH5CKv09zTBfWA

    unity_cH5CKv09zTBfWA

    Joined:
    Feb 23, 2020
    Posts:
    3
    Many Thanks Salvador

    Ive played with gradients but never got a near horizon black sky. I'll try it again
     
  11. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,063
    Shame this asset isn't updated anymore. Really would like to use it with URP. :(
     
  12. XyrisKenn

    XyrisKenn

    Joined:
    Dec 8, 2015
    Posts:
    38
    Likewise - it's the only sky system I want to use but now HDRP is out of beta.
     
  13. Mehrdad995

    Mehrdad995

    Joined:
    Jul 17, 2013
    Posts:
    42
    Greetings,
    Thanks for developing such a great asset however there's an issue with the Sunset/Sunrise timing.
    Set blow values for "world" and you can see sunrise triggers at 1 AM whereas it shouldn't be triggered at least until ~6
    Sunset too triggers wrongly at 16 which should happen around 20 as it's visually still very bright and day.
    Apparently it doesn't take UTC into account at all :/

    Latitude: 35.74924
    Longitude: 51.37173
    UTC: 3.5
     
  14. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,063
    I've switched over to Enviro & I find it's far better than this. Check it out guys if you need to make progress in your game.
     
  15. PanicEnsues

    PanicEnsues

    Joined:
    Jul 17, 2014
    Posts:
    132
    Thanks! Can you give some examples of how it's better and what you like about it?
     
    Salvador-Romero likes this.
  16. ikriz

    ikriz

    Joined:
    Dec 3, 2009
    Posts:
    95
    Did you port this eventually, if so is the code public?
     
  17. eblumrich

    eblumrich

    Joined:
    Nov 12, 2015
    Posts:
    98
    Hi- I am thinking of getting Time Of Day, but I needed to know:

    Is it possible to add extra satellites/moons?
     
  18. TonyBlunder

    TonyBlunder

    Joined:
    Mar 9, 2020
    Posts:
    7
    Has anyone experienced the entire sky flickering/flashing randomly, or have any ideas what might cause that behavior? It's been hard for me to reproduce, but I've experienced it in both the Editor and a build.
     
  19. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    681
    HDRP is not yet usable for large scale projects from our experience. The biggest issue is performance, and some of it will have to be fixed by Unity. Until that's resolved it's difficult to justify the time it would take to upgrade to HDRP.

    Adding them positioned relative to the primary moon would be easy, since you could simply make them a child object of the primary moon and use the same moon shader. If they are supposed to move on their own orbit you would have to implement the additional orbit yourself (see UpdateCelestials method).

    I would start with a minimal project with just the sky dome in it, if the issue isn't happening there then it's most likely an image effect in your main project that's causing it.
     
    Salvador-Romero and SLGSimon like this.
  20. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    302
    I saw this is on sale but hasn't been updated in a while, are there any issues with URP?
     
  21. ikemen_blueD

    ikemen_blueD

    Joined:
    Jan 19, 2013
    Posts:
    320
    @andererandre can you support TOD_Rays, TOD_Scattering for URP? TOD_Sky mostly works fine with URP, but its visual reduces so much without TOD_Rays, TOD_Scattering. Many thanks.
     
  22. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    326
    Has anyone done street lights to work with this?
    I tried but could not figure out how to get the actuall current time so i can change the intensity of the lights for day and night time at the update function.
     
  23. PanicEnsues

    PanicEnsues

    Joined:
    Jul 17, 2014
    Posts:
    132
    Easiest way is to just hook into the TOD_Time's "OnSunrise" and "OnSunset" events, e.g.

    myTODTime.OnSunset += TurnOnStreetLights;
    myTODTime.OnSunrise += TurnOffStreetLights;

    Or if you want them to turn on/off at a specific hour, there's also an "OnHour" event.
     
    SLGSimon likes this.
  24. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    326
    I have no idea how to make it work with the events, maybe you could point me in the right direction?
    Code (csharp):
    1.  
    2. public class LightsDayNight : MonoBehaviour
    3. {
    4.     public List<Light> lights = new List<Light>();
    5.     public TOD_Time TODTime;
    6.     public bool needUpdate = false;
    7.     public float current = 0f;
    8.     float desired = 0f;
    9.     public float wantedDay = 0f;
    10.     public float wantedNight = 1f;
    11.     public float adjustRate = 2f;
    12.  
    13.     void Start()
    14.     {
    15.      
    16.     }
    17.  
    18.     void Update()
    19.     {
    20.         bool needUpdate = false;
    21.         if (current < desired)
    22.         {
    23.             needUpdate = true;
    24.             current += adjustRate * Time.deltaTime;
    25.             if (current > desired) current = desired;
    26.         }
    27.  
    28.         if (current > desired)
    29.         {
    30.             needUpdate = true;
    31.             current -= adjustRate * Time.deltaTime;
    32.             if (current < desired) current = desired;
    33.         }
    34.  
    35.         // now only update your lights if needUpdate is true!
    36.         if (needUpdate)
    37.         {
    38.             foreach (var L in lights) L.intensity = current;
    39.         }
    40.     }
    41.  
    42.     void Day()
    43.     {
    44.         desired = wantedDay;
    45.         needUpdate = true;
    46.     }
    47.  
    48.     void Night()
    49.     {
    50.         desired = wantedNight;
    51.         needUpdate = true;
    52.     }
    53. }
    54. [/CODE
    Edit:
    I realize that i need something in my script to check if these events are happening or not.
    But i think it would be easier to just check or sync with the time in TOD:Sky to trigger the "Day" and "Night" function in my script?
     
    Last edited: Oct 12, 2020
  25. PanicEnsues

    PanicEnsues

    Joined:
    Jul 17, 2014
    Posts:
    132
    Yes, you could easily hook up the events by adding two lines to its Start() method:

    TODTime.OnSunset += Night;
    TODTime.OnSunrise += Day;

    But I'm always looking for any way to remove Update() loops from my scripts (since they just eat cycles needlessly), so you could also do something like this, which has zero perfomance hit outside of the two-second fade twice a day:

    Code (CSharp):
    1.  
    2. public class LightsDayNight : MonoBehaviour
    3. {
    4.     public List<Light> lights = new List<Light>();
    5.     public TOD_Time TODTime;
    6.     public float adjustRate = 2f;
    7.  
    8.     void Start()
    9.     {
    10.         TODTime.OnSunset += Night;
    11.         TODTime.OnSunrise += Day;
    12.     }
    13.  
    14.     private IEnumerator iFadeLights(bool turnOn)
    15.     {
    16.         float endValue = 1f;
    17.         float value = 0f;
    18.         while (value < endValue)
    19.         {
    20.             value += adjustRate * Time.deltaTime;
    21.  
    22.             foreach (var L in lights)
    23.             {
    24.                 L.intensity = turnOn ? value : 1 - value;
    25.             }
    26.             yield return 0;
    27.         }
    28.     }
    29.  
    30.     void Day()
    31.     {
    32.         StartCoroutine(iFadeLights(false));
    33.     }
    34.  
    35.     void Night()
    36.     {
    37.         StartCoroutine(iFadeLights(true));
    38.     }
    39. }
     
  26. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    326
    I figure it out, but..there is always a but, i start at night at 00:00 and at 6 when the OnSunrise event is triggered the lights is still on, and at 18 the lights goes of and then on 1 sec after. After that everything is working fine for some reason.
    Is there anything in the code i have done wrong maybe?
    Code (csharp):
    1.  
    2.     public List<Light> bakedlights = new List<Light>();
    3.     public List<GameObject> realTimeLights;
    4.     public TOD_Time TODTime;
    5.     public bool needUpdate = false;
    6.     public float current = 0f;
    7.     float desired = 0f;
    8.     public float wantedDay = 0f;
    9.     public float wantedNight = 1f;
    10.     public float adjustRate = 2f;
    11.  
    12.     void Awake()
    13.     {
    14.         needUpdate = true;
    15.     }
    16.  
    17.     public void Update()
    18.     {
    19.         TODTime.OnSunrise += Day;
    20.         TODTime.OnSunset += Night;
    21.         needUpdate = false;
    22.         if (current < desired)
    23.         {
    24.             needUpdate = true;
    25.             current += adjustRate * Time.deltaTime;
    26.             if (current > desired) current = desired;
    27.         }
    28.  
    29.         if (current > desired)
    30.         {
    31.             needUpdate = true;
    32.             current -= adjustRate * Time.deltaTime;
    33.             if (current < desired) current = desired;
    34.         }
    35.  
    36.         // now only update your lights if needUpdate is true!
    37.         if (needUpdate)
    38.         {
    39.             foreach (var L in bakedlights) L.intensity = current;
    40.         }
    41.     }
    42.  
    43.     public void Day()
    44.     {
    45.         desired = wantedDay;
    46.         //needUpdate = true;
    47.         foreach (var obj in realTimeLights) obj.SetActive(false);
    48.     }
    49.  
    50.     public void Night()
    51.     {
    52.         desired = wantedNight;
    53.         //needUpdate = true;
    54.         foreach (var obj in realTimeLights) obj.SetActive(true);
    55.     }
    56. }
    57.  
     
  27. PanicEnsues

    PanicEnsues

    Joined:
    Jul 17, 2014
    Posts:
    132
    You can't connect to the events in your Update loop; "TODTime.OnSunrise += Day" is telling TODTime "hey, every time there is a sunrise, call "Day()". But if you do that from Update, you're telling TODTime that every frame. So once your game has been running for 10 seconds, come sunrise TODTime is going to call Day() 300 times.

    So just connect to the events once (usually in Start()) and they'll stay connected for as long as the game is running.
     
  28. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    326
    Thank you! i have fixed that dumb placement of the code xD
    But still, the other issue is still there, that at the first "morning" the lights doesnt goes off. Not a big problem, but a little anyoing.
     
  29. PanicEnsues

    PanicEnsues

    Joined:
    Jul 17, 2014
    Posts:
    132
    This is an edge-case bug, but I figure I'll report it in case it helps anyone else:

    If you manually advance TOD_Time's clock (via AddSeconds or AddHours), it will trigger OnSunrise() and OnSunset() events... But ONLY if the previous time was within the same 24-hour cycle as the new time.

    E.g., if the time is 03:00 and you add 5 hours (to make it 08:00), OnSunrise will trigger.
    But if the time is 23:00 and you add 9 hours (also to make it 08:00), OnSunrise will NOT trigger.

    So you'll need to either account for that elsewhere, or change TOD_Time's "AddHours" method (lines 152 & 157) to more accurately determine if the time change crosses a sunrise/sunset.

    -Scott
     
    Salvador-Romero likes this.
  30. gambr

    gambr

    Joined:
    Oct 13, 2017
    Posts:
    109
    I'm implementing a Floating Origin method in my project. In TOD_Camera script, attached to my main camera, I check the "Dome Pos To Camera" option to make sky dome following the main camera global position on every update. The problem is that the Floating Origin implementation translates the main camera to global origin when its position is greater than a fixed amount, and this makes clouds stutter on every main camera translation (please see attached video). What should I do to avoid the clouds stuttering?

    Regards,
    Gianni
     

    Attached Files:

    • tod.zip
      File size:
      21.8 KB
      Views:
      22
  31. PanicEnsues

    PanicEnsues

    Joined:
    Jul 17, 2014
    Posts:
    132
    I'm also using Floating Origin.

    The clouds use world-space UVs (which is how they stay in position while you move the dome). The shader has a CloudUV method that takes a Vector3 offset value, but it doesn't seem to do what I expected; passing it my world-shift offset didn't prevent the clouds from popping to a new position.

    But rather than finding a real solution, I stumbled by pure accident onto one that works for my project: If you offset your camera by close to 10,000m in x or z, the clouds don't pop. I'm assuming that just happens to line up with a wrap point in the texture.

    I don't know if that will work for you, but maybe it will help...

    -Scott
     
  32. gambr

    gambr

    Joined:
    Oct 13, 2017
    Posts:
    109
    Thanks Scott for the hint.
    Anyway, any idea from @andererandre?
     
  33. gambr

    gambr

    Joined:
    Oct 13, 2017
    Posts:
    109
    I modified the quoted code to make it usable with or without floating origin, by simply adding an offset variable. I used a DomePosOffset since it is already present in TOD_Camera. Unfortunately setting proper values in DomePosOffset of TOD_Camera didn't solve the problem. I don't know if there is a way to use the same DomePosOffset for TOD_Camera and TOD_Animation, this is a question for @andererandre, anyway this is the code that works fine if CameraMovement is 0 (default value is 1). When CameraMovement is 1 I see a clouds stuttering in one frame, then clouds are correctly placed in the following frame. Please look at the attached video.
    Any idea on how to fix the code to make it working also with CameraMovement = 1?

    Code (CSharp):
    1.  
    2. public Vector3 DomePosOffset = Vector3.zero;
    3. public Vector3 OffsetUV
    4.     {
    5.         get
    6.         {
    7.             var pos = (DomePosOffset + transform.position) * (CameraMovement * 1e-4f);
    8.             var rot = Quaternion.Euler(0, -transform.rotation.eulerAngles.y, 0);
    9.             return rot * pos;
    10.         }
    11.     }
    12.  
    Regards,
    Gianni
     

    Attached Files:

  34. gambr

    gambr

    Joined:
    Oct 13, 2017
    Posts:
    109
    Time of Day latest version has been released in 2018 but I can't see anything about that, right?
     
  35. qmqz

    qmqz

    Joined:
    Jan 25, 2013
    Posts:
    12
    Any plans on updating this with rainbows/auroras? Your last post on it was 2016, but I don't see anything after that. Thank you.
     
  36. Salvador-Romero

    Salvador-Romero

    Joined:
    Jan 21, 2014
    Posts:
    51
    hopeful likes this.
  37. qmqz

    qmqz

    Joined:
    Jan 25, 2013
    Posts:
    12
  38. Image3d

    Image3d

    Joined:
    Jun 20, 2008
    Posts:
    115
    Hi, I am using the postprocessing FOG, because my camera is set to deferred, but my skydome background does not render on iOS when fog options is set...any idea ?
     
  39. kai_lehmann

    kai_lehmann

    Joined:
    Apr 14, 2020
    Posts:
    2
    I have a problem with the cloud billboards, I adjust billboard altitude, azimute and size during runtime to make the scene more interesting. I can see the updated values in the editor but in the scene the billboards never change. Is there a sync method to be called anywhere to bring the changes of the TOD_Billboard script to life?
     
  40. PanicEnsues

    PanicEnsues

    Joined:
    Jul 17, 2014
    Posts:
    132
    What if you change the values in the inspector, do you see the clouds moving? If not, are you sure you're looking at the right cloud (each has its own values)?

    I don't use the billboards (they look nice on their own, but I think they clash with the overhead cloud layer, especially in high wind), but just did some quick testing and was able to adjust them using the inspector Altitude/Azimuth/Size controls. Haven't tried it through code yet, but should be the same.
     
  41. hpgbproductions

    hpgbproductions

    Joined:
    Jul 27, 2019
    Posts:
    1
    Here to say that in each of the TOD classes pages, those things called "attributes" were actually "fields". Important since "attributes" in C# have their own meaning. I'm working with TOD through reflection and this got me confused for a while.
     
  42. Atomiklan

    Atomiklan

    Joined:
    Feb 14, 2021
    Posts:
    1
    I can get the dome and main camera to work in unity but when I jump in game the sky is just pitch black which I assume is the camera background prior to render. What am I doing wrong here? Thanks!
     
unityunity