Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Custom time scale manager and WindZone component

Discussion in 'General Graphics' started by xVergilx, Oct 21, 2018.

  1. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Been using own custom time scale manager for a while, until I've realised that windzone cannot be properly "paused". Settings provided by Windzone component doesn't help with this either. Problem arises when timeScale is 0, trees are still moving.

    Which is not acceptable, because it completely ruins the effect I'm trying to achieve.

    Does anyone encountered the same problem?

    There must be a way to feed custom time value. Because altering forces doesn't produce "paused" state, but rather slow-fading wind one.

    Wind / Tree is controlled by some terrain shader as it seems. I wonder if there's a way to override it?
    If not, maybe someone could suggest me some asset that does exact thing?
     
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Forgot to mention. I'm using Nature/SpeedTree shader with same trees, plus default Terrain System.

    Found out from source that wind time seems to be passed as _ST_WindGlobal.x. I might be wrong though.

    I wonder if it's possible to override it using Shader.SetGlobalVector? Or I'd need to override the SpeedTreeWind.cginc to do so?

    Edit: _ST_WindGlobal seems to be not really global, but per instance as Shader.GetGlobalVector/GetGlobalColor returns 0,0,0,0.

    It seems there's no way around except overriding the source and setting time variable everywhere manually to some global variable multiplier.
     
    Last edited: Oct 21, 2018
  3. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,239
    Could you report a bug for this? You are welcome to request it be assigned to me, and link to this forum thread. I will then look at it and let you know.

    (Someone else may also be able to suggest an alternative asset to you)
     
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Not quite sure about what. Should the Shader.GetGlobalVector actually return something? Or the whole thing about WindZone component?
     
  5. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,239
    Time scale of 0 in the time manager should pause the wind zone effects, if I understand you correctly.
     
  6. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Keyword is custom.

    I'm not using default time manager, as that won't help with handling time scale per local object or groups of entities and their time scales. So its working as intended, just cannot be used in my case.
     
  7. ABerlemont

    ABerlemont

    Joined:
    Sep 27, 2012
    Posts:
    66
    (Digging a grave)

    @xVergilx any best pratices out of your experience using multiple time scales ? :)
     
  8. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    It works. If you're seeking some kind of a solution for shaders - make & manage your own time data.
    Time data can be fed to the shader via global array either as part of the system or as MonoBehaviour.

    E.g. something like this:
    https://github.com/VergilUa/SpeedTreev6HDRP_ASE_Port/blob/master/Utility/ShaderTimeControlExample.cs

    Note that you will need custom shaders that read those values based on the index.
    Which means nothing built-in will work.
    Also, SpeedTree right now is a mess for HDRP. Too slow to render and really inefficient.

    As a result - I've dumped the idea to make it work even with a custom fork of the shader.
    I'm using custom "trees" instead (MTree). Which stylistically aren't trees in conventional sense because game setting allows it. So no windzone required. Just some vertex offsets over time. Creates the illusion of movement and still looks nice.

    That's on topic of trees / windzone.

    In the example - those are global timers that are few. Like <100 max;
    Any custom shader written with access to that global array will be able to read custom time data just like _Time variable. Low count is due to platform restrictions. Each platform has its own limit and less than 128 seems to cover most (even mobiles).

    On top of that, I've got a custom written framework that processes time data for each separate entity for the hybrid setup (Entities + MonoBehaviours). This is for the CPU part / simulation. Which is then fed into global array for the shaders, similar to the example, except in a system.

    Meaning each entity can have separate TimerComponent / LocalTimer, which is updated at the beginning of the frame / before simulation. Those LocalTimers can have "root" timer, which can be either local or global timer. Both are TimerComponents [IComponentData] internally.

    Math is simple - its: resultTimeScale = rootTimeScale * localTimeScale;
    (You can go additive as well, but multiplication makes more sense, and I haven't bothered adding it)

    This allows to have 1k+ timers almost free because of Jobs + Burst.
    And double precision for the "Time.time [total]" instead of float.

    Initial values are unscaled values from Time class.
    Like unscaledDeltaTime with extra checks applied on top.

    Afterwards, compute rest of the values (like deltaTime, fixedDT, total / elapsed, whatever you need).
    It gets much more complicated onwards because each component has to be adapted to work with it.
    Stuff like ParticleSystem, Physics, Animator etc.

    User domain code (written scripts) access either LocalTimer [if MonoBehaviour] or TimerComponent [if entity] instead of Time class.

    Lots of concepts are similar to Chronos framework [made by Ludiq].
    But alas, its no longer available on the asset store even for free.
    It was a paid asset, then free, and deprecated a while ago.
    Maybe you'll be able to find a fork somewhere.


    So overall, you need to be more specific.
     
    Last edited: May 28, 2023