Search Unity

Description of packed SpeedTree (Wind) shader inputs

Discussion in 'Shaders' started by xVergilx, Oct 28, 2018.

  1. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Looking for information about SpeedTreeWind.cginc inputs. Haven't found any information on the net.

    Specifically these:
    Code (CSharp):
    1. CBUFFER_START(SpeedTreeWind)
    2.     float4 _ST_WindVector;
    3.     float4 _ST_WindGlobal;  // (_Time.y, ?, ?, ?)
    4.     float4 _ST_WindBranch; // (_Time.y, ?, ?, ?)
    5.     float4 _ST_WindBranchTwitch;
    6.     float4 _ST_WindBranchWhip;
    7.     float4 _ST_WindBranchAnchor;
    8.     float4 _ST_WindBranchAdherences;
    9.     float4 _ST_WindTurbulences;
    10.     float4 _ST_WindLeaf1Ripple; // (_Time.y, ?, ?, ?)
    11.     float4 _ST_WindLeaf1Tumble; // (_Time.z, ?, ?, ?)
    12.     float4 _ST_WindLeaf1Twitch; // (?, ?, _Time.y, ?)
    13.     float4 _ST_WindLeaf2Ripple; // (_Time.y, ?, ?, ?)
    14.     float4 _ST_WindLeaf2Tumble; // (_Time.z, ?, ?, ?)
    15.     float4 _ST_WindLeaf2Twitch; // (?, ?, _Time.y, ?)
    16.     float4 _ST_WindFrondRipple; // (_Time.y, ?, ?, ?)
    17.     float4 _ST_WindAnimation;
    18. CBUFFER_END
    Names give some idea, but what is actually packed inside those xyzw?
    I do need to find every variable that sets time to modify it via my own variable instead.

    EDIT:
    Twitch has packed _Time as Z. This is what I was missing.

    Replacing those commented values in shader code will stop time, if passed the Time.time with the accordance to the _Time (time / 20, time, time * 2, time *3).

    Note that those values are approximate, and I don't really know what values are used exactly. To my eye it's pretty close, if not exact.

    Leaves are alterations of 2 variants I think? But passing same time value for them seems to be nice solution. Although, if in doubt - pass additional offset for them.
     
    Last edited: Oct 28, 2018
  2. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    I do not think there is any info about the calculation. It is generated by the hidden "Tree" component on the speedtrees and added to the MaterialPropertyBlock of the Renderer. This happens only when the renderer is visible in a camera.
     
    xVergilx likes this.
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Yeah, I've figured that out. Maybe somebody from UT will shed some light on the parameters. (Somebody did worked on these shaders, right?)

    I've almost figured it out, a bit confused why do they need so many time variables sent, if they simply could use one.
     
  4. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    If you do figure it out it would be great if you could share :)
     
  5. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Found out what I was missing. Twitch has Z as time as well. Updated OP with data for time.

    Replacing those values will stop time, if passed the Time.time with the accordance to the _Time (time / 20, time, time * 2, time *3).

    Note that those values are approximate, and I don't really know what values are used exactly. To my eye it's pretty close, if not exact.

    Rest of the variables are probably packed with the animation / wind direction / tree data, which I don't need to know anyway.
     
    Last edited: Oct 28, 2018
    LennartJohansen likes this.