Announcement

Collapse
No announcement yet.

How to calculate SpeedTree wind input parameters in Unity?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to calculate SpeedTree wind input parameters in Unity?

    The built in Unity SpeedTree shaders have the following input parameters related to wind:

    CBUFFER_START(SpeedTreeWind)
    float4 _ST_WindVector;
    float4 _ST_WindGlobal;
    float4 _ST_WindBranch;
    float4 _ST_WindBranchTwitch;
    float4 _ST_WindBranchWhip;
    float4 _ST_WindBranchAnchor;
    float4 _ST_WindBranchAdherences;
    float4 _ST_WindTurbulences;
    float4 _ST_WindLeaf1Ripple;
    float4 _ST_WindLeaf1Tumble;
    float4 _ST_WindLeaf1Twitch;
    float4 _ST_WindLeaf2Ripple;
    float4 _ST_WindLeaf2Tumble;
    float4 _ST_WindLeaf2Twitch;
    float4 _ST_WindFrondRipple;
    float4 _ST_WindAnimation;
    CBUFFER_END

    Does anyone know how to manually calculate these?
    I need to calculate them because Unity doesn't do it for Graphics.DrawMesh but I want to use that call to render trees if possible.

  • #2
    Hey there,

    I'm afraid there isn't a way to manually calculate these. They're calculated from parameters you set for the wind inside the SpeedTree Modeler.

    Sorry for the bad news.

    Comment


    • #3
      Hey!

      I would also be interested in this topic. Since we can't access those parameters is there any way to draw animated speedtrees with Graphics.DrawMesh? Any workaround anything? Since I have a lot of 'speedtree' grass in Unity that is drawn based on cell visibility and it is completely impossible to draw it decently in huge quantities as game objects.

      I asked for this since I was helped in the past with some workarounds.

      Thank you very much for your time!

      Comment


      • #4
        Hey John,

        Since we can't access those parameters is there any way to draw animated speedtrees with Graphics.DrawMesh? Any workaround anything?
        I'm afraid not. Again, sorry for the bad news.

        Comment


        • #5
          But if we would expose those parameters in the material and read them back and apply them to another tree, would that be possible?

          Comment


          • #6
            No, those parameters are specific to that tree. Many are packed data that coincides with other data stored in the tree's vertex buffer.

            They also change over time. Most of the wind effects are computed on the CPU and then uploaded to those shader constants. These are the results of the wind effect, not the parameters that govern the wind effect (which are editable on the fan in the SpeedTree Modeler).

            Comment


            • #7
              I see, thank you for the input.

              Comment


              • #8
                By the way, I got some extra data related to a SpeedTree model, some data that I needed when I rolled out my own SpeedTree rendering routines in Unity. SpeedTree was kinda unusable in Unity but with some improvements and support from you guys I managed to get it at a decent FPS (by manually batching the distant billboards and drawing them all in one go. With unity particles it's at 150FPS and with manually batched meshes at 500+FPS for hundreds of thousands of trees).

                But now I've noticed that the extra data also contains the wind data. So my question was, is there any problem if I extract the data from there update it on the CPU and manually update it in the shader from c# code so that we can use 'Graphics.DrawMesh' with a MaterialPropertyBlock? Unreal does that without any problems ('SpeedTreeWind.h' 'SpeedTreeWind.cpp'). And we only need that for meshes imported from SpeedTree that contain all that special vertex data you have mentioned in the previous post, we don't really care about 'winding' anything else, SpeedTree meshes only.

                I really appreciate all support since this is kind of important for us and I do not wish to let it go so easily, since foliage is the last piece of our game.

                Thank you very much!

                P.S: If you are interested you can check out the whole SpeedTree discussion at:
                http://forum.unity3d.com/threads/spe.../#post-2740316

                Comment


                • #9
                  I'd like to enquire further about this. We have built a section of tree that we'd like to repeat many times to draw a bigger structure, but in order to animate it with the SpeedTree shader we'd need to send info in a MaterialPropertyBlock. It would be great if the calculations necessary to do this could be exposed. Are they in the SpeedTree code or in Unity? Just so I know where to enquire further.

                  To be clear, we don't want to calculate our own data for this but merely obtain values that would otherwise be used by the shader under normal circumstances from wind zones etc.

                  Comment

                  Working...
                  X