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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[RELEASED] Vegetation Studio

Discussion in 'Assets and Asset Store' started by LennartJohansen, Jun 23, 2017.

  1. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    862
    You can try to reduce the shadow intensity of your directional light when the sun angle is lower than 10 degrees.
    And lerp it to 0 when the sun angle is 0.
     
    AlwaysBaroque likes this.
  2. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Can you check confirm that you have the latest version? Painting rocks was added then. You can also add rocks manually at the Edit Vegetation tab. There you can also rotate and scale manually in the scene with normal unity handles.
     
  3. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    I think that should work good. As long as the mesh terrain (lods) have the same size it will get the same cell setup and the persistent storage should work with both the mesh and unity terrain.

    Lennart
     
  4. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Is there a node graph in MegaSplat? I did not use it that much. Vegetation Studio has a mega splat control texture mask. This will work with mesh terrain when done.

    Lennart
     
    Ascensi likes this.
  5. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    I can see this happening if you exclude the default layer from the camera. I will make sure the speedtree wind sampler will be on the same layer as you select for the trees.

    Lennart
     
  6. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    GPU culling should affect shadows. Trees currently should be rendered instanced. The test for shadow visibility is done on the CPU. Plan is to move this to the GPU to support instanced indirect trees also. When this happens I think we can increase the distance of invisible trees tested. It is much faster to test this on the GPU.

    On the to-do list but priority now is the mesh terrains.

    That is a nice idea.

    Lennart
     
  7. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    I do not know of any bug with the terrain texture rules. Send me a pm with a screenshot of the exclude rules and I can help you configure.

    Lennart
     
  8. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    488
    Ok, not sure if I get everything.

    All my assets are instance indirect compatible and set like that in VS. Should I change a setting on the render part or just set the culling to CPU (no compute shader + gpu culling) to avoid the shadow rendering issue until an update come out that include culling + shadow testing on the GPU?

    Also, I didn't find a clear information on: What exactly does "Compute shaders" setting and in what conditions it has a performance impact?

    I know that Instanced indirect rendering has a huge positive impact on performances, didn't find it with Compute shaders
     
  9. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    488
    Ah.. I'll be honest and just answer that I won't know how to figure out the Sun angle ;)

    But I like the idea, will try to search about that
     
  10. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi. Instanced indirect does not work properly for trees yet. While you can see them shadow visibility testing does not work on the GPU yet. The main benefits on instanced indirect is for grass and plants. You have a lot more instances of that and it is not limited to the max 1023 items per drawcall that instancing has.

    Since you usually have much less trees the difference is smaller.

    Support for trees will be added in a later update.

    With compute shaders enabled, instanced indirect vegetation will use a compute shader to merge buffers and perform frustum culling before rendering. It also does per item LOD selection on the GPU.

    It is there as a settings for the platforms that does not suppport compute shaders.
    It reduces drawcalls and the number of instances rendered since it can frustum cull partial visible cells.

    Lennart
     
  11. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    488
    Ah ok, it's way clearer now. So I'll use the regular Instanced for Trees until a future update.

    I know it's kind of "cheating" but I was using most of my tall plants (jungle plants) as Trees in VS so they have a billboard and are still visible from far (to avoid popping, which is annoying)
     
  12. Alexanderansoft

    Alexanderansoft

    Joined:
    Jan 5, 2015
    Posts:
    26
    Hi! How activate unity trees and vegetation studio grass together?
     
  13. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    hey! Speedtree vs shader foor 2018.1?
     
  14. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    862
    Quick answer is to use Vector3.Angle. You only need to get the light's backward vector and it's projection vector on XZ plane:
    Sunlight's backward is: - DirectionalLight.transform.forward
    Projection on XZ plane is to set the backward vector's y to 0;
    Then you can use Vector3.angle to get the sun angle. The returned value is always between 0-90.
    You can go further to check the sunlight backward vector's y value, if it's smaller than 0, multiply the sun angle with -1.
    Now you'll get a -90 to 90 degree sunlight angle calculation method ;)
     
    Necka_ likes this.
  15. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    488
    So I moved forward and enabled Instanced indirect only on my compatible grass (from Fantasy Adventure Environment - their shader is VS instance indirect compatible)

    Started to work on my scene lights (realtime point lights)

    When I move my camera towards a light with grass behind I have a huge performance hit, FPS drops to 10, everything freeze quite hard and I got in the profiler a "GFX.WaitForPresent" that goes up to 500ms all the time

    If I turn off Instanced indirect the problem disappear. I tried turning off LOD Instanced indirect only, that didn't fix the issue.
     
  16. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,516
    I've just started checking out Vegetation Studio. The tools are great, well done there!

    I have a couple of questions. For context, my game involves exploring large outdoor environments with fast moving vehicles. So overall I'm less concerned with dense detail up close than I am with handling long distances well.

    1. Is there a performance guide somewhere I've missed? Graphics performance is pretty neat, but Vegetation Studio is eating a lot of CPU time. For instance, "Update Vegetation Instance Lists" commonly takes >2ms per frame on my workstation (particularly with a rotating camera), and my workstation is quite a bit more powerful than my target spec. What kind of things should I look out for to cut down on that?

    (Related: It also allocates >10kb per frame.)

    2. Is there a way to set different distances for different types of objects? For example, I would love to have "Large Objects" visible from kilometers away, while having smaller things only spawn within a few hundred meters. I haven't tried treating these things as trees yet (billboarding them would be great), and notice you do hage additional distances for trees as meshes and billboards.

    3. Where would I look to have my objects appear gradually rather than pop into existence? I'm guessing that I'd look at handling this in the materials for the most distant LODs?


    Thanks very much!
     
    Beennn likes this.
  17. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    580
    Ok, so I worked hard on it and I made it some tests, but the result is not good.
    First of all, I cannot get it to work in deferred mode, as I can't find a way to override the final result (the finalcolor pragma works only in forward mode and the finalgbuffer doesn't do what's needed).
    Second, but most important, if I set the render queue below 2500 (so that I can get self-shadow and DoF working on the trees) even if I set transparency 100% I still get the self-shadow rendered over my character.
    If I set the render queue over 2500 all the trees are treated as transparent objects and look poor (also DoF doesn't work on them).
    Please let me know if there could be another way.

    SpeedTree shader with instance indirect and transparency
    Code (CSharp):
    1.  
    2. // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
    3.  
    4. Shader "Nature/SpeedTree_Transparent"
    5. {
    6.     Properties
    7.     {
    8.         _Color ("Main Color", Color) = (1,1,1,1)
    9.         _HueVariation ("Hue Variation", Color) = (1.0,0.5,0.0,0.1)
    10.         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    11.         _DetailTex ("Detail", 2D) = "black" {}
    12.         _BumpMap ("Normal Map", 2D) = "bump" {}
    13.         _Cutoff ("Alpha Cutoff", Range(0,1)) = 0.333
    14.         _Transparency ("Transparency", Range(0,1)) = 0.6
    15.         [MaterialEnum(Off,0,Front,1,Back,2)] _Cull ("Cull", Int) = 2
    16.         [MaterialEnum(None,0,Fastest,1,Fast,2,Better,3,Best,4,Palm,5)] _WindQuality ("Wind Quality", Range(0,5)) = 0
    17.     }
    18.  
    19.     // targeting SM3.0+
    20.     SubShader
    21.     {
    22.         Tags
    23.         {
    24.             "Queue"="AlphaTest+50"
    25.             "IgnoreProjector"="True"
    26.             "RenderType"="Opaque"
    27.             "DisableBatching"="LODFading"
    28.         }
    29.         LOD 400
    30.         Cull [_Cull]
    31.      
    32.         GrabPass
    33.         {
    34.             "_GrabFondScene"
    35.         }
    36.  
    37.         CGPROGRAM
    38.             #pragma target 3.0
    39.             #pragma surface surf Lambert vertex:SpeedTreeVert finalcolor:alpha nodirlightmap nodynlightmap exclude_path:deferred
    40.          
    41.             //fullforwardshadows
    42.             // dithercrossfade
    43.             #pragma instancing_options assumeuniformscaling maxcount:50 procedural:setup
    44.             #pragma multi_compile_vertex LOD_FADE_PERCENTAGE
    45.             #pragma multi_compile GPU_FRUSTUM_ON __
    46.             #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
    47.             #pragma shader_feature EFFECT_BUMP
    48.             #pragma shader_feature EFFECT_HUE_VARIATION
    49.             #define ENABLE_WIND
    50.             #include "SpeedTreeCommon.cginc"
    51.             #include "VS_indirect.cginc"
    52.  
    53.             sampler2D _GrabFondScene;
    54.             float _Transparency;
    55.          
    56.             void surf(Input IN, inout SurfaceOutput OUT)
    57.             {
    58.                 SpeedTreeFragOut o;
    59.                 SpeedTreeFrag(IN, o);
    60.                 SPEEDTREE_COPY_FRAG(OUT, o)
    61.             }
    62.          
    63.             void alpha(Input IN, SurfaceOutput o, inout fixed4 color) {
    64.                 #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
    65.                     #ifdef GPU_FRUSTUM_ON
    66.                         float on = VisibleShaderDataBuffer[unity_InstanceID].ControlData.x;
    67.                     #else
    68.                         float on = IndirectShaderDataBuffer[unity_InstanceID].ControlData.x;
    69.                     #endif
    70.                 #else
    71.                     float on = 1;
    72.                 #endif
    73.                 half3 diffuseColor = tex2D(_MainTex, IN.mainTexUV).rgb;
    74.              
    75.                 color.rgb = color.rgb * (1 - _Transparency * on) + tex2Dproj( _GrabFondScene, IN.grabUV).rgb * _Transparency * on;          
    76.             }
    77.          
    78.          
    79.         ENDCG
    80.  
    81.         Pass
    82.         {
    83.             Tags { "LightMode" = "ShadowCaster" }
    84.  
    85.             CGPROGRAM
    86.                 #pragma vertex vert
    87.                 #pragma fragment frag
    88.                 #pragma target 3.0
    89.                 #pragma instancing_options assumeuniformscaling maxcount:50 procedural:setup
    90.                 #pragma multi_compile_vertex LOD_FADE_PERCENTAGE LOD_FADE_CROSSFADE
    91.                 #pragma multi_compile GPU_FRUSTUM_ON __
    92.                 #pragma multi_compile_fragment __ LOD_FADE_CROSSFADE
    93.                 #pragma multi_compile_instancing
    94.                 #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
    95.                 #pragma multi_compile_shadowcaster
    96.                 #define ENABLE_WIND
    97.                 #include "SpeedTreeCommon.cginc"
    98.                 #include "VS_indirect.cginc"
    99.  
    100.                 struct v2f
    101.                 {
    102.                     V2F_SHADOW_CASTER;
    103.                     #ifdef SPEEDTREE_ALPHATEST
    104.                         float2 uv : TEXCOORD1;
    105.                     #endif
    106.                     UNITY_DITHER_CROSSFADE_COORDS_IDX(2)
    107.                     UNITY_VERTEX_INPUT_INSTANCE_ID
    108.                     UNITY_VERTEX_OUTPUT_STEREO
    109.                 };
    110.  
    111.                 v2f vert(SpeedTreeVB v)
    112.                 {
    113.                     v2f o;
    114.                     UNITY_SETUP_INSTANCE_ID(v);
    115.                     UNITY_TRANSFER_INSTANCE_ID(v, o);
    116.                     UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
    117.                     #ifdef SPEEDTREE_ALPHATEST
    118.                         o.uv = v.texcoord.xy;
    119.                     #endif
    120.                     OffsetSpeedTreeVertex(v, unity_LODFade.x);
    121.                     TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
    122.                     UNITY_TRANSFER_DITHER_CROSSFADE_HPOS(o, o.pos)
    123.  
    124.                     return o;
    125.                 }
    126.  
    127.                 float4 frag(v2f i) : SV_Target
    128.                 {
    129.                     UNITY_SETUP_INSTANCE_ID(i);
    130.                     #ifdef SPEEDTREE_ALPHATEST
    131.                         clip(tex2D(_MainTex, i.uv).a * _Color.a - _Cutoff);
    132.                     #endif
    133.                     UNITY_APPLY_DITHER_CROSSFADE(i)
    134.                     SHADOW_CASTER_FRAGMENT(i)
    135.                 }
    136.             ENDCG
    137.         }
    138.  
    139.         //GrabPass { }
    140.  
    141.         Pass
    142.         {
    143.             Tags { "LightMode" = "Vertex" }
    144.  
    145.             CGPROGRAM
    146.                 #pragma vertex vert
    147.                 #pragma fragment frag
    148.                 #pragma target 3.0
    149.                 #pragma instancing_options assumeuniformscaling maxcount:50
    150.                 #pragma multi_compile_fog
    151.                 #pragma multi_compile_vertex LOD_FADE_PERCENTAGE LOD_FADE_CROSSFADE
    152.                 #pragma multi_compile_fragment __ LOD_FADE_CROSSFADE
    153.                 #pragma multi_compile_instancing
    154.                 #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
    155.                 #pragma shader_feature EFFECT_HUE_VARIATION
    156.                 #define ENABLE_WIND
    157.                 #include "SpeedTreeCommon.cginc"
    158.  
    159.                 struct v2f
    160.                 {
    161.                     UNITY_POSITION(vertex);
    162.                     UNITY_FOG_COORDS(0)
    163.                     Input data      : TEXCOORD1;
    164.                     UNITY_VERTEX_INPUT_INSTANCE_ID
    165.                     UNITY_VERTEX_OUTPUT_STEREO
    166.                 };
    167.  
    168.                 v2f vert(SpeedTreeVB v)
    169.                 {
    170.                     v2f o;
    171.                     UNITY_SETUP_INSTANCE_ID(v);
    172.                     UNITY_TRANSFER_INSTANCE_ID(v, o);
    173.                     UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
    174.                     SpeedTreeVert(v, o.data);
    175.                     o.data.color.rgb *= ShadeVertexLightsFull(v.vertex, v.normal, 4, true);
    176.                     o.vertex = UnityObjectToClipPos(v.vertex);
    177.                     UNITY_TRANSFER_FOG(o,o.vertex);
    178.                     return o;
    179.                 }
    180.  
    181.                 fixed4 frag(v2f i) : SV_Target
    182.                 {
    183.                     UNITY_SETUP_INSTANCE_ID(i);
    184.                     SpeedTreeFragOut o;
    185.                     SpeedTreeFrag(i.data, o);
    186.                     UNITY_APPLY_DITHER_CROSSFADE(i.vertex.xy);
    187.                     fixed4 c = fixed4(o.Albedo, o.Alpha);
    188.                     UNITY_APPLY_FOG(i.fogCoord, c);
    189.                     return c;
    190.                 }
    191.             ENDCG
    192.         }
    193.     }
    194.  
    195.     // targeting SM2.0: Cross-fading, Normal-mapping, Hue variation and Wind animation are turned off for less instructions
    196.     SubShader
    197.     {
    198.         Tags
    199.         {
    200.             "Queue"="Geometry"
    201.             "IgnoreProjector"="True"
    202.             "RenderType"="Opaque"
    203.             "DisableBatching"="LODFading"
    204.         }
    205.         LOD 400
    206.         Cull [_Cull]
    207.  
    208.         CGPROGRAM
    209.             #pragma surface surf Lambert vertex:SpeedTreeVert nodirlightmap nodynlightmap noshadowmask
    210.             #pragma multi_compile  LOD_FADE_PERCENTAGE
    211.             #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
    212.             #include "SpeedTreeCommon.cginc"
    213.             #pragma target 3.0
    214.  
    215.             void surf(Input IN, inout SurfaceOutput OUT)
    216.             {
    217.                 SpeedTreeFragOut o;
    218.                 SpeedTreeFrag(IN, o);
    219.                 SPEEDTREE_COPY_FRAG(OUT, o)
    220.             }
    221.         ENDCG
    222.  
    223.         Pass
    224.         {
    225.             Tags { "LightMode" = "ShadowCaster" }
    226.  
    227.             CGPROGRAM
    228.                 #pragma vertex vert
    229.                 #pragma fragment frag
    230.                 #pragma multi_compile  LOD_FADE_PERCENTAGE
    231.                 #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
    232.                 #pragma multi_compile_shadowcaster
    233.                 #include "SpeedTreeCommon.cginc"
    234.  
    235.                 struct v2f
    236.                 {
    237.                     V2F_SHADOW_CASTER;
    238.                     #ifdef SPEEDTREE_ALPHATEST
    239.                         float2 uv : TEXCOORD1;
    240.                     #endif
    241.                 };
    242.  
    243.                 v2f vert(SpeedTreeVB v)
    244.                 {
    245.                     v2f o;
    246.                     #ifdef SPEEDTREE_ALPHATEST
    247.                         o.uv = v.texcoord.xy;
    248.                     #endif
    249.                     OffsetSpeedTreeVertex(v, unity_LODFade.x);
    250.                     TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
    251.                     return o;
    252.                 }
    253.  
    254.                 float4 frag(v2f i) : SV_Target
    255.                 {
    256.                     #ifdef SPEEDTREE_ALPHATEST
    257.                         clip(tex2D(_MainTex, i.uv).a * _Color.a - _Cutoff);
    258.                     #endif
    259.                     SHADOW_CASTER_FRAGMENT(i)
    260.                 }
    261.             ENDCG
    262.         }
    263.  
    264.         Pass
    265.         {
    266.             Tags { "LightMode" = "Vertex" }
    267.  
    268.             CGPROGRAM
    269.                 #pragma vertex vert
    270.                 #pragma fragment frag
    271.                 #pragma multi_compile_fog
    272.                 #pragma multi_compile  LOD_FADE_PERCENTAGE
    273.                 #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
    274.                 #include "SpeedTreeCommon.cginc"
    275.  
    276.                 struct v2f
    277.                 {
    278.                     float4 vertex    : SV_POSITION;
    279.                     UNITY_FOG_COORDS(0)
    280.                     Input data        : TEXCOORD1;
    281.                     UNITY_VERTEX_OUTPUT_STEREO
    282.                 };
    283.  
    284.                 v2f vert(SpeedTreeVB v)
    285.                 {
    286.                     v2f o;
    287.                     UNITY_SETUP_INSTANCE_ID(v);
    288.                     UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
    289.                     SpeedTreeVert(v, o.data);
    290.                     o.data.color.rgb *= ShadeVertexLightsFull(v.vertex, v.normal, 2, false);
    291.                     o.vertex = UnityObjectToClipPos(v.vertex);
    292.                     UNITY_TRANSFER_FOG(o,o.vertex);
    293.                     return o;
    294.                 }
    295.  
    296.                 fixed4 frag(v2f i) : SV_Target
    297.                 {
    298.                     SpeedTreeFragOut o;
    299.                     SpeedTreeFrag(i.data, o);
    300.                     fixed4 c = fixed4(o.Albedo, o.Alpha);
    301.                     UNITY_APPLY_FOG(i.fogCoord, c);
    302.                     return c;
    303.                 }
    304.             ENDCG
    305.         }
    306.     }
    307.  
    308.     FallBack "Transparent/Cutout/VertexLit"
    309.     CustomEditor "SpeedTreeMaterialInspector"
    310. }
    311.  
    I had to change also the vertex function to get the uv for the GrabPass.
    SpeeTreeCommon.cginc
    Code (CSharp):
    1.  
    2. // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
    3.  
    4. #ifndef SPEEDTREE_COMMON_INCLUDED
    5. #define SPEEDTREE_COMMON_INCLUDED
    6.  
    7. #include "UnityCG.cginc"
    8.  
    9. #define SPEEDTREE_Y_UP
    10.  
    11. #ifdef GEOM_TYPE_BRANCH_DETAIL
    12.     #define GEOM_TYPE_BRANCH
    13. #endif
    14.  
    15. #include "SpeedTreeVertex.cginc"
    16.  
    17. // Define Input structure
    18.  
    19. struct Input
    20. {
    21.     fixed4 color;
    22.     half3 interpolator1;
    23.     #ifdef GEOM_TYPE_BRANCH_DETAIL
    24.         half3 interpolator2;
    25.     #endif
    26.     float4 grabUV;
    27. };
    28.  
    29. // Define uniforms
    30.  
    31. #define mainTexUV interpolator1.xy
    32. sampler2D _MainTex;
    33.  
    34. #ifdef GEOM_TYPE_BRANCH_DETAIL
    35.     #define Detail interpolator2
    36.     sampler2D _DetailTex;
    37. #endif
    38.  
    39. #if defined(GEOM_TYPE_FROND) || defined(GEOM_TYPE_LEAF) || defined(GEOM_TYPE_FACING_LEAF)
    40.     #define SPEEDTREE_ALPHATEST
    41.     fixed _Cutoff;
    42. #endif
    43.  
    44. #ifdef EFFECT_HUE_VARIATION
    45.     #define HueVariationAmount interpolator1.z
    46.     half4 _HueVariation;
    47. #endif
    48.  
    49. #if defined(EFFECT_BUMP) && !defined(LIGHTMAP_ON)
    50.     sampler2D _BumpMap;
    51. #endif
    52.  
    53. fixed4 _Color;
    54.  
    55. // Vertex processing
    56.  
    57. void SpeedTreeVert(inout SpeedTreeVB IN, out Input OUT)
    58. {
    59.     UNITY_INITIALIZE_OUTPUT(Input, OUT);
    60.  
    61.     OUT.mainTexUV = IN.texcoord.xy;
    62.     OUT.color = _Color;
    63.     OUT.color.rgb *= IN.color.r; // ambient occlusion factor
    64.  
    65.     #ifdef EFFECT_HUE_VARIATION
    66.         float hueVariationAmount = frac(unity_ObjectToWorld[0].w + unity_ObjectToWorld[1].w + unity_ObjectToWorld[2].w);
    67.         hueVariationAmount += frac(IN.vertex.x + IN.normal.y + IN.normal.x) * 0.5 - 0.3;
    68.         OUT.HueVariationAmount = saturate(hueVariationAmount * _HueVariation.a);
    69.     #endif
    70.  
    71.     #ifdef GEOM_TYPE_BRANCH_DETAIL
    72.         // The two types are always in different sub-range of the mesh so no interpolation (between detail and blend) problem.
    73.         OUT.Detail.xy = IN.texcoord2.xy;
    74.         if (IN.color.a == 0) // Blend
    75.             OUT.Detail.z = IN.texcoord2.z;
    76.         else // Detail texture
    77.             OUT.Detail.z = 2.5f; // stay out of Blend's .z range
    78.     #endif
    79.  
    80.     OffsetSpeedTreeVertex(IN, unity_LODFade.x);
    81.  
    82.     float4 grabUV = ComputeGrabScreenPos(UnityObjectToClipPos(IN.vertex));
    83.     OUT.grabUV = grabUV;
    84. }
    85.  
    86. // Fragment processing
    87.  
    88. #if defined(EFFECT_BUMP)
    89.     #define SPEEDTREE_DATA_NORMAL           fixed3 Normal;
    90.     #define SPEEDTREE_COPY_NORMAL(to, from) to.Normal = from.Normal;
    91. #else
    92.     #define SPEEDTREE_DATA_NORMAL
    93.     #define SPEEDTREE_COPY_NORMAL(to, from)
    94. #endif
    95.  
    96. #define SPEEDTREE_COPY_FRAG(to, from)   \
    97.     to.Albedo = from.Albedo;            \
    98.     to.Alpha = from.Alpha;              \
    99.     SPEEDTREE_COPY_NORMAL(to, from)
    100.  
    101. struct SpeedTreeFragOut
    102. {
    103.     fixed3 Albedo;
    104.     fixed Alpha;
    105.     SPEEDTREE_DATA_NORMAL
    106. };
    107.  
    108. void SpeedTreeFrag(Input IN, out SpeedTreeFragOut OUT)
    109. {
    110.     half4 diffuseColor = tex2D(_MainTex, IN.mainTexUV);
    111.  
    112.     OUT.Alpha = diffuseColor.a * _Color.a;
    113.     #ifdef SPEEDTREE_ALPHATEST
    114.         clip(OUT.Alpha - _Cutoff);
    115.     #endif
    116.  
    117.     #ifdef GEOM_TYPE_BRANCH_DETAIL
    118.         half4 detailColor = tex2D(_DetailTex, IN.Detail.xy);
    119.         diffuseColor.rgb = lerp(diffuseColor.rgb, detailColor.rgb, IN.Detail.z < 2.0f ? saturate(IN.Detail.z) : detailColor.a);
    120.     #endif
    121.  
    122.     #ifdef EFFECT_HUE_VARIATION
    123.         half3 shiftedColor = lerp(diffuseColor.rgb, _HueVariation.rgb, IN.HueVariationAmount);
    124.         half maxBase = max(diffuseColor.r, max(diffuseColor.g, diffuseColor.b));
    125.         half newMaxBase = max(shiftedColor.r, max(shiftedColor.g, shiftedColor.b));
    126.         maxBase /= newMaxBase;
    127.         maxBase = maxBase * 0.5f + 0.5f;
    128.         // preserve vibrance
    129.         shiftedColor.rgb *= maxBase;
    130.         diffuseColor.rgb = saturate(shiftedColor);
    131.     #endif
    132.  
    133.     OUT.Albedo = diffuseColor.rgb * IN.color.rgb;
    134.  
    135.     #if defined(EFFECT_BUMP)
    136.         #if defined(LIGHTMAP_ON)
    137.             OUT.Normal = fixed3(0,0,1);
    138.         #else
    139.             OUT.Normal = UnpackNormal(tex2D(_BumpMap, IN.mainTexUV));
    140.             #ifdef GEOM_TYPE_BRANCH_DETAIL
    141.                 half3 detailNormal = UnpackNormal(tex2D(_BumpMap, IN.Detail.xy));
    142.                 OUT.Normal = lerp(OUT.Normal, detailNormal, IN.Detail.z < 2.0f ? saturate(IN.Detail.z) : detailColor.a);
    143.             #endif
    144.         #endif
    145.     #endif
    146. }
    147.  
    148. #endif // SPEEDTREE_COMMON_INCLUDED
    149.  
    150.  
     
  18. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    580
    I was also thinking about another possible solution. To completely clip the tree that is over the character (so do don't render it at all) and replace it with a standard tree prefab that will have the transparent shader. This way I could set the queue over 2500 just for this tree.
    But I don't know how to match the shader data with the Runtime Prefab Spawner so that it will clip just the tree that will be spawned.
     
  19. kepesh

    kepesh

    Joined:
    Dec 29, 2017
    Posts:
    92
    Is there any performance tests made with VS vs the build in grass or other plugins? Both on builds and in editor.
    It would be great to see some stress tests like they did for Microsplat:


    I'm asking because I'm working on a pretty big scene and it's getting to a point where it's not possible to navigate the scene because of the lag from VS. I have a lot of vegetation items but very low render distance and I'm using a GTX 1080ti.
    It's a bit better when I bake the vegetation but that takes time to do every time I update something. I've tried using instanced indirect and instanced.

    When I use the build in grass with AFS it's super fast but some hiccups every now and then, but that doesn't have the touch react function or adapts to the terrain angle.

    I really love this plugin and all it's features and I hope it's just me that has these problems.
     
  20. Necka_

    Necka_

    Joined:
    Jan 22, 2018
    Posts:
    488
    I tried for fun to put around 6 different trees, 5 plants and 3 grass with no filter, so completely filling the map. I never dropped under 50fps on my GTX 1080ti average around 70

    With reasonable amount of vegetation I'm around 200. I'm trying to keep those numbers that high for when I implement the rest of the scene (AI, particles and so on). I have to disable the Profiler in the editor because it oddly drop FPS by 100...

    All my vegetation is Instanced and Instanced indirect. 350 of rendering distance, Compute shaders and GPU Culling.

    My main FPS issues (where it was not playable) was because of reflection (from Aquas mostly). had to remove the vegetation from being reflected by my water and the different projectors I have in my scene (aquas and others)
     
  21. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi. sending you a pm, lets see what is taking time for you in editor mode.

    Lennart
     
  22. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi. Sending you a pm for some more info, lets see what is happening...
     
  23. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi again. Saw you shader post also. The indirect implementation seems correct. For the transparency isseues I do not know the shader good enough to have any input without actually testing...

    Lets look at options in a private chat and post results here if we find a good system others could benefit from.

    Lennart
     
  24. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    The one in github for 2017.3 does not work in 2018.1? I did not test it yet.

    Lennart
     
  25. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    By default Vegetation Studio disables the trees and details on the Unity Terrain. Nothing is deleted, just the drawing turned of. There is a setting on the settings tab of the VegetationSystem component you can disable. Then go the settings on the unity terrain and enable the checkboxes for trees and/or details.

    Lennart
     
  26. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    Nope, I can see the grass but the wind dosent work...
     
  27. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    I also get this error.. Probably not speedtree issue because it says something about aquas...

    Unable to add Renderer to the Scene after Culling.

    Possible cause: A Camera callback, such as OnPreRender, called Graphics.DrawMesh.
    Solution: If this is the cause, move the callback to earlier in the frame, to in OnPreCull, for example.
    UnityEngine.Graphics:DrawMeshInstanced(Mesh, Int32, Material, List`1, MaterialPropertyBlock, ShadowCastingMode, Boolean, Int32, Camera, LightProbeUsage)
    AwesomeTechnologies.VegetationSystem:DrawVegetation() (at Assets/AwesomeTechnologies/VegetationStudio/VegetationSystem/VegetationSystem.cs:2016)
    AwesomeTechnologies.VegetationSystem:ExecuteRenderVegetation(Boolean) (at Assets/AwesomeTechnologies/VegetationStudio/VegetationSystem/VegetationSystem.cs:1828)
    AwesomeTechnologies.VegetationSystem:OnRenderObject() (at Assets/AwesomeTechnologies/VegetationStudio/VegetationSystem/VegetationSystem.cs:1691)
    UnityEngine.Camera:Render()
    AQUAS_Reflection:OnWillRenderObject() (at Assets/AQUAS/Scripts/AQUAS_Reflection.cs:100)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
     
  28. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    It looks like something changed in Unity 2018.1. I need to test and see what is happening. I have an idea of what might be wrong. Does this error happen in playmode and builds also?

    Lennart
     
  29. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    yes it does
     
  30. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    1. Update vegetation lists is preparing the instances of the currently visible internal cells. This is only done for instanced vegetation. When rendering instanced indirect the buffers are merged on the GPU before rendering.
    In order to reduce this try to get your rocks, plants and grass to render instance indirect.

    Here is a guide to update shaders to support it.

    There is a GC allocation for starting threads in Unity. There is a non multithreaded version of the "Update Vegetation Instance Lists" you can enable to get rid of this. With more items rendering instanced indirect this could be an option.

    2. There is currently 2 distances, Vegetation distance that is grass, plants and objects, and an additonal mesh distance that is added to this. This is used with large objects and trees. Trees also have billboards after this.

    You can add a rock as a tree and get billbording but the rotation needs to be set to rotate around Y axis. Billboards does not tilt....

    I am looking at adding an option to reduce the distance of individual trees and large objects. This will only be implemented on instanced indirect. To slow to test all on the CPU. With indirect and a compute shader it can be done as a pass on the GPU before rendering.

    3. You could add some kind of fade to the shader used on the last LOD. The distances are available from the VegetationSystem and you could fade out.

    From 2018.1 we can inject the Unity_LODFade variable while rendering instanced. I will try to get this calculated automatic for shaders that implement the unity dither fade.

    Lennart
     
    Beennn and angrypenguin like this.
  31. Cubic_Creo

    Cubic_Creo

    Joined:
    Oct 13, 2014
    Posts:
    47
    I'm having a problem getting VS to work with a large set of terrains without major FPS drops. I have a set of 8 x 8 terrain tiles (64 terrains total, and 4097x4097 meters each). I'm using World Streamer to load the terrains in and out. Without VS I have around 90 FPS all the time, even as I fly very fast (200 meters/second) across the terrain.

    I've added a Vegetation System as a child of each terrain in the World Streamer "work" scene, and assigned the appropriate terrain to each.

    When I start the game, FPS drops to about 2 FPS for around 10 seconds as World Streamer loads in the initial terrain scenes. There is no FPS drop without VS. Then if I try to fly across the terrain, there is an FPS drop down to around 2 FPS again every time new terrain scenes get loaded in. Once the loading is complete, FPS goes back up to 90.

    I've disabled billboard preloading around the camera, since the profiler showed that as a major bottleneck. I'm not sure what else to do, though. Here's a screenshot of what I see in the profiler. Obviously there's some overhead from the profiler itself, but this seems to be where it's getting hung up. Any suggestions?

    profiler.png
     
  32. StevanJay

    StevanJay

    Joined:
    Feb 5, 2014
    Posts:
    79
    Hello! I'm just starting to investigate what I can do with VS... My scene has trees with very different sizes, and it doesn't really make sense to have them all start billboarding at the same distance - is there any way to change the distances that billboarding starts on a per-tree basis...??

    Thx! :)
     
  33. Casanuda

    Casanuda

    Joined:
    Dec 29, 2014
    Posts:
    53


    Hi,

    Not sure if you missed this reply.

    Thanks
    Cas
     
  34. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi. I am out of the office today, but I will answer messages when I am back tomorrow.

    Lennart
     
  35. Pecek

    Pecek

    Joined:
    May 27, 2013
    Posts:
    187
    During the sale I finally picked up VS, holy S*** this asset is awesome! :D I have a few questions though.
    Is it possible to use billboards for objects other than trees? Like the "large objects" for example. If so how, or will this feature be available in the future?
    For some reason only SpeedTrees have billboards, why is that? I mean, VS has a custom billboard solution, the billboards are clearly generated but don't show up in the scene at all.
    Is there a demo for the touch react system? I read the manual but I can't make it work with moving objects.
    Is there\will be a template for ASE to make custom shader creation easier?

    About performance.
    Is it possible to disable the colliders in the scene view?(other than collapsing the component on the prefab) Also what about convex colliders, will it be possible in the future to generate convex meshes(or at least specify one by hand)?
    When the editor is running in the background (or even if it's minimized) my GPU is working at 100% unless I manually disable VS, is this normal?
     
  36. p87

    p87

    Joined:
    Jun 6, 2013
    Posts:
    318
    where can i find the information regarding how vegetation studio now works with gaia? thanks
     
  37. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,445
    There's actually two different procedural texturing systems in MegaSplat. One is a node-graph based solution, which should work fine with whatever ruleset VS uses since it's just doing the "paint job" for you. The other is executed at runtime in the vertex shader, and the data wouldn't be available to VS in that mode since it's done entirely in the shader.
     
  38. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi.

    Using Vegetation Studio with Gata is not complex. Gaia stamps and textures terrains. This is normal Unity terrains and will work direct with Vegetation Studio.

    If you want you can import Terrain Trees to the persistent storage. Have a look here.

    I would start with the getting started video on Youtube. You find links on the website.

    Lennart
     
  39. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi. There is some options to load faster setting up a pool of vegetation systems and hotswaping the terrains.
    Sending you a pm, we can look at your setup.

    Lennart
     
  40. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi. You can not do that now. Right now we benefit of fast distance culling using the DistanceBand functionality of the CullingGroups API.

    But when I get the next step of instanced indirect support for trees done we should be able to do this. Per instance distance tests will be fast on the GPU.

    It is on my requested features list.

    Lennart
     
    StevanJay likes this.
  41. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Yes. Missed it. A lot of messages sometimes. Sent you a pm (private message)

    Lennart
     
  42. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi.

    1. Per now billboards are restricted to trees. You can add any prefab as a tree. Most should billboard good but there is a limit on rotation. Billboards only rotate around the Y axis.

    2. All trees should billboard. If you have a custom shader with color tint or some other we might have to make a custom atlas render shader but most work direct. What tree did not work for you? send me a pm with info and I can look at it.

    3. There is no demo, on my list to write a better guide but not got there yet. Busy days. The car example you see in the video on the website is made using trail renderers on the wheels. They are using a material called touch react in the project and render only to the layer set on the touch react component. I did a post on this some weeks ago.

    4. I do not think you can make custom templates for surface shaders in ASE?
    There is a small guide here and the extra files you need to support instanced indirect in ASE shaders.
    Have a look here

    there is also an included node that helps you add touch react to grass/plant shaders. Simple to use. vertex position in and out.

    5. There is an option on the Editor tab to hide colliders in the sceneview.
    for colliders there is an option on the colliders setting on each vegetation item where you can assign custom meshes. or create automatic mesh colliders.

    6. For the GPU use. try disabling the animated materials on the sceneview top bar. in the dropdown menu there.

    Lennart
     
  43. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,238
    I am wondering if something changed with VS recently. I did a bunch of testing in December and found good performance on my Mac. But now it's much worse. In the basic VS Demo scene (grass, no trees):

    • I get about 38 fps (initial camera view).
    • If I slide all the density sliders to zero, I get 65 fps.
    • If I disable VS entirely, I get well over 200 fps.

    So that seems pretty weird, right? I'm using Unity 2017.4 on Mac High Sierra with a Radeon 580. (Unfortunately the profiler only says "Gfx.WaitForPresent" because the stupid GPU profiler doesn't work on Metal.) I'm sure I got around 100 fps in December with Radeon 560 -- and that was with trees.
     
  44. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    I have a large world that is zoned in a way where I only have a single terrain active at once. I don't use scenes for zones but instead use an approach of only load/reload what is actually necessary. Ie I will often reuse object instances and just reconfigure and reload what is necessary. So the loading time between these virtual zones is very fast.

    It seems likely I can use the same approach with VS. Reuse the same instance and reload it with new data. I don't know how much this would actually save me though (beyond the obvious object instantiation) and that is the main question. One caveat is that I have runtime spawning disabled on everything. I use vegetation storage packages.
     
  45. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    862
    Here I got another question: I'm using mapmagic to paint my terrain, and I found that VS also tries to paint the terrain, it sometimes overrides the actual texture from mapmagic's result (executed later than MM I assume).
    How do I disable the terrain texturing function of VS if I'm using other methods to paint the terrain?
     
  46. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Ok so I sorted this out seems to work just fine. Use a single VS instance with all vegetation types configured in it. Then a storage package per terrain with just the types wanted for that terrain baked. Switching both terrains and storage packages at runtime works well minimal performance hit.
     
  47. mzylak

    mzylak

    Joined:
    Jan 14, 2016
    Posts:
    8
    I have another bugs.
    In our project we are using dynamic multiple cameras, so every time when new Camera is added to the scene, we clone VegetationSystem GameObject, set new Camera to VegetationSystem and turn ON Render only to selected camera option.
    Firstly, there is a huge problem with multiple cameras, when Use Compute shaders is ON - one view totally depends on another.
    Secondly, even when Use Compute shaders is OFF, the billboards from one camera are shown in the same place as the 3D Trees from second camera.
     
  48. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    That does sound a bit strange. I guess the compute shaders still run for all the vegetation items. It does not know that the cell/compute buffers are empty. Setting density to 0 is not something I considererd using run-time since you can disable the rendering itself with setting RenderVegetation to false...

    Anyway I plan to buy a proper development imac for testing and debuging in 3 weeks. Just do not want to buy direct before the Apple development conference. seems like they will upgrade the imacs then.

    I will find out what is happening then.
     
    mons00n and Lars-Steenhoff like this.
  49. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    There is a HotSwap terrain function on the VegetationSystem component. This will allow you to assign a new terrain to it. It has to be the same size. This will re-use the internal cell structure and quadtree saving you some init time.

    Lennart
     
  50. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Nice I had missed that, thanks!