Search Unity

SRP batcher for speed tree

Discussion in 'General Discussion' started by jetspeed, Mar 31, 2021.

  1. jetspeed

    jetspeed

    Joined:
    Feb 7, 2013
    Posts:
    10
    Hello, I have created a URP VR project using terrain and SpeedTree.
    As the number of trees is veri high, i`m reaching only 40 frm building it (i need 90frm(;'∀'))

    ■SITUATION

    - URP project
    - I have multiple speedtrees objects
    - I have 4 material at list For only one tree
    - | want to reduce the drawcalling with the SRP batcher

    As i am a newbie about modify shaders i ask:

    ■QUESTION

    - To modify the shader that now is not compatible with SRPbatcher
    where do i have to add the script lines?

    - To reduce the draw calls do you have any suggestion combining Atlas texture and speed tree?

    Thanks in advance.
     

    Attached Files:

  2. jetspeed

    jetspeed

    Joined:
    Feb 7, 2013
    Posts:
    10
    this is the shader
     

    Attached Files:

  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    To fix CBUFFER issue - use CBUFFER_START(UnityPerMaterial) and define your shader properties inside it. Like so:
    Code (CSharp):
    1. CBUFFER_START( UnityPerMaterial )
    2.             float4 _ST_WindLeaf1Tumble;
    3.             float4 _HueVariation;
    4.             float4 _ST_WindBranchAnchor;
    5.             float4 _ST_WindVector;
    6.             float4 _Color;
    7.             float4 _ST_WindBranchTwitch;
    8.             float4 _ST_WindLeaf1Twitch;
    9.             float4 _ST_WindLeaf2Ripple;
    10.             float4 _ST_WindLeaf2Tumble;
    11.             float4 _ST_WindBranch;
    12.             float4 _ST_WindBranchWhip;
    13.             float4 _ST_WindLeaf2Twitch;
    14.             float4 _ST_WindGlobal;
    15.             float4 _ST_WindBranchAdherences;
    16.             float4 _ST_WindFrondRipple;
    17.             float4 _ST_WindAnimation;
    18.             float4 _ST_WindTurbulences;
    19.             float4 _ST_WindLeaf1Ripple;
    20.             float _Metallic;
    21.             int _WindQuality;
    22.             int _GlobalTimerId;
    23.             float _Cutoff;
    24.             int _Cull;
    25.             float _Smoothness;
    26.             float4 _EmissionColor;
    27.             float _AlphaCutoff;
    28.             float _RenderQueueType;
    29.             #ifdef _ADD_PRECOMPUTED_VELOCITY
    30.             float _AddPrecomputedVelocity;
    31.             #endif
    32.             float _StencilRef;
    33.             float _StencilWriteMask;
    34.             float _StencilRefDepth;
    35.             float _StencilWriteMaskDepth;
    36.             float _StencilRefMV;
    37.             float _StencilWriteMaskMV;
    38.             float _StencilRefDistortionVec;
    39.             float _StencilWriteMaskDistortionVec;
    40.             float _StencilWriteMaskGBuffer;
    41.             float _StencilRefGBuffer;
    42.             float _ZTestGBuffer;
    43.             float _RequireSplitLighting;
    44.             float _ReceivesSSR;
    45.             float _SurfaceType;
    46.             float _BlendMode;
    47.             float _SrcBlend;
    48.             float _DstBlend;
    49.             float _AlphaSrcBlend;
    50.             float _AlphaDstBlend;
    51.             float _ZWrite;
    52.             float _TransparentZWrite;
    53.             float _CullMode;
    54.             float _TransparentSortPriority;
    55.             float _EnableFogOnTransparent;
    56.             float _CullModeForward;
    57.             float _TransparentCullMode;
    58.             float _ZTestDepthEqualForOpaque;
    59.             float _ZTestTransparent;
    60.             float _TransparentBackfaceEnable;
    61.             float _AlphaCutoffEnable;
    62.             float _UseShadowThreshold;
    63.             float _DoubleSidedEnable;
    64.             float _DoubleSidedNormalMode;
    65.             float4 _DoubleSidedConstants;
    66.             #ifdef TESSELLATION_ON
    67.                 float _TessPhongStrength;
    68.                 float _TessValue;
    69.                 float _TessMin;
    70.                 float _TessMax;
    71.                 float _TessEdgeLength;
    72.                 float _TessMaxDisp;
    73.             #endif
    74.             CBUFFER_END
    You can also take a peek at my shader port via ASE for SpeedTree v6. Here:
    https://github.com/VergilUa/SpeedTreev6HDRP_ASE_Port/blob/master/SpeedTreeHDRP_ASE.shader

    HOWEVER. I'd highly suggest abandoning SpeedTree until actual bugs fixed with Renderer and SRP Batcher.
    At some point you'll run into the dead end - that's because SpeedTree uses submeshes that are supplied to the Renderer.

    And SRP batcher does not support multiple submesh "renderer" / materials.
    This is critical issue, because it will always break batching

    Unfortunately, Unity QA makes this issue completely unreachable for developers to fix (or they just ignore it because they're developing shadergraph alternative, idk really).

    There's also a second major issue - Light Probe incompatibility with SRP batcher.
    If you use them - they will also break batching between objects that are affected by different probes.

    There's two options right now - wait for proper SpeedTree port, and fixes for SRP Batcher (which may take years, due to lazy QA).

    Or abandon SpeedTree and use something else.
    If you don't need wind, and/or are capable of making trees as separate meshes - I'd say go for it.


    Alternative solution would be to use instancing, however, due to black box nature of wind its somewhat problematic to implement.
     
    StenCG, Rewaken, lmbarns and 3 others like this.
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,144
    Rewaken, lmbarns, jeroll3d and 3 others like this.
  5. jetspeed

    jetspeed

    Joined:
    Feb 7, 2013
    Posts:
    10
    thank you for your advices, i will try.

    I`m also trying to find a way to reduce the number of material of speed tree, i searched a lot in the web but seems impossible till the speed tree company don`t change the system.

    i also tried to modify a directly a tree but take too much time to modify all the uv`s..
     
  6. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    That is true.

    SpeedTree wind / uv data / export algorightm also depends on proper submesh order, so separating each submesh as a mesh does not work to full extent.

    That is unless its adjusted correctly, and I haven't found a way to do it unfortunately, because got no clue how internally their wind data is represented during export (its uv data, but the rest is pretty much black box).

    Alternatively, it might be worth a shot to use something like GPU Instancer / Vegetation Studio to bypass pipeline completely and render trees with Indirect Instancing. (But haven't tried that yet)
     
    Last edited: Apr 3, 2021
  7. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    2,198
    I wonder if Lennart have fixed it, in veg studio you can convert speed trees to veg studio trees. I haven't used veg studio in years so don't know how well he supports URP
     
    jetspeed and xVergilx like this.
  8. jeroll3d

    jeroll3d

    Joined:
    Nov 6, 2010
    Posts:
    249
    jetspeed likes this.
  9. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    2,198
    Nature manufacture also have some nice looking stuff atleast for HDRP
     
    jetspeed likes this.
  10. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    So, regarding this issue, it seems to be I was wrong, its not submeshes, but actually Tree component that internally breaks batching. Got this answer from support:
    You won't be able to batch any tree with Tree component as of right now.
     
  11. sqallpl

    sqallpl

    Joined:
    Oct 22, 2013
    Posts:
    384
    SpeedTree is now a part of Unity family. I hope that SpeedTree wind will work with SRP batcher/instancing/hybrid renderer etc. in the future.

    At the moment, as a workaround, we are removing 'Tree' components from our prefabs for all LODs except LOD0. Off course it's not a great solution because it disables wind on them.
     
    Last edited: Aug 3, 2021