Search Unity

Trees in VR

Discussion in 'AR/VR (XR) Discussion' started by Claytonious, Apr 18, 2017.

  1. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    903
    Has anybody settled on a successful solution for quality trees in VR with Unity?

    The SpeedTree/Unity solution is generally a train-wreck in the first place, but is even worse in VR.

    Unity's native terrain trees work pretty well, but the billboards face the camera and look really strange when the user rotates his head.

    What is everybody else using? Any good tips?

    Thanks.
     
  2. RSH1

    RSH1

    Joined:
    Jul 9, 2012
    Posts:
    256
    Speedtree absolutely kills performance in VR. So far I've found the best thing to do is use low poly tree meshes.
     
  3. Ecocide

    Ecocide

    Joined:
    Aug 4, 2011
    Posts:
    293
    Unity terrain trees would be great, but as you mentioned there is this billboard bug that hasn't been fixed yet (for a long time)... Using low poly tree meshes is fine, but not having a billboard functionality also kills performance. Someone in another thread wrote you should create your own billboards for every tree and use LOD group component to change between mesh and billboard. However, getting a proper billboard with lightning etc. is not that easy.

    It is really not fun atm to setup VR environments with a lot of vegetation in Unity. I just hope they will fix it soon.
     
  4. mindless2831

    mindless2831

    Joined:
    May 15, 2017
    Posts:
    17
    I've been trying to find a solution for awhile now and I think I finally found one. Get a package from PolyPixel like the country side or Lakeside cabin one, they come with many great trees ( country side has more ). They don't have animations for wind, so pair it with the advanced foliage shader. Once you've done that everything looks and works fantastic. I have a 4kmX4km world generated with Gaia with dx11 grass shader using their realistic grass and I have finally hit target fps with a very large amount of trees. Also the billboards are great and work fine since it's not unity trees.
     
  5. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    @mindless2831
    Have you been able to get a large amount of animated grass working in VR? Everything I've tried seem way too expensive.
     
  6. SiliconDroid

    SiliconDroid

    Joined:
    Feb 20, 2017
    Posts:
    302
    I scripted my own billboards that rotate around Y axis to look at cam. I had to optimize for mobile, so all trees are batched quads and managed in a single update loop (each tree does not have its own script), half get managed one frame half the other resulting in trees getting rotation updates at 30Hz. They also have stationary blob shadows and 3D collider approximations. They also make rustling noises when driving into them or scraping past them. I'm happy with them.

     
    Last edited: Jun 24, 2017
  7. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,519
    Terrain Tree billboards are uniquely broken, I think they fixed it for other billboard types. You have to use LOD's and setup a prefab to show at the lowest level instead of billboards.

    The issue has actually always been there. It's an artifact of the billboarding orientation, but its just actually noticeable in VR.
     
  8. JDMulti

    JDMulti

    Joined:
    Jan 4, 2012
    Posts:
    384
    Unity really need to fix this, I see this question popup so many times on the forums. It's insane that while Unity has gotten a money boost several times for VR, this is still an issue. It's unbelievable funny but sad the same time.
     
  9. mindless2831

    mindless2831

    Joined:
    May 15, 2017
    Posts:
    17
    @sbmhome
    Unfortunately I've done away with grass and use the new CTS terrain shader to give normal maps to my grass textures. DirectX11 Grass Shader is the only one that looks decent enough in VR, but it is also way too expensive to render. It can be used in small patches, but until the guy decides to try and optimize it it will never be a large terrain grass solution. Nothing else looks even kind of decent unfortunately.

    As far as billboards go, use Gaia and put non unity terrain trees in with lods ( even billboards ) and they will work perfectly without scripting. It's only unity terrain trees that have the issue that I've found...
     
  10. Grendelbiter

    Grendelbiter

    Joined:
    Oct 14, 2016
    Posts:
    123
    Y'all need to take a look at this asset: https://www.assetstore.unity3d.com/en/#!/content/76657

    Great performance and correct billboarding in VR.

    Oh and shame on Unity for not fixing billboards in VR, SHAME!!! Reflections still don't work either, it's absolute bullshit that they advertise Unity as VR friendly. They're just sitting on their piles of money.
     
  11. shakozzz

    shakozzz

    Joined:
    Mar 1, 2017
    Posts:
    60
    What shader are you using on the trees? I've been using Legacy/Transparent/Cutout/Unlit, but the game starts lagging at a certain number of trees. I'm developing for Gear VR.
     
  12. SiliconDroid

    SiliconDroid

    Joined:
    Feb 20, 2017
    Posts:
    302
    I was using cutout, because I thought it would be faster with less overdraw, but cutout breaks the weird cell batching that mobile GPUs employ.

    So it's faster to use a simple alpha shader, like you I used unlit as my tree textures have baked lighting from approx above. Also try and atlas all your trees into one megatexture.

    I was really suprised how much faster alpha ran than cutout.

    Not sure how many trees you need, but I never put more than 100 of these in any one scene, it could handle more but I am also throwing many other alpha quads around, weapon FX etc. If it was just trees then 200 is fine.

    Also to reduce script cost:

    Manage all trees in one update loop, make a tree manager script for all trees.

    Update each trees yaw every N frames to reduce engine calcs (below is every 4th frame).

    Code (CSharp):
    1.         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    2.         //    UPDATE
    3.         const int K_MOD_FRAMES = 4;
    4.  
    5.         int iMod = 0;
    6.  
    7.         int iTree = 0;
    8.         static Vector3 vLookAt = new Vector3();
    9.         static Vector3 vUp = Vector3.up;
    10.         void Update()
    11.         {
    12.             if (!v.tCamera)
    13.             {
    14.                 if (Camera.main)
    15.                 {
    16.                     v.tCamera = Camera.main.transform;
    17.                 }
    18.                 else
    19.                 {
    20.                     return;
    21.                 }
    22.             }
    23.             vLookAt = v.tCamera.position;
    24.             vLookAt.y = 0.0f;
    25.             iMod = ++iMod % K_MOD_FRAMES;
    26.             for (iTree = iMod; iTree < v.GRP_tBillboards.childCount; iTree += K_MOD_FRAMES)
    27.             {
    28.                 v.GRP_tBillboards.GetChild(iTree).LookAt(vLookAt, vUp);
    29.             }
    30.         }
     
    Last edited: Aug 14, 2017
  13. shakozzz

    shakozzz

    Joined:
    Mar 1, 2017
    Posts:
    60
    Thanks for that! So I'm looking through the list of available shaders and I can't seem to find an "alpha shader" or am I making a really noob mistake?
     
  14. SiliconDroid

    SiliconDroid

    Joined:
    Feb 20, 2017
    Posts:
    302
    Oh yeah I forgot about limited mobile shaders out of the box.

    You'll need a fast alpha shader, here's the one I use, alpha channel must be in texture.

    Save it as "Mobile_UnlitAlpha.shader" anywhere in your project directory.

    It should then be available in available shader dropdown under "SiliconDroid" group.

    Code (CSharp):
    1. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    2. //   ____ ___ _     ___ ____ ___  _   _   ____  ____   ___ ___ ____
    3. //  / ___|_ _| |   |_ _/ ___/ _ \| \ | | |  _ \|  _ \ / _ \_ _|  _ \
    4. //  \___ \| || |    | | |  | | | |  \| | | | | | |_) | | | | || | | |
    5. //   ___) | || |___ | | |__| |_| | |\  | | |_| |  _ <| |_| | || |_| |
    6. //  |____/___|_____|___\____\___/|_| \_| |____/|_| \_\\___/___|____/
    7. //
    8. //    MOBILE: UNLIT WITH ALPHA
    9. //
    10. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    11.  
    12. Shader "SiliconDroid/Mobile_UnlitAlpha"
    13. {
    14.     Properties
    15.     {
    16.         _MainTex ("Main Texture (RGBA)", 2D) = "white" {}
    17.     }
    18.  
    19.     Category
    20.     {
    21.         Tags { "Queue"="Transparent" "RenderType"="Transparent" }
    22.         Blend SrcAlpha OneMinusSrcAlpha
    23.         Lighting Off
    24.          Cull Back
    25.         ZWrite Off
    26.         ZTest LEqual
    27.         Fog { Color (0,0,0,0) }
    28.  
    29.         BindChannels
    30.         {
    31.             Bind "Color", color
    32.             Bind "Vertex", vertex
    33.             Bind "TexCoord", texcoord
    34.         }
    35.  
    36.         SubShader
    37.         {
    38.             Pass
    39.             {
    40.                 SetTexture [_MainTex]
    41.                 {
    42.                     combine texture * primary
    43.                 }
    44.             }
    45.         }
    46.     }
    47.     Fallback "Transparent/Cutout/VertexLit"
    48. }
     
    Last edited: Aug 14, 2017
  15. shakozzz

    shakozzz

    Joined:
    Mar 1, 2017
    Posts:
    60
    This shader is indeed more performant than Legacy/Transparent/Cutout/Unlit. Did you write it yourself or is this available online somewhere?
     
  16. SiliconDroid

    SiliconDroid

    Joined:
    Feb 20, 2017
    Posts:
    302
  17. shakozzz

    shakozzz

    Joined:
    Mar 1, 2017
    Posts:
    60
    Great stuff! Thanks again for the feedback :)
     
  18. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    903
    2017.3 beta 1 release notes include this tantalizing snippet:

    XR: Improved VR Terrain Trees: fixed billboard trees rotating all the time as viewer moves in VR, better transition of 2D to 3D trees, fast "sort-independent" trees with alpha-to-coverage blending and MSAA , billboard texture aliasing improvements (733507, 946544)

    Time to give it a whirl!
     
    pscolto, P_Jong and SiliconDroid like this.
  19. Deleted User

    Deleted User

    Guest

    I'm trying to work with a client that uses Sketchup and a tree library for it. I've been able to import the models in and found that even with a handfull of trees the fps has dropped down to around 20fps using the vive. I even found to the point were if I went from 0 trees to 1 the framerate dropped by half.

    I've been turning off shadows and tried some of these shader options, but I'm not really bringing my framerate up. I also looked at Alt-tree, but the sketchup trees don't really seem to play nicely with that. Any suggestions there?
     
  20. pscolto

    pscolto

    Joined:
    Jul 9, 2017
    Posts:
    4
    Also saw this:

    XR: Fixed billboard trees moving around in VR as viewer moves or rotates. Also fix VR issue of morphing tree vertices "growing" as camera moves closer to trees (733507, 946544)

    Going to try it tonight, have you tried it yet?
     
  21. magg

    magg

    Joined:
    Sep 29, 2013
    Posts:
    74
    Sounds great. It was the reason I killed all my trees and now only using ultra-cheap pine trees here and there.
     
  22. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    I was in the Vegetation Studio beta group. Very nice piece of SDK. With a bit shorter foliage distance it works pretty well. Also make sure to lower shadow distance to 50-75 meters to reduce draw calls
     
    P_Jong likes this.
  23. peardez

    peardez

    Joined:
    Jun 27, 2017
    Posts:
    10
    Hey guys have you tried native speedtrees on VR with Unity 2017.3? I still see the branches rotate along with my point of view....Do I need to do something extra?
     
  24. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    903
    What is Vegetation Studio?
     
  25. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
  26. drakekaz

    drakekaz

    Joined:
    Jan 16, 2014
    Posts:
    43
    Has anyone had any issues with Vegetation Studio? I am trying to create an open world game for VR and Vegetation Studio sounds perfect.
     
  27. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    I tried the beta, it works pretty good, but occlusion culling is crucial and builld a word that does not display too much in a single panorama. I got framedrops with our sniper scopes because they render the game a second time inside the scope, Other than that the framerate seemed pretty solid

     
  28. MichaelSchenck

    MichaelSchenck

    Joined:
    Sep 23, 2011
    Posts:
    49
    Ha! Just saw this thread. I submitted the project for 733507 right after meeting with the Unity devs at Oculus Connect that year trying to get them to do something about the Unity trees in VR. ;)
     
  29. graphicDNA

    graphicDNA

    Joined:
    Jun 26, 2017
    Posts:
    47
  30. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    903
    OK, @iayucar , but this thread is about trees in VR. Your tool is 100% billboards only, correct? That's not going to fly in VR at all.
     
  31. graphicDNA

    graphicDNA

    Joined:
    Jun 26, 2017
    Posts:
    47
    Hi @Claytonious. Our tool uses billboards, yes. But works perfectly well in VR for distant trees. It's not a tool designed for a player walking through trees, or for close-up images of them. It's thought for those trees you need to see in the distance. Cheers.
     
  32. graphicDNA

    graphicDNA

    Joined:
    Jun 26, 2017
    Posts:
    47
    I forgot to mention that Massive Vegetation includes two modes of Billboard's Rotation: one always facing the camera's orientation, what looks awful in VR, and another one always facing the camera's position, what looks much better in VR. Cheers.
     
  33. GoesTo11

    GoesTo11

    Joined:
    Jul 22, 2014
    Posts:
    604
    Has this not been solved yet? I've tried a scene in the last 2017 and 2018 versions and still get the bilboards rotation when I turn my head.
     
  34. sdargiewicz

    sdargiewicz

    Joined:
    Aug 2, 2018
    Posts:
    4
    Same... I thought this was fixed but the billboard rotation is still just as awful when turning my head
     
  35. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    Seriously, one good quality tree is all it takes to grind it down to a halt.
     
  36. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668

    Have you run into any performance issues with CTS + VR?