Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

[Released] Advanced Terrain Grass

Discussion in 'Assets and Asset Store' started by larsbertram1, Sep 11, 2017.

  1. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    1,366
    That explains why it wouldn't show up when looked at with the with the CPU Profiler Module set to show a Hierarchy view set to the Main thread. It still shows up when switching the Hierarchy view to the worker thread; when using Timeline view; or in the Memory Profiler module (as "GC Allocated" or "GC Allocated per frame"). It is still allocating memory monitored by the GC so it can of course lead to GC.Collect kicking in on whichever thread will next try to allocate something. GC.Collect then stops the world, i.e. ALL threads, while it goes over all GCHandles trying to find empty space or allocating a new heap section. I.e. that costs performance, also on the Main Thread, also when using Incremental GC, (albeit possibly less sever in the last case but not because it happened off the main thread).

    Just because allocations happen outside off the main thread doesn't mean there isn't a performance cost to them that can reflect back onto the main thread.
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    just to clearify: it is not a unity worker thread. and i have never seen main thread being blocked or spiking.
     
  3. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    1,366
    What thread is it then? A normal C# thread? That is still using the same GCed memory as the main thread. Unless it's a native plugin's thread, it's all happening in the same shared managed memory and can affect the main thread.
     
  4. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    419
    I've made demo project from scratch. Check your PM for the link.
     
    Last edited: Feb 5, 2021
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    a normal c# Thread
     
    MartinTilo likes this.
  6. D3m0n

    D3m0n

    Joined:
    Nov 11, 2014
    Posts:
    118
    Solved thanks! There remains only the problem that the grass seems to be raised a few centimeters from the ground (also seen in the editor). Is it not possible to set an offset for each type of plant?

    Also checking with the Frame Debugger, I realized that the shaders don't seem to take advantage of the SRP Batching, will this be possible in the future?
     
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    it is but i won't add this in the nearby future, sorry. you could however edit the meshes and lower the vertices a bit relatively to the pivot.
    no :) as it would be way slower. the grass is rendered using darwmeshinstancedindirect which is by magnitudes faster than doing it using srp batcher.
     
  8. kepesh

    kepesh

    Joined:
    Dec 29, 2017
    Posts:
    90
    Is it possible to turn off certain grass prototypes during runtime? I'm making a season change in-game and during winter I only want to have one of the grass prototypes visible.
     
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    there is no such functionality...
    but if you do not have to gain a lot of performance during that season you may just add some kind of null shader to the prototypes you do not want to show up like a shader that degenerates all vertices in the vertex shader.
    alternatively you could change alpha cutoff of the main texture but this will give you less performance gain.
     
  10. kepesh

    kepesh

    Joined:
    Dec 29, 2017
    Posts:
    90
    The null shader could work. Or is it possible to have two grass scripts on the terrain? One with the winter grass and one with the rest of them. So I can turn off and on the entire script.
     
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    no. and it would be a killer!
     
  12. kepesh

    kepesh

    Joined:
    Dec 29, 2017
    Posts:
    90
    It wouldn't be though having one active at a time.
     
  13. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    419
    @larsbertram1, have you checked that test project I've sent you? Can you do something about mono growth? Can I do something about mono growth?
     
  14. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    i had a quick look into it but only in editor.
    mono grows there already regardless if th egrass manager is enabled or not.
    and regardless if the camera moves or not. if any the garss manager would allocate memory if the camera is moving and new cells have to be generated. not if the camera just stands still.
     
  15. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    419
    In a build, with ATG in grows, when you fly around. With default unity grass it doesn't.

    ATG


    NO ATG
     
  16. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    unity grass dos not live in mono land. atg does.
    meanwhile i have checked a build as well: it grows from 50 to 70mb, then drops back to 50.
     
  17. Ali-Nagori

    Ali-Nagori

    Joined:
    Apr 9, 2010
    Posts:
    147
    is there another way to implement Touch Bending effect without the method of @dongliang28 of using the second camera , what i have in mind is array evaluated by the vertex distance from the effected points selected from the global position array

    EDIT: the reason is, that the second camera is not performance-friendly.
     
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    of course you can use an array of points you test against. but this may get expensive quickly if you add more and more points. furthermore if does not allow you to get trails (at least not if you go with something 5-7 points to check against).
     
  19. ysundawa

    ysundawa

    Joined:
    Mar 2, 2020
    Posts:
    15
    hi is there anyone here experience with ATG used for runtime generated terrain? (like MapMagic 2). I have tried to add GrassManager component in runtime but always got this error :

    IndexOutOfRangeException: Index was outside the bounds of the array.
    AdvancedTerrainGrass.GrassManager.DrawGrass () (at Assets/_AdvancedTerrainGrass/_Scripts/GrassManager.cs:1509)
    AdvancedTerrainGrass.GrassManager.LateUpdate () (at Assets/_AdvancedTerrainGrass/_Scripts/GrassManager.cs:358)

    It is only work for Terrain which already available in design time and already attached with GrassManager.
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    converting the internal grass information into data which can be used by atg is rather slow and costly. so i do not recommend to do it at runtime.
     
  21. arminiuskielpecache

    arminiuskielpecache

    Joined:
    Jun 15, 2020
    Posts:
    32
    Hello, this maybe a noob question but how do I have the grass to smoothly appear instead of growing like appearance when going near the grass? Thanks
     
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    this is the way it works... you may however tweak the fade distance so it gets less distracting
     
  23. arminiuskielpecache

    arminiuskielpecache

    Joined:
    Jun 15, 2020
    Posts:
    32
    Thanks, Fade length of 300 I guess works best for me
     
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    that will kill your gpu...
     
  25. arminiuskielpecache

    arminiuskielpecache

    Joined:
    Jun 15, 2020
    Posts:
    32
    But the fps seems stable for me, or the gpu is silently getting butchered? sorry I am new to optimization :(
     
  26. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    f the fps are stable then you should be fine.
     
    arminiuskielpecache likes this.
  27. reggie_sgs

    reggie_sgs

    Joined:
    Jun 29, 2014
    Posts:
    246
    I'm having issues on the PS4 in VR mode (2019.4.16f1 / XR Plugin). The grass flickers when the camera is not aligned with the X axis. If I turn off Compute, the grass no longer flickers but there are missing cells along the Z axis. Changing the instance size has no effect and lower the bucket size when not using Compute makes the missing smaller but they're still missing. The screenshot shows the missing patches with the bucket size set to 4x4. In the videos the bucket size is set to 64x64.

    This video shows the grass jittering.


    This shows the jittering stops when turning off Compute but there are grass patches missing.


    Also, there were 2 build errors but I'm not sure they're related.

    Shader error in 'Wind Visualization X': Fragment program 'frag_surf': struct variable 'AtgGrass' is ignored. only instancing constant buffers can have struct variables
    (on ps4)

    Compiling Fragment program with UNITY_PASS_FORWARDBASE DIRECTIONAL
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_FULL_HDR
    Shader error in 'Hidden/ATG-Internal-DepthNormalsTexture': Vertex program 'vert': struct variable 'AtgGrass' is ignored. only instancing constant buffers can have struct variables
    (on ps4)

    Thanks for any help you can give.
     
    Last edited: Mar 12, 2021
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    hi there,
    i am sorry, but i neither have a ps4 dev kit nor vr...

    flickering when using compute should be caused by the hiZ culling which does not take depth buffers per eye into account. so you should get rifd of this. it is the bottom part of the related compute shader.reach out for me if you need any help.
    the urp version skips hiZ culling if "using URP" is checked. so you may just check this and try without editing the code.

    you can remove the "Wind Visualization X' shader.
    and in case you do not use forward and want to add image effects such as ssao you may also skip the "ATG-Internal-DepthNormalsTexture" shader. otherwise you would have to move all texture declarations outside the cbuffer.
     
  29. reggie_sgs

    reggie_sgs

    Joined:
    Jun 29, 2014
    Posts:
    246
    Hey, thanks for the info. I selected the "Universal Render Pipeline" checkbox but that made no difference. I realized that I had stripped out your demo scripts and remembered a hiZ script which I had removed. I added that back to the camera but again there was no change to the flickering.

    Would you be able to correspond with me on Discord? It might be a quicker way to try things as I suspect this may take some tweaking to get fixed. Thanks!
     
  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    pm sent
     
  31. arminiuskielpecache

    arminiuskielpecache

    Joined:
    Jun 15, 2020
    Posts:
    32
    So I have a camera that switches from one place to another using unity timeline and I noticed that the grass doesn't appear ahead of the time is there a way to work around this? here is the video
     
  32. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    the only way is using burst. and check out the provided demos!
     
    arminiuskielpecache likes this.
  33. arminiuskielpecache

    arminiuskielpecache

    Joined:
    Jun 15, 2020
    Posts:
    32
    Got it thanks
     
  34. arminiuskielpecache

    arminiuskielpecache

    Joined:
    Jun 15, 2020
    Posts:
    32
    Another question, what are does dots on top of the grass? and How do I remove them?
     

    Attached Files:

  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    can you post a better screen shot?
    and do you use simple images as grass?
     
  36. arminiuskielpecache

    arminiuskielpecache

    Joined:
    Jun 15, 2020
    Posts:
    32
    I use images (I set them into sprites)
     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    always a bad idea :) especially when it comes to atg: here any enitiy will be drawn using drawmehinstanced indirect. so we draw a lot of quads... and waste a lot of the wavefront or warp capacities of modern gpus.
    better would be to create small clusters of grass as a mesh with 32 or 64 vertices (anything below will not fully utilize the gpu) and draw less instances.
    coming to the dots: these most likely come from the adjacent grass texture in your sprite atlas. especially when lower mips are sampled.
    so either skip the atlas and go with texture arrays insted.
    or do not use the default quad but assign a custom one where the uvs do not fill the entire 0-1 space but e.g. only 0.1-0.9. this will suppres te dots at least at lower mip levels (when camera is close). they will come back when the gpu samples higher mips tho.
     
  38. arminiuskielpecache

    arminiuskielpecache

    Joined:
    Jun 15, 2020
    Posts:
    32
    ok got it thanks! been figuring this out all day yesterday lol
     
  39. zedz

    zedz

    Joined:
    Aug 31, 2013
    Posts:
    94
    WRT touch bending and the built in pipeline, I just made another RenderTexture in the Wind.cs file and just drew the displayments into that updated each frame and just sampled this texture in the shader to give some extra blending
    seems to work OK
     
  40. arminiuskielpecache

    arminiuskielpecache

    Joined:
    Jun 15, 2020
    Posts:
    32
    Hello, I got a problem with the windzone from ATG. When I play on playmode the wind seems to be at normal speed like 1 for turblance and all that but when I build the game the wind changes to a drastic speed not like the one that I see on play mode. I have a work around on this where I set the wind to the half of the one in playmode in unity but I got eleven scenes and if I keep using my work around I have to build the game every time and I takes a lot of time.
     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    i can not reproduce this but will havw a closer look into it.
     
  42. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    what is your build platform? and do you use the built in render pipeline or urp?
     
  43. arminiuskielpecache

    arminiuskielpecache

    Joined:
    Jun 15, 2020
    Posts:
    32
    upload_2021-4-16_20-16-7.png

    I use the Built-In
     
  44. lilacsky824

    lilacsky824

    Joined:
    May 19, 2018
    Posts:
    85
    Can I copy prototypes setting between Terrain tiles?
    Or I need Get prototypes and setting manually on each terrain tile's Grass Manager when I use multi terrain?
     
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    you have to do it manually, sorry.
     
  46. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    i have no problems at all... but are you sure that the wind is moving faster? maybe the grss is just floating around which could be cuased by unity stripping out the vertex colors in build...
     
  47. lilacsky824

    lilacsky824

    Joined:
    May 19, 2018
    Posts:
    85
    It is fine. :p
    How about direct copy Grass Manager to other terrain's gameobject?
    I tried and seems fine.
     
  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    if so: nice :)
     
    lilacsky824 likes this.
  49. arminiuskielpecache

    arminiuskielpecache

    Joined:
    Jun 15, 2020
    Posts:
    32
    Maybe that is it, if so how is that fixed?
     
  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    actually unity should know about keeping vertex colors if the prefabs assigned to the terrain have a material which uses a shader that looks up vertex colors. but this seems to fail sometimes...

    in order to get around this i can think of 2 different ways:

    brute force:
    - uncheck "optimize mesh data" in the player settings and look into the "vertex compression" settings: color should be unchecked here.
    not really recommended but good for testing and tracking down the issue.

    dummy version:
    add a prefab of each of your grass prototpyes somewhere under the terrain and make sure these prefabs use the atg shaders. when unity goes over the meshes it should detect that these meshes are combined with a shader reading their vertex colors.
     
unityunity