Search Unity

TENKOKU - Dynamic Sky

Discussion in 'Assets and Asset Store' started by chingwa, Apr 12, 2015.

  1. TheSeawolf

    TheSeawolf

    Joined:
    Apr 10, 2015
    Posts:
    267
    Thank you guys, I appreciate that and report back :)
     
    BackwoodsGaming and Bagnol like this.
  2. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    As mentioned, the demo contains an example setup with GUI changing Tenkoku system settings... Time, weather, lighting etc. I recommend digging into the code to see what it's doing (it should be pretty straightforward). It's probably easiest to look at the example, and then adapt it for your own needs, but you can also read about code and variable access, starting on page 8 of the documentation here: http://www.tanukidigital.com/tenkoku/documentation/tenkoku_documentation.pdf
     
    BackwoodsGaming and TheSeawolf like this.
  3. TheSeawolf

    TheSeawolf

    Joined:
    Apr 10, 2015
    Posts:
    267
    Thanks chingwa, I'll get into that on the weekend.

    I'm looking forward to getting Suimono shortly now. That buoy demo sold me :)
     
    chingwa and BackwoodsGaming like this.
  4. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    Hi, I noticed the sky blur in tenkoku has a problem with garbage collection where it allocates 1.6k every frame which adds up quickly. I've re-written the code below without the memory issue. Using the param list allocates a new array every call.

    Code (csharp):
    1.  
    2. using System;
    3. using UnityEngine;
    4.  
    5. namespace Tenkoku.Effects
    6. {
    7.   [RequireComponent(typeof(Camera))]
    8.   public class TenkokuSkyBlur : MonoBehaviour
    9.   {
    10.  
    11.   public int iterations = 3;
    12.   public float blurSpread = 0.6f;
    13.   public Shader blurShader = null;
    14.   public Material material = null;
    15.  
    16.   Vector2[] downSample = new Vector2[4];
    17.   Vector2[] fourTap = new Vector2[4];
    18.  
    19.   void Start()
    20.   {
    21.   downSample[0] = new Vector2(-1f, -1f);
    22.   downSample[1] = new Vector2(-1f, 1f);
    23.   downSample[2] = new Vector2(1f, 1f);
    24.   downSample[3] = new Vector2(1f, -1f);
    25.  
    26.   fourTap[0] = Vector2.zero;
    27.   fourTap[1] = Vector2.zero;
    28.   fourTap[2] = Vector2.zero;
    29.   fourTap[3] = Vector2.zero;
    30.  
    31.  
    32.   if (material == null)
    33.   {
    34.   material = new Material(blurShader);
    35.   material.hideFlags = HideFlags.DontSave;
    36.   }
    37.  
    38.   // Disable if we don't support image effects
    39.   if (!SystemInfo.supportsImageEffects)
    40.   {
    41.   enabled = false;
    42.   return;
    43.   }
    44.   // Disable if the shader can't run on the users graphics card
    45.   if (!blurShader || !material.shader.isSupported)
    46.   {
    47.   enabled = false;
    48.   return;
    49.   }
    50.   }
    51.  
    52.  
    53.   // Performs one blur iteration.
    54.   void FourTapCone(RenderTexture source, RenderTexture dest, int iteration)
    55.   {
    56.   float off = 0.5f + iteration * blurSpread;
    57.   fourTap[0] = downSample[0] * off;
    58.   fourTap[1] = downSample[1] * off;
    59.   fourTap[2] = downSample[2] * off;
    60.   fourTap[3] = downSample[3] * off;
    61.  
    62.   Graphics.BlitMultiTap(source, dest, material, fourTap);
    63.   }
    64.  
    65.   // Downsamples the texture to a quarter resolution.
    66.   void DownSample4x(RenderTexture source, RenderTexture dest)
    67.   {
    68.   //float off = 1.0f;
    69.   Graphics.BlitMultiTap(source, dest, material, downSample);
    70.   }
    71.  
    72.   RenderTexture buffer, buffer2;
    73.  
    74.   // Called by the camera to apply the image effect
    75.   void OnRenderImage(RenderTexture source, RenderTexture destination)
    76.   {
    77.   int rtW = source.width / 4;
    78.   int rtH = source.height / 4;
    79.   buffer = RenderTexture.GetTemporary(rtW, rtH, 0);
    80.  
    81.   // Copy source to the 4x4 smaller texture.
    82.   DownSample4x(source, buffer);
    83.  
    84.   // Blur the small texture
    85.   for (int i = 0; i < iterations; i++)
    86.   {
    87.   buffer2 = RenderTexture.GetTemporary(rtW, rtH, 0);
    88.   FourTapCone(buffer, buffer2, i);
    89.   RenderTexture.ReleaseTemporary(buffer);
    90.   buffer = buffer2;
    91.   }
    92.   Graphics.Blit(buffer, destination);
    93.  
    94.   RenderTexture.ReleaseTemporary(buffer);
    95.   }
    96.   }
    97. }
    98.  
     
  5. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    @wightwhale Thanks for the code! This doesn't give the same blur quality using the same settings, but I'm sure it can be tuned to work similarly to the original. For the next update I've already replaced the original blur with an optimized blur shader, but I'll go back and remove any allocations similar to your code above.
     
  6. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    Hmm that should be the exact same code, must have written something slightly off. I also have done some work on the LateUpdate, FixedUpdate, and tenkoku sun shafts below. I replaced various new vector3 and new color with declared variables instead of having a new in an update function which should be avoided. I also replaced some new color (0,0,0,1) with black and new color (1,1,1,1) with color.white.

    I changed display time to only update the string in the editor because that info isn't needed when we're in a build.
    #if UNITY_EDITOR
    //SET DISPLAY TIME
    displayTime = DisplayTime("[ hh:mm:ss am] [ M/D/Y ad]");
    #endif

    I moved the layer mask code to the start as I don't think those will change during runtime. But if that code is needed you can make it so there's not a new list every time just use the same list and clear it each loop.

    not sure why you're using clamp here, this will always give you .8f
    fxUseLight = Mathf.Clamp(4.0f,0.1f,0.8f);

    and a little lower here, the lerp isn't doing anything
    fogCol = Color.Lerp(new Color(1f,1f,1f,1f),new Color(1f,1f,1f,1f),0.6f) * fxUseLight;
    which could go to
    fogCol = Color.Lerp(Color.white,Color.white,0.6f) * fxUseLight;
    which is the same as
    Color fogColStart = new Color(.6f,.6f,.6f,.6f);
    fogCol = fogColStart * fxUseLight;

    i'm not sure what this is doing but it's causing memory leaks for each time it's called in the late update. This link here goes into more detail .
    http://forum.unity3d.com/threads/wh...f-the-old-particlesystem-emissionrate.373106/
    rainEmission.rate = new ParticleSystem.MinMaxCurve(weather_RainAmt,Mathf.Lerp(2,5000,weather_RainAmt));
    it does look like you can skip the min max curve when there aren't particles emitting and it would be a nice performance gain. I wasn't sure how to tell when the emitters were on for sure.

    I replaced the send message call to SetLightValues in tenkokusunshafts.cs All the string concatenations and parsing is much slower than just passing the values directly. I'm seeing a significant performance boost and it also fixes the biggest garbage collection issues in the file.

    Let me know if you want me to take down these files or send them in a different way
     
    chingwa likes this.
  7. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    @wightwhale Thanks! I'll review these edits for inclusion in the main codebase tomorrow. In the meantime, yes, please remove them from the public forum. I've already saved them on my end. In the future you can always email me files directly at konnichiwa[at]tanukidigital.com. :)
     
  8. CaptainMurphy

    CaptainMurphy

    Joined:
    Jul 15, 2014
    Posts:
    746
    @chingwa a private code repo would help on these pull requests ;)
     
  9. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    @CaptainMurphy I was counting the minutes until you were going to show up... I was not let down :D
    I've been slowly getting onboard with github. I admit it's taken me a while getting used to working this way. I'm pretty confidant with it now though, and expect to be offering private access to those who would like to contribute... uh... "Soon".
     
  10. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    NOTE: For some unknown reason all my websites went offline this morning. :( Tech Support is currently looking into the issue. To anyone who is interested in checking out the demos of my assets everything should hopefully be back up soon!

    EDIT: Nevermind, everything is working again! :)
     
    Last edited: Aug 25, 2016
  11. Andrzej-Skibinski

    Andrzej-Skibinski

    Joined:
    Apr 16, 2014
    Posts:
    13
    Hello

    I was wondering are you planning on adding time-zone support to Tenkoku? Currently we use our own code to offset time in tenkoku depending on time-zone and daytime saving. But since Tenkoku has such a accurate model based on geoposition, it could also offer such timezone support :)
     
  12. CaptainMurphy

    CaptainMurphy

    Joined:
    Jul 15, 2014
    Posts:
    746
    I can't, honestly, see a use for it in Tenkoku as every game will be doing their time differently. For instance, one of ours is done in the 1750's area and time is relative based on sun position, not on a 'zone'. Another of our games is based in another set of real world islands, but is on a zone border that would necessitate the time changing based on lat/long of these really crazy lines. Just trying to keep that straight as a developer for our OWN game is a pain, let alone trying to compensate for everyone's possible usage. I think giving the UTC is probably the best possible outcome for the asset without sinking time into a part of it that isn't fully useful to the larger portion of users.
     
    chingwa likes this.
  13. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    @Andrzej-Skibinski No I don't have any plans to add this. As @CaptainMurphy says most people won't need this functionality. Calculating accurate Time-zone and daytime-savings is not trivial because this is not really a function of longitude, but instead it's a function of politics since different localities have different time policies and keeping it all accurate is a bit too much to deal with :) Leaving it to the end-developer to handle this, as you have done, is the best way to deal with this I think.
     
  14. TheSeawolf

    TheSeawolf

    Joined:
    Apr 10, 2015
    Posts:
    267
    hello Chingwa, I'm having a great time with Tenkoku but am having minor difficulties finding a good blend of values to tone down the brightness of the sunglare directly under the sun, and on the horizon. Can anyone offer their settings as starting points?

    Also are there any plans to implement separate climatic zones within the same terrain. for example I would ike to have cooler and snowing weather 1500 metres above sea level, but at the same time retain non snowing weather at sea level?
     
  15. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    @TheSeawolf You're right these two areas are pretty hard to adjust currently. You can lower the overall brightness of the sky somewhat, by lowering the "sky amount (day)" setting under celestial settings. But you don't want to lower this too far as it affects the entire sky. you can also raise the "sky dispersion" under atmospherics and this will blend out botht he sun and horizon dispersion which should help a bit. I'll see if I can get some better color or brightness controls for these two elements in the next update.

    I haven't done any work with climactic zones, but it shouldn't be too hard for me to add something like this. It would probably be akin to defining sphere trigger colliders and allowing you to adjust certain aspects of the system as the camera intersects them. This would work well for local climate zones, but more to your point on altitude I could also build in a curve that effects temperature based on y-position. I'll add it to the list. (that never ending list :D )
     
  16. TheSeawolf

    TheSeawolf

    Joined:
    Apr 10, 2015
    Posts:
    267
    Well while you're compiling that list...hehehe:) When is the next update...tomorrow, or possibly the next day?

    Thank you for the suggestion regarding the lighting, I'll muck around some more with these, but as you suggest the changes that are made have to be slight. Thanks for looking into the climate zones/biome feature too.
     
  17. Andrzej-Skibinski

    Andrzej-Skibinski

    Joined:
    Apr 16, 2014
    Posts:
    13
    I wasn't talking about calculating time-zones (I know this is based on politics and local settings). I was just thinking of adding a time-zone integer and day-time saving boolean directly to your system. I work in architecture/infrastructure industry, and here accurate representation of sun movement is a must. But even the professional software only allows to input those two variables (so i.e. timezone +2 and daytime saving on). This simply offsets the time by given amount of hours.
    But I ofc understand that you're not going to add this for small percentage of your users. No worries.
     
  18. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    @Andrzej-Skibinski Oh I see, yes a simple "timezone" offset could be quite useful actually! Great Idea!

    @TheSeawolf I'm working on adding in the first version of the new automatic weather generator, and once I'm happy with that I'll be putting out the next release. It shouldn't take much longer, but it won't be ready tomorrow :D
     
  19. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,270
    @chingwa: The webplayer demo looks awesome. Is that included in the asset when you buy it?
     
  20. Bagnol

    Bagnol

    Joined:
    Sep 5, 2013
    Posts:
    169
    @Rowlan if you're referring to the hill scene with the spheres then yes, it's included.
     
    chingwa and Rowlan like this.
  21. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    @Andrzej-Skibinski just FYI, I implemented both a timezone offset and a daylight savings time toggle. These will be available in the next update. :)
     
  22. daschatten

    daschatten

    Joined:
    Jul 16, 2015
    Posts:
    208
    @chingwa i get this error when building my project:

    Code (CSharp):
    1. Shader error in 'TENKOKU/galaxy_shader': texld/texldb/texldp/dsx/dsy instructions with r# as source cannot be used inside dynamic conditional 'if' blocks, dynamic conditional subroutine calls, or loop/rep with break*. at line 85 (on d3d9)
    Any ideas about it?
     
    chingwa likes this.
  23. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    @daschatten I'll take a look. Can you tell me what build target your project is set to?
     
  24. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    I was getting that same error in unity 5.4. The api updater ran something so I think it updated some of the shaders and couldn't fix an issue with that.
     
    chingwa likes this.
  25. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    Ah yes, I'm getting this as well in Unity 5.4... the strange thing is that even though it comes up as a red 'serious' error, the galaxy rendering still works fine in build. I'm not 100% sure what this is a bout but I'll keep looking. I wouldn't worry too much about it in the meantime, unless you think it's actually affecting the night galaxy rendering in your build.
     
  26. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    I think it kept me from building a player for some reason. I'm avoiding the update to 5.4 for now.
     
  27. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    OK, this is fixed now. Below is an updated galaxy shader. The problem was the texture coordinates need to be flipped in the Y-vector which I had been doing in the fragment function. Unity 5.4 compiler doesn't like this for whatever reason. I'm now flipping them in the vertex function instead which it has no issues with (why so sensitive???).
     

    Attached Files:

  28. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    yes, no more errors for me! Thanks
     
  29. daschatten

    daschatten

    Joined:
    Jul 16, 2015
    Posts:
    208
    Works for me, too. Thanks!

    Only remaining issue: pixelated or (playing with cloud scale) blurry clouds, see screenshot. Are there additional settings to resolve this?
     

    Attached Files:

  30. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    @daschatten There aren't any additional settings for the clouds, no. I am working on an updated cloud system though, due to balancing the visuals of the clouds vs performance it is taking me much longer than anticipated. I hope to have some more news about this soon.
     
  31. daschatten

    daschatten

    Joined:
    Jul 16, 2015
    Posts:
    208
    Ok, thx for the update. Take your time!
     
  32. daschatten

    daschatten

    Joined:
    Jul 16, 2015
    Posts:
    208
    @chingwa I have a wish for your next releases: Please include events for time, weather... all things that can change.
     
  33. jessejarvis

    jessejarvis

    Joined:
    Aug 9, 2013
    Posts:
    303
    When using Tenkoku with the Survival Game Template 1.1b it freezes/locks up the mouse look. Anybody else have this strange issue?
     
  34. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    Can't imagine why it would change any mouse behavior. Are you sure Tenkoku is tracking the correct scene camera?
     
  35. ikemen_blueD

    ikemen_blueD

    Joined:
    Jan 19, 2013
    Posts:
    341
    @chingwa Hi there, I sent u a private message about the runtime memory allocations, that trigger GC calls often. I hope you could improve it in your future updates. That would be awesome. Overall, I'm very happy with Tenkoku Dynamic Sky, just wish its performance could be improved much more.
     
  36. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    507
    Because of a future that Time of Day have I'm not using Tenkuko anymore but I really like to back and work with tenkoku again, can you please add this future to tenkoku?

    I'm talking about this section.


    With this future I can set my sun every where I like (For a better horizon view) and then change light's height to put light source upper than sun! (without moving the sun) so with this I can set my sun behind the mountains for a nice horizon view and set light source higher than sun to avoid long wide shadows.
     
    Last edited: Sep 23, 2016
  37. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    @Crossway Hmm, I've never considered this before... am I the only one that actually likes the long shadows? :D This is an easy fix, I'll definitely add this function in the next update.
     
    Crossway likes this.
  38. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    ....aaaaand 15 minutes later, It's already in. Will be included with version 1.1.2.

     
  39. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    507
    That was really fast :eek: please release this sooner. thanks.

    Of course you are the only one :D
     
  40. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    176
    Does this asset fully support unity 5.4, wondering as I currently have TOD and it definitely isn't working with 5.4 and the update may be some time in arriving.
     
  41. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    BackwoodsGaming likes this.
  42. BackwoodsGaming

    BackwoodsGaming

    Joined:
    Jan 2, 2014
    Posts:
    2,229
    I can confirm that it is working on 5.4 as well. I haven't tried a build, so I haven't seen the issue @chingwa talked about. But I'm having no issues at all with it in my build scenes in 5.4.0f3. :)
     
    chingwa likes this.
  43. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    176
    Thanks guys, I think I'll be making a purchase, I already have Suimono so I'm sure the two will play nice together :)
     
    BackwoodsGaming likes this.
  44. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    176
    Bought and integrated it, it looks really nice, very pleased with it.

    A quick question (I hope). Is there an easy way to dynamically decide as to whether I want to load a straight forward skybox or Tenkoku at scene load time. One of my quality settings is for dynamic sky on/off and I'm not sure as to how I would implement this. Is it as simple as deactivate the tenkoku game object and scripts on the camera and load in a different skybox to render settings? The docs don't cover anything on this.
     
  45. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    Hi catfink, thanks for your purchase! When Tenkoku is active it automatically loads in it's own sky material when the scene loads. You can disable the Tenkoku object in the scene, which would prevent it from assigning it's skybox (just make sure to also disable the Tenkoku camera effect too!). You can also replace the skybox while the scene is running, as Tenkoku only makes this assignment at load-time.

    If you're doing this as a quality setting then you may just want to completely disable the Tenkoku game object and image effect, and then replace the skybox with the appropriate material.
     
    catfink likes this.
  46. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    176
    Apologies if this has been asked before but what I see in the scene view is not what I see when I run the game, which is slowing up my workflow a bit as I'm having to run it to see what effect my changes have. Is it meant to be like this?
     
  47. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    Some aspects of the sky do not render properly in edit mode... clouds, moon, fog, etc. But the sky itself should be showing at least close to correct colors in edit mode. What are you seeing on your end?
     
  48. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    176
    yes, I have lighting but as you say the clouds etc are not visible as they are on a plane off in the distance. What I wasn't sure about was if the lighting I am seeing is accurate to the settings as I find it difficult to judge when the sky is in big contrast to the landscape, where as in game mode it renders the sky and the contrast differences are less.

    In edit it looks like this ....
    upload_2016-9-28_10-31-13.png

    In game like this ....

    upload_2016-9-28_10-40-1.png

    What causes me issues is the white of the skybox as you approach the horizon in edit mode, this causes a big contrast on my screen and makes it very hard to judge the lighting as there is a big white area throwing your eyes off.
     
  49. EddieChristian

    EddieChristian

    Joined:
    Oct 9, 2012
    Posts:
    725
    So I am working with a group on an UFPS based game. In the main camera there is no Stutter. But in the 3RD Person camera it still stutters quite a bit..
     
  50. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    @SoloChristian I've been working on a fix for the UFPS stutter for the next Tenkoku update, but in the meantime you can try fixing this manually on your end by going to Edit-->Project Settings-->Script Execution Order and dragging the TenkokuModule.cs script file into the list (located under /SCRIPTS), then setting it to be 1000.

    This has fixed some stuttering issues in some other 3rd party assets and I believe it should fix UFPS as well. All this will be done automatically through code in the next update so you won't have to worry about this going forward. Let me know if you still have stuttering issues after trying this.