Search Unity

Time of Day - Dynamic Sky Dome

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

  1. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    Both. Time of Day is being used in some fairly big Unity projects for both mobile and desktop platforms.
     
  2. karaokefreak

    karaokefreak

    Joined:
    Nov 12, 2013
    Posts:
    96
    Hi there

    I found the time to try it with your demo scene.
    Unfortunately I have the same problem there. Trees will generate a wrong two-dimensional "shadow" that cuts a transparent field into your skydome as soon as you activate cloud shadows. It doesn't happen with the standard palm trees that you included in the demo. But with ANY other kind of tree that I import from the store. EG the oak tree pack and the mountain pine pack. It also happens with every tree that you generate by yourself using the tree generator.


    I attached an image from your demo scene with a very simple tree from a free pack. However, it also happens with more sophisticated trees and it is the exact same problem.

    I might be wrong, but I have the feeing that it is connected with the 2D billboard that every tree brings along for LOD purposes. The shapes match. However, the fake shadow only shows the shape of bark and branches, leaves are not involved.. I used prefabs only...
     

    Attached Files:

    Last edited: Feb 19, 2014
  3. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    Okay, things are getting clearer. The strange thing is really that this only happens with enabled cloud shadows - or any projector hitting the trees for that matter. Thanks for posting those details, I'll look into it as soon as I find the time.
     
  4. snowcult

    snowcult

    Joined:
    Feb 6, 2014
    Posts:
    295
    Sorry if this is answered already. I'm using the prefab skydome and a preset. Any idea why my sky would be gray/grey at both day and night? In my Scene View, it appears to show a blue sky + clouds, but in game/play mode... the sky is gray, no clouds/sun/anything and it stays like that thought day and night cycles.

    Thanks.
     
  5. karaokefreak

    karaokefreak

    Joined:
    Nov 12, 2013
    Posts:
    96
    Hey ShinfoK
    I guess you just need to change the weather settings (there are two settings to define)

    See Skydome - Inspector-->TOD_Weather (Script)

    There is one menu item that lets you pic the density of the clouds (--> couds) and another right below that sets the overall mood of the weather (-->weather)
    If you set weather to "clear" and clouds to "none", you will have a perfect blue sky with no clouds at all. Just try that ;)

    Combining the two settings allows you to have very nice blending effects when changing the weather. Actually, there is a lot you can play with once you write yourself a weather randomizer. You can have the clouds clear up while maintaining a grey sky in order to have a soft transition. And if you generate your own particle rain and such, you can have it all change to foggy after rainfall while the clouds dissappear and so on.. I think this is a clever system. TOD is hands down one of my best unity aquirements (aside from the fake shadow bug, which hopefully will get a fix soon ;) ).
     
  6. snowcult

    snowcult

    Joined:
    Feb 6, 2014
    Posts:
    295
    Hey Karaokefreak. Thanks for the reply.

    I've tried what you suggested to no avail, unfortunately.

    Here's what I'm seeing: http://i.imgur.com/Lv7L62w.jpg

    Top part is what I see in game, no matter the time of day. Second part is how it looks before pressing play. Third part is what happens when I stop the play. It goes back to the second part when i ctrl>s save my project... it's behavior quite weird.

    Edit: Also, congrats to the OP. Just read you got a job with FP. Nice!
     
    Last edited: Feb 20, 2014
  7. snowcult

    snowcult

    Joined:
    Feb 6, 2014
    Posts:
    295
    So I started a new project with just the sky dome, terrain and a char controller and it works fine. Must be something conflicting with it in my main project,

    EDIT: I got it. Scaling was too far and camera clipping.
     
    Last edited: Feb 20, 2014
  8. fabio1955

    fabio1955

    Joined:
    Nov 11, 2009
    Posts:
    72
    I need to add a mini map to the scenery. I just added, to your Test Scene Terrain, a second camera with a render texture and the following script:
    Code (csharp):
    1. var material:Material;
    2. var texture: RenderTexture;
    3. function OnGUI () {
    4. Graphics.DrawTexture(Rect(10,10,256,256),texture,material);
    5. }
    Where the material is the unlit/texture shader as suggested somewhere in the forum...
    Every things go well in the Unity IDE, in other words I can run inside Unity without problems.
    BUT once compiled the minimap is not visible!
    Other info:
    Unity 4.3.4 running on Windows 7, graphic card: AMC Radeon HD 5800 Series
    Any suggestion? work around?
     
    Last edited: Feb 20, 2014
  9. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    Thanks. Also good to hear you already fixed the issue you encountered.

    That doesn't really have anything to do with Time of Day. RenderTexture only works with Unity Pro licenses though, so make sure you're not in the trial period or something.
     
  10. fabio1955

    fabio1955

    Joined:
    Nov 11, 2009
    Posts:
    72
    I am on Unity Pro and not in the trial period. The problem happen only with Time of Day. I also tested without. As I said every things are fine inside Unity. If you don't believe me just try it!
    $img3.png
    Minimap: Inside Unity

    $Img1.png
    Nothing seen running the executable
     
    Last edited: Feb 20, 2014
  11. fabio1955

    fabio1955

    Joined:
    Nov 11, 2009
    Posts:
    72
    Without Time Of day
    $Img1.png




    With TOD
     

    Attached Files:

    Last edited: Feb 20, 2014
  12. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    According to the docs you should probably use GUI.DrawTexture rather than Graphics.DrawTexture in OnGUI calls.

    That being said, I tested this using both GUI.DrawTexture and Graphics.DrawTexture and it works for me in both the editor and standalone. You're either screwing something up in the shader of the material you assigned to the script or while rendering into your RenderTexture.

    For the rest of you: there will be an update 2.0.5 some time during the upcoming weeks with quite a few tweaks and fixes that came to my attention.
     
  13. karaokefreak

    karaokefreak

    Joined:
    Nov 12, 2013
    Posts:
    96
    YAY!
     
  14. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    I did the research and it's unlikely that I'll be able to fix the tree creator shader / cloud shadow projector issue as it seems to be a problem with the Unity tree creator shaders itself. I verified that this happens with every projector that hits trees that use the tree creator shader. The exact requirements for it to occur are the following:
    • Trees using the tree creator shaders
    • Tree placement using the Unity terrain tools (it works for drag drop into the scene or script instantiation)
    • Any Unity projector hitting the trees (e.g. enable cloud shadows in Time of Day)
    However, you can work around this even if you have to use all of the above things. I would recommend using the "Tree Soft Occlusion Bark" and "Tree Soft Occlusion Leaves" shaders for all trees that are being be placed on the terrain using the terrain tools. This means that you have to create a new prefab and two materials for every tree and assign a "Mesh Filter" and "Mesh Renderer" component to the prefab. The mesh is the tree creator output mesh and the materials should use the beforementioned shaders and the tree creator output texture. You cannot directly edit the shader for the tree creator materials, which is why the two materials have to be manually created.
     
    Last edited: Feb 23, 2014
  15. fabio1955

    fabio1955

    Joined:
    Nov 11, 2009
    Posts:
    72
    Last edited: Feb 24, 2014
  16. fabio1955

    fabio1955

    Joined:
    Nov 11, 2009
    Posts:
    72
  17. spj

    spj

    Joined:
    Feb 7, 2014
    Posts:
    1
    Hello all, I'm really new to Unity and I hate to bother everyone since it seems everyone in this thread is way above my experience level. But this seemed the appropriate place to ask this since it directly correlates to my problem.

    I have a very large terrain (15,000) and when I place a skydome just like the one the author is selling Its obviously out of the clipping distance. I understand I can attach the dome to the controller and that's fine if it was a single player thing but I want multiplayer and im wondering how to get the dome to render the same for everyone at the same time. I don't have an ftp set up so I'm just assuming it wont work and if it will that's great. I saw at the beginning of this thread about a 2 camera set up but I cant even come close to understanding that concept and ive looked around alot for tutorials on how to do this and came up nill.

    Can anyone point me in the right direction on how to make something like this work in a multiplayer setting? Because i would really like to buy this asset. remember my tech level please =)
     
  18. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    999
    You should post your question in the general support forum...

    http://forum.unity3d.com/forums/10-Unity-Support

    This forum is for the discussion about and support for the asset this developer is selling. Your getting ahead of yourself with the multiplayer idea, considering your tech level and all. Create a simple game to start.
     
  19. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    Time of Day 2.0.5 is out! As always, check out the changelog on the website.
     
  20. SiBlack

    SiBlack

    Joined:
    Jun 12, 2013
    Posts:
    22
    Hi,

    I've got an issue using Time of day alongside SUIMONO water system.
    I need to transition the water shader between day and night settings so the water fog matches the sky.
    Using IsDay and IsNight makes the transition happen too late ( It's way dark before the water starts to change and I don't like that it's constantly polling this on each update.)

    I've tried using the LerpTime and setting my own bools from it BUT on Start() or Awake(), LerpTime always returns 0 regardless of time of day (The same is true, of course, testing IsDay or IsNight as they're set from LerpTime.)
    So any bools set are messed up. This is also a potential problem when loading a saved game. Again I don't want to be polling every frame for everything that should or shouldn't be active during day or night, it's already costing a frame or so.

    Any suggestions on a fix or workaround?

    Thanks.
     
  21. SiBlack

    SiBlack

    Joined:
    Jun 12, 2013
    Posts:
    22
    Never mind I got it working using sky.Cycle.Hour instead :)
     
  22. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    Good to hear you were able to work around it, but I'll see to change the behaviour to at least initialize those properties in Awake() in the next update so that they are available in Start() of other scripts.
     
  23. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Could you include a version of your system using standard skyboxes instead of skydomes?
     
    Last edited: Mar 9, 2014
  24. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    Why do you want that? Time of Day can use a Unity skybox at night if you want an to use a skybox of the milky way at night and require the texture projection a skybox offers, other than that there's no reason not to use a skydome. The default Unity skybox can only render textures and a cube mesh cannot be used since the physical model is calculated per-vertex and 8 points to solve the equations would not be enough.
     
  25. snowcult

    snowcult

    Joined:
    Feb 6, 2014
    Posts:
    295
    How do I make lights only appear at night? I tried attaching the RenderAtNight script to no avail.
     
  26. Mayalicious

    Mayalicious

    Joined:
    Feb 21, 2014
    Posts:
    12
    I want to make a key press cycle system. For example when i click "C" in the keyboard i want the time to cycle? Is this possible? If yes, how? Thank you.
     
  27. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. [RequireComponent(typeof(Light))]
    4. public class LightAtNight : MonoBehaviour
    5. {
    6.     public TOD_Sky sky;
    7.  
    8.     private Light lightComponent;
    9.  
    10.     protected void OnEnable()
    11.     {
    12.         if (!sky)
    13.         {
    14.             Debug.LogError("Sky instance reference not set. Disabling script.");
    15.             this.enabled = false;
    16.         }
    17.  
    18.         lightComponent = this.light;
    19.     }
    20.  
    21.     protected void Update()
    22.     {
    23.         lightComponent.enabled = sky.IsNight;
    24.     }
    25. }
    26.  
    By using Input.GetKeyDown and TOD_Sky.Cycle.Hour.
     
  28. Mayalicious

    Mayalicious

    Joined:
    Feb 21, 2014
    Posts:
    12
    Can you please give example code? I am a programming newbie. Thank you
     
  29. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    The script reference for OnKeyDown already provides example code, all you have to do is change it so that Cycle.Hour is set instead. For that have a look at the LightAtNight script I just posted, it uses a public reference of type TOD_Sky and then accesses sky.IsNight, you'd have to access sky.Cycle.Hour instead.

    Sorry if this sounds unhelpful, but you'll have to learn this stuff sooner or later - if you read the documentation and what I just said closely you should be able to piece it together.
     
  30. snowcult

    snowcult

    Joined:
    Feb 6, 2014
    Posts:
    295
    Thanks OP. Appreciate it.
     
  31. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    999
    Just a suggestion. It would be helpful to rename standard assets included with the demo scene so they don't conflict with anything else in a project. Or include the demo scene as a zip that can be extracted if needed. In this case it's the mouselook script. Deleting the demo scene doesn't fix it as having it there mucked up the import process. Great asset though ;) Thanks.
     
  32. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    I actually addressed this for the mouselook script in the 2.0.5 update - it should no longer happen. I did another quick test just now to verify this by importing all sorts of Standard Assets into the Time of Day project and I couldn't reproduce it anymore - could it be that you're still on 2.0.4 or that your project still uses the wrong GUID for the mouselook script?
     
  33. Mayalicious

    Mayalicious

    Joined:
    Feb 21, 2014
    Posts:
    12
    Hello again. I am getting errors with this javascript. It says "Assets/cycleHour.js(4,9): BCE0005: Unknown identifier: 'TOD_Sky'." My cycleHour.js is;

    Code (csharp):
    1.  
    2. function Update()
    3. {
    4.     if (Input.GetKeyDown(KeyCode.C))
    5.         TOD_Sky.Cycle.Hour;
    6. }
    7.  
     
  34. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    999
    I can reproduce it at home either. It's possible I haven't updated that asset at work, i'll double check tomorrow. Thank you.
     
  35. Mayalicious

    Mayalicious

    Joined:
    Feb 21, 2014
    Posts:
    12
    I tried this. Still no luck. Can you help please?

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. [RequireComponent(typeof(Light))]
    4. public class LightAtNight : MonoBehaviour  
    5. {
    6.    
    7.     public TOD_Sky sky;
    8.     private Light lightComponent;
    9.     protected void OnEnable()
    10.    
    11.     {  
    12.         if (!sky)  
    13.         {  
    14.             Debug.LogError("Sky instance reference not set. Disabling script.");
    15.             this.enabled = false;  
    16.         }
    17.        
    18.         lightComponent = this.light;
    19.        
    20.     }
    21.    
    22.     protected void Update()
    23.  
    24.     {
    25.         if (Input.GetKeyDown(KeyCode.C))
    26.             TOD_Sky.Cycle.Hour;
    27.        
    28.     }
    29.    
    30. }
    31.  
     
  36. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    I recommend reading some scripting tutorials. I fixed your script for now, but you'll have to get a better understanding of how Unity scripts work sooner or later. Paste this into a script called "IncreaseTime.cs", attach it to a game object and drag the sky dome instance onto the "sky" inspector variable.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class IncreaseTime : MonoBehaviour  
    5. {
    6.     public TOD_Sky sky;
    7.  
    8.     protected void OnEnable()
    9.     {  
    10.         if (!sky)  
    11.         {  
    12.             Debug.LogError("Sky instance reference not set. Disabling script.");
    13.             this.enabled = false;  
    14.         }
    15.     }
    16.    
    17.     protected void Update()
    18.     {
    19.         if (Input.GetKeyDown(KeyCode.C))
    20.             sky.Cycle.Hour += 1;
    21.     }
    22. }
    23.  
     
  37. Mayalicious

    Mayalicious

    Joined:
    Feb 21, 2014
    Posts:
    12
    Thank you very much!
     
  38. snowcult

    snowcult

    Joined:
    Feb 6, 2014
    Posts:
    295
  39. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    The light is constantly very slowly moving, so the view from the light is always very slightly different from one frame to the next. Therefore, pixels shift around.
     
  40. snowcult

    snowcult

    Joined:
    Feb 6, 2014
    Posts:
    295
    Is there anyway to stop this from looking so drastically.... bad?
     
  41. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    You can try adjusting the shadow parameters of the light source, reduce the shadow distance or get some shadow smoothing solution from the Asset Store. Also, if you prefer jumping shadows over this you can use this modified version of TOD_Time (will be part of the next update) and set UpdateInterval to whatever time you want between the jumps,

    Code (csharp):
    1. using UnityEngine;
    2. using System;
    3.  
    4. /// Time iteration class.
    5. ///
    6. /// Component of the sky dome parent game object.
    7.  
    8. public class TOD_Time : MonoBehaviour
    9. {
    10.     /// Day length inspector variable.
    11.     /// Length of one day in minutes.
    12.     public float DayLengthInMinutes = 30;
    13.  
    14.     /// Time update interval in seconds.
    15.     /// Zero means every frame.
    16.     public float UpdateInterval = 0;
    17.  
    18.     /// Date progression inspector variable.
    19.     /// Automatically updates Cycle.Day if enabled.
    20.     public bool ProgressDate = true;
    21.  
    22.     /// Moon phase progression inspector variable.
    23.     /// Automatically updates Moon.Phase if enabled.
    24.     public bool ProgressMoonPhase = true;
    25.  
    26.     private TOD_Sky sky;
    27.     private float deltaTime;
    28.  
    29.     protected void Start()
    30.     {
    31.         sky = GetComponent<TOD_Sky>();
    32.     }
    33.  
    34.     protected void Update()
    35.     {
    36.         deltaTime += Time.deltaTime;
    37.  
    38.         if (deltaTime < UpdateInterval) return;
    39.  
    40.         float oneDay = DayLengthInMinutes * 60;
    41.         float oneHour = oneDay / 24;
    42.  
    43.         float hourIter = deltaTime / oneHour;
    44.         float moonIter = deltaTime / (30*oneDay) * 2;
    45.  
    46.         sky.Cycle.Hour += hourIter;
    47.  
    48.         if (ProgressMoonPhase)
    49.         {
    50.             sky.Cycle.MoonPhase += moonIter;
    51.             if (sky.Cycle.MoonPhase < -1) sky.Cycle.MoonPhase += 2;
    52.             else if (sky.Cycle.MoonPhase > 1) sky.Cycle.MoonPhase -= 2;
    53.         }
    54.  
    55.         if (sky.Cycle.Hour >= 24)
    56.         {
    57.             sky.Cycle.Hour = 0;
    58.  
    59.             if (ProgressDate)
    60.             {
    61.                 int daysInMonth = DateTime.DaysInMonth(sky.Cycle.Year, sky.Cycle.Month);
    62.                 if (++sky.Cycle.Day > daysInMonth)
    63.                 {
    64.                     sky.Cycle.Day = 1;
    65.                     if (++sky.Cycle.Month > 12)
    66.                     {
    67.                         sky.Cycle.Month = 1;
    68.                         sky.Cycle.Year++;
    69.                     }
    70.                 }
    71.             }
    72.         }
    73.  
    74.         deltaTime = 0;
    75.     }
    76. }
     
  42. snowcult

    snowcult

    Joined:
    Feb 6, 2014
    Posts:
    295
    Thanks, I gave that a tried. Definitely fixed the shadows, just really not a fan of the result. I suppose that "fading" transitions would negate the effect, if even possible?
     
  43. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    No, it's not. You can't fade between shadowmaps ;)
     
  44. Batigol

    Batigol

    Joined:
    Oct 17, 2012
    Posts:
    234
    I'm just new with this plugin.
    Previous time, I use UniSky, it doesn't update anymore
    In UnitySky, we can input the SkyColor by time of day in Editor
    Base on that UniSky will transition the color, is there any same function in this plugin?
     
  45. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    You cannot set colors for a specific time of day via editor since sunset / sunrise coloring is calculated using the star color and scattering intensities. There are a few colors you can adjust though to tweak the looks of the sky dome to your preference, just look at the inspector. (Atmosphere.ScatteringColor, Day/Night.AdditiveColor, Day/Night.SunLightColor)
     
  46. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    I have a doubt, I don´t know if it is already answered here, sorry:
    What happen when the main camera is destroyed in the scene (ingame) and recreated again? Is the skydome-system reassigned automatically to the new main camera or it is neccessary to do it by script?
     
  47. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    The sky dome itself finds the camera via the "Main Camera" tag, the scripts on the camera (like TOD_Camera) require you to set the sky dome reference by hand - if you create the camera via code you also have to set the sky dome reference via code. There are no hidden references that aren't in the inspector, so to see if all references are correctly setup simply look at the camera in the Unity editor.
     
  48. Baldwin

    Baldwin

    Joined:
    Apr 1, 2014
    Posts:
    37
    How can I add lens flare to this? I cant seem to get it to work.....
     
  49. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    Simply add it to the directional light source game object, it's no different than any other directional light.
     
  50. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    2.0.6 is on its way, I hope to finish it up this weekend for an Asset Store submission on Monday. It will address all of the minor issues you guys reported, offer more configuration options for the ambient light calculation, an option to use the actual real-life moon position rather than the mirrored sun position, a configurable light position update interval and additional and improved example scripts.