Search Unity

Critias Tree System [Asset Store]

Discussion in 'Works In Progress - Archive' started by Assembler-Maze, Oct 21, 2016.

  1. simonjewell

    simonjewell

    Joined:
    May 19, 2016
    Posts:
    24
    I have managed to get the billboards drawing now on Unity 5.6.0f2 - all I needed to do was add "UNITY_VERTEX_INPUT_INSTANCE_ID" to your appdata_t struct in both the billboard batch and master shaders.

    And it's looking good!
    island1.jpg
     
    Alverik and Assembler-Maze like this.
  2. Roni92pl

    Roni92pl

    Joined:
    Jun 2, 2015
    Posts:
    395
    Everything nice and all, but why SlowTree only? Seems very limiting, and by limiting I'm mostly thinking about number of your potential clients.
     
  3. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    10x a bunch, I'll keep it in mind when updating it! I see quite many trees there :)
     
  4. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Cuz' it makes SlowTree fast again :). And it's a free product and it will be free. It is used for a in-development real game (unlike many of the assets out there) and I really don't feel the need of any other vegetation, except the SpeedTree one.

    In the future I'll probs add support for other batched objects, like rocks. And in-development there's also the counterpart grass system.
     
    Alverik and mons00n like this.
  5. marcatore

    marcatore

    Joined:
    May 22, 2015
    Posts:
    158
    Assembler-Maze likes this.
  6. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
  7. simonjewell

    simonjewell

    Joined:
    May 19, 2016
    Posts:
    24
    Well, I may have been a little premature, as that fix only worked (very) occasionally. A better fix was to do this to the billboard batch shader:
    Code (csharp):
    1.  
    2.         #pragma surface surf Standard vertex:BatchedTreeVertex nolightmap addshadow
    3.         #pragma multi_compile_INSTANCING_ON
    4.  
    5.         #if INSTANCING_ON
    6.         #pragma multi_compile_instancing
    7.         #endif
    8.         #pragma target 3.0
    9.  
    10. // stuff removed for brevity
    11.  
    12.         struct appdata_t
    13.         {
    14.             float4 vertex        : POSITION;
    15.             float4 tangent        : TANGENT;
    16.             float3 normal        : NORMAL;
    17.             float4 texcoord        : TEXCOORD0;
    18.             float4 texcoord1    : TEXCOORD1;
    19.             float4 texcoord2    : TEXCOORD2;
    20.             half4 color            : COLOR;
    21. #if INSTANCING_ON
    22.             UNITY_VERTEX_INPUT_INSTANCE_ID
    23. #endif
    24.         };
    25.  
    And billboard master shader:
    Code (csharp):
    1.  
    2.         #pragma surface surf Lambert vertex:TreeVertex nolightmap addshadow
    3.         #pragma multi_compile_INSTANCING_ON
    4.  
    5.         #if INSTANCING_ON
    6.         #pragma multi_compile_instancing
    7.         #endif
    8.  
    9.         #pragma target 3.0
    10.  
    11.         struct appdata_t
    12.         {
    13.             float4 vertex        : POSITION;
    14.  
    15.             float2 texcoord        : TEXCOORD0;
    16.             float2 texcoord1    : TEXCOORD1;
    17.             float2 texcoord2    : TEXCOORD2;
    18.  
    19.             float4 tangent        : TANGENT;
    20.             float3 normal        : NORMAL;
    21. #if INSTANCING_ON
    22.             UNITY_VERTEX_INPUT_INSTANCE_ID
    23. #endif
    24.         };
    25.  
    I then added this code into the GenerateRuntimePrototypeData method:
    Code (csharp):
    1.  
    2.         if (m_Settings.m_UseInstancing) {
    3.             data.m_BillboardBatchMaterial.EnableKeyword("INSTANCING_ON");
    4.             data.m_BillboardMasterMaterial.EnableKeyword("INSTANCING_ON");
    5. #if UNITY_5_6_OR_NEWER
    6.             data.m_BillboardBatchMaterial.enableInstancing = true;
    7.             data.m_BillboardMasterMaterial.enableInstancing = true;
    8. #endif
    9.         }
    10.  
    This was inspired by ElroyUnity's excellent work on uNature, which I hope to integrate soon. The billboards do disappear if I focus off the editor and back again, but it's good progress! And here is another screenshot showing LOADS of billboard trees!
    islandOverdrive2.jpg
     
  8. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Hm... This cant be right, since the batched billboards and master billboards are NOT supposed to be instanced. Actually for the well functioning of the system it is mandatory for their 'instancing' to be turned off. Instancing is used only for the trees nearby. I am using a little more tricky system where the manually batched billboards are organized per grid while the master billboards are only very few each frame (even if you have 100k trees the master billboards are only like 5-10 per frame). In fact those have to have instancing off so that other stuff don't break.

    I'll look into the fix as soon as possible, since I'm sure the fix is required due to the fact that all the shaders have to have that 'instancing' option, but trust me, it will never have to be used with the batched/master billboards. Those use another kind of instancing (old directX 9 style vertex attribute instancing, since dx11 instancing is not a good idea for a ton of small meshes).

    PS: I like that you have a lot of trees in your game, looking forward for live footage :)
     
  9. simonjewell

    simonjewell

    Joined:
    May 19, 2016
    Posts:
    24
    Interesting. This shader stuff is all very new to me, so it may be possible that I don't really know what I am doing :oops:. I did see a 20-30fps increase when using the instancing code though, so it might be worth a little investigation.

    There are about 220k trees on that island (one of 6 in the final game), so yes I rely heavily on your tree system! Hopefully some live footage will be possible soon - the trees look much better in motion!
     
  10. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,891
    In the Treeifier script what is the System Quad supposed to be set to? The docs say that it must be set, but there's no information on what it is or where it comes from.
     
  11. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    I'll see to it, and I'll do some serious profiling. When the scene is not extra full the FPS gain might be more or less relative. I really hope that I'll do it this week, since I'm extra busy, we've almost finished the game's demo and I'm required there :).

    I'll also look into equalizing the lighting of the master/batched billboards so that both use 'Standard'. I can't remember why but I think I had a very good reason for using 'lambert' during that time :).

    Keep up the good work :)
     
  12. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    It is the standard system quad, sorry for not being clear :). Check out the video tutorials too if you feel lost.
     
    Alverik likes this.
  13. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    Placing vegetation over meshes is a BIG bonus, I always needed this. Definitely worth trying.
     
    Alverik and Assembler-Maze like this.
  14. jlink

    jlink

    Joined:
    Jan 8, 2017
    Posts:
    10
    Your package is a lifesaver. We have an rts-style project that we're working on that has lots of trees, and of course speed tree performs the opposite that the name implies. Using your stuff has brought our fps from about 20 up to around 100.

    I have some feedback and a question for you. First, though the LOD transitions seem to be working, the animation only plays the first time the 3D lod trees are instanced. After that they just pop in. Is this how it works or is this a bug? Second, I was trying to disable shadows on our 3D trees from the speed tree prefab, but those settings aren't being carried through to the TreeSystem instances. Looking through the script it looks like you are manually setting the shadow casting mode instead of pulling it from the source. I haven't spent the time to see where you assign that data, but I'm sure its an easy fix.
     
  15. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    If they just pop in then it's a bug. Yes, the LOD transitions are a bit flimsy, (including the LOD dithering) I should improve them too, but, again, I have to use as an excuse the sparse amount of time I have :).

    The tree system shadows are bound to the tree distance, there are not different options for shadow and tree distance, they are liked. The 'mandatory tree shadow distance' is related to shadow popping, and that is a workaround until I have time to correctly fix the shadow caster culling.
     
  16. jlink

    jlink

    Joined:
    Jan 8, 2017
    Posts:
    10
    No problem, I really appreciate the work you've done and shared so far. I don't think you're understanding my second issue though. What I'm trying to do is completely disable shadows on trees by unchecking the "Cast Shadows" checkbox in the LOD settings for the SpeedTree prefab. These settings aren't having an effect and it's because you're setting the shadow casting mode in the TreeSystem script manually (line 974 for example). I'm not sure how accessible the LOD settings are on the SpeedTree prefabs though.
     
  17. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    847
    Hi! This tree system looks really cool, I got some questions to ask about it.
    I'm using MapMagic to generate terrains in runtime, dose this system support runtime generations?
    And can I quickly get individual tree information through this system? like the transform of the tree I'm facing.
    Can I add or reduce trees in runtime in this system?
    hear you soon, cheers!
     
  18. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    You are not supposed to modify prefabs in order to modify the system. The system is 'stand alone' it does not grab it's data from anywhere, and not from the speedtree prefabs. If you uncheck the 'cast shadows' it will have no effect.

    If you wish to disable your tree's shadow you have to browse through the code and search for the 'DrawMesh' and pass in there 'false' to 'draw shadows'. At the moment it is hard-coded to 'true'.

    In the future I'll update it for those cascade trees I've been talking about and you will have shadow distances per-tree prefab along with draw distances per-tree prefab.
     
    Alverik likes this.
  19. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Sorry, the system works at edit time, it does not support the population of trees at runtime. It is modifiable thought, but I do not plan to do that in the near/far future, there are some other priorities at the moment. You can't add/remove individual trees at runtime.

    Getting tree information is possible, try modify the 'collider' script (the one that sets at runtime the collider data). It should provide the trees that are around you, but to see which tree you are facing, you have to write your own custom logic. It is pretty basic math I think.
     
    Alverik likes this.
  20. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    847
    Thanks for the reply!
    I'll see what I can do to integrate these features myself :)
     
    Assembler-Maze likes this.
  21. the3dhermit

    the3dhermit

    Joined:
    Mar 25, 2014
    Posts:
    10
    Hi. Firstly want to thank you for your awesome asset.And ask couple questions.
    I have this error upload_2017-4-14_0-28-58.png
    when I'm using this option upload_2017-4-14_0-28-4.png
    Some problems with Atmospheric Scattering.
    upload_2017-4-14_0-31-38.png
    Not a big problem for me but mb this will be interesting for you.
    And main reason why I'm here.Can you instead turning off default vegetation drawing just set tree distance to 0?
    upload_2017-4-14_0-35-33.png
    Thank you!
     
  22. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    1. I think you are using 5.6, right? I need to update the asset for 5.6 I didn't have the time just yet.
    2. If you use atmospheric scattering you have to modify your shaders to accommodate it. I think in the 'adam' and 'bs' unity demos they had custom standard shaders that support scattering. Not 100% sure though, haven't tried it with scattering.
    3. If you use speedtrees you can't set the tree distance to 0, since unity's system uses data from the speedtree prefab for that data. There is even a warning there for that: "Tree Distance, Billboard Start [...] have no effect on SpeedTrees [...]". If you require a terrain for grass I recommend using 2 terrains, one for grass and one for trees.
     
  23. the3dhermit

    the3dhermit

    Joined:
    Mar 25, 2014
    Posts:
    10
    Thank you for a quick answer.I will try different shades and two terrains method. And waiting for your update :)
     
  24. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    I have updated the system to 5.6, it should be on the asset store shortly.

    If you wish to get it working you need to do the following:

    1. Shader modifications are NOT required
    2. Regenerate your speed tree prefab materials
    3. Delete your speedtree critias system generated data
    4. Regenerate your critias system data (with generate materials)
     
    SyGem, marcatore and Alverik like this.
  25. marcatore

    marcatore

    Joined:
    May 22, 2015
    Posts:
    158
    Great!! Thank you very much
     
  26. bgrz

    bgrz

    Joined:
    Mar 22, 2015
    Posts:
    58
    I'm also having issues with blinking transitions between billboard and lod (tree disappearing for a brief moment). Distance is set to 150, however it's a VR game and these pops are really obvious and distracting. I wanted to look into it so I checked out the github repo and launched BillboardScene.unity, and found the following case which is much worse and seems like it might be related to it:

    https://www.dropbox.com/s/7yo0nkd093dku4z/2017-04-16_21-27-39.mp4?dl=0
    (captured from Critias Tree System commit a3e07a19, Unity 5.5.1f1)

    Hopefully it gives you a bit more insight into the problem.

    Edit: here's a bit more VR-related flickering: https://www.dropbox.com/s/yuh9fd2spg32bu7/2017-04-16_22-23-43.mp4?dl=0
     
    Last edited: Apr 16, 2017
  27. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Yes, the problems are real, but at the moment there are some workarounds.

    1. Use a distance higher than 50M, 50M is kinda low, and the transitions will be very visible
    2. Use a lowers 'mandatory shadow distance' to avoid the shadow popping in the distance

    I really have the second problem in mind for the next update, it is related to the fact that I haven't implemented proper shadow caster culling just yet. There is no built-in function/mechanism in unity to determine if a shadow caster can cast shadows inside the frustum and I'll have to do it manually. 'GeometryUtilitu.TestAABB' is only partly helpfull :)
     
    Alverik likes this.
  28. marcatore

    marcatore

    Joined:
    May 22, 2015
    Posts:
    158
    Could you specify the version of this update?
    The last one I see in the asset store now is 0.9.2. Is it correct for this last update?

    Thanks
     
  29. Pecek

    Pecek

    Joined:
    May 27, 2013
    Posts:
    178
    Is this system works with standard Unity trees as well or SpeedTree only? Hats off for making it free btw.
     
    Assembler-Maze likes this.
  30. No0B25

    No0B25

    Joined:
    May 2, 2016
    Posts:
    69
    SpeedTree only.
     
    Pecek likes this.
  31. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Yes, it's the latest version. Updated it for 5.6 but I haven't changed the version number, forgot to do that sorry :).
     
    Alverik likes this.
  32. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    SpeedTree only, but in the future I plan to make it compatible with detail objects like big-medium rocks, or any other details that you might require.
     
    Pecek, Alverik and SyGem like this.
  33. smonz3

    smonz3

    Joined:
    Jan 9, 2017
    Posts:
    18
    how does this system fare with VR? currently the unity system is more or less broken as the billboards rotate very noticably
     
  34. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Um... I haven't tried it with VR, but you can try it yourself. Just don't set a very large distance at 'mandatory shadows' or you will get some noticeable popping.

    As for the billboard rotation, I have an update planned, so that it doesn't just pop like the unity system, but fade-in very nicely. However at the current time it works like the unity system, the billboard rotation might be quite noticeable when looking at 45° around an object, I'm sorry for that :(

    But the tree-billboard transition is quite good, I think it works somewhat better than the default unity one.
     
    Alverik and marcatore like this.
  35. saarg

    saarg

    Joined:
    Mar 9, 2017
    Posts:
    31
    Great work i manage to ahve it work on one project but i have an issue on another one, only billborads are displayed and the trees closest to the camera are not. There is also a small billboard on the road on this screenshot.
    upload_2017-4-25_11-50-42.png
    not sure what i'm missing...
    upload_2017-4-25_11-55-14.png
    The project is for vr so maybe that's why.
     
  36. marcatore

    marcatore

    Joined:
    May 22, 2015
    Posts:
    158
    Ok. Thank you but is it correct that if I import the updated one, in the import window I don't see any "new" icon?
     
  37. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    I didn't changed any code, so kinda yea... :) The problem was the re-generation of the materials and the tree data.

    Actually, I don't really know why I made this update :). Just updated the new version with Unity 5.6.
     
    Alverik likes this.
  38. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Try it in normal mode and delete the 'Used Camera' leave it to 'null'. Also check and reset the positions of all the system's objects to (0,0,0) and (0,0,0) rotation and (1,1,1) scale. After that check it in VR. If it still doesn't work, don't hesitate to share a project with me.

    Be sure that you watched the tutorial video and generated the tree data correctly.
     
    Alverik and saarg like this.
  39. saarg

    saarg

    Joined:
    Mar 9, 2017
    Posts:
    31
    thanks a lot the issue was the used camera, i have some cameras only used on debug and leaving it null worked!

    I will look at your grass system next
     
  40. rsklnkv

    rsklnkv

    Joined:
    Sep 8, 2012
    Posts:
    59
    Thanks for a great asset, we've switched to Critias after AltTrees and it's a breath of fresh air )))
    But we have 2 problems - we can't use Critias in Editor (Scene View) and it's critical for us - currently we have roughly 5fps in editor with all trees. And second - our Main Camera located in a level which reloaded every time when play loads the game (starts, loads save game, etc), currently right after load Critias spams a lot of messages about missing MeshRenderer, I understand why this happens (it creates trees in Main Camera), is there a way to fix this?

    Thanks!
     
  41. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    The camera creates a lot of trees due to the fact that it requires their wind properties. It uses MPB's 'copy' to get the wind from those owned trees and applying it to the others it draws. Unfortunately there's no other way (at least at the moment) to draw the other's trees wind.

    About the editor... I don't really know at the moment how to fix it properly. One thing i'd try is splitting up the terrain in smaller chunks, have those chunks in different levels and edit them one at the time and only load all the chunks when generating the trees... That's one solution, pretty bad, but it might just work.

    Another (better) solution I thought in implementing is the possibility of having trees in different scenes and loading those scenes only when generating the trees. But that requires extra coding.

    The best solution would be to draw the trees right into my system, but that gives me another problem, it is difficult to convince the 'scene view' to draw your trees in the editor :).

    Unfortunately I don't have time to implement any of those at the moment, due to the fact that I'm finishing our game's demo (which is quite large atm at 4.5x4.5km, and has a lot of trees, and we didn't had problems. how large your world is?) and you are on your own at the moment :(.

    In your place i'd go with the first solution which is the quickest.
     
  42. rsklnkv

    rsklnkv

    Joined:
    Sep 8, 2012
    Posts:
    59
    Currently I made workaround for this - I have special DontDestroyOnLoad object where I attach trees (instead of Camera.main) and I move this object with camera
    Code (csharp):
    1.  
    2.         if (weirdTreeGameObject == null)
    3.         {
    4.             weirdTreeGameObject = new GameObject("weirdTreeGameObject");
    5.             DontDestroyOnLoad(weirdTreeGameObject);
    6.             weirdTreeTransform = weirdTreeGameObject.transform;
    7.         }
    8.  
    9.         // Stick it to the camera
    10.         weirdTree.transform.SetParent(weirdTreeTransform);
    11.  
    That's our current approach - we disable tree rendering in editor on all tiles except one where camera is located, but with AltTrees we were able to have all trees active and keep acceptable framerate :)

    That would be the best option - we use TerrainComposer2 which can output tree data into any system, so if you have simple API, I would be happy to integrate Critias Tree System into TerrainComposer.

    We have ~10x10km with 350k trees, SpeedTree doesn't really work at this numbers ))

    Thanks for a quick reply! :)
     
    Alverik likes this.
  43. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    No probs. I just hope that I'll be able to dig back into this system at some near point in the future :)
     
    Alverik likes this.
  44. rsklnkv

    rsklnkv

    Joined:
    Sep 8, 2012
    Posts:
    59
    One more question - is there a way to "expand" culling to make shadows look better? Currently as soon as tree leaves camera frustum it stops casting shadows.
     
  45. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Yes, make bigger the 'mandatory shadow distance'.
     
  46. rsklnkv

    rsklnkv

    Joined:
    Sep 8, 2012
    Posts:
    59
    you are awesome - haven't even checked this, decided that every system should have it's own cons ))
     
  47. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Nah, even that is a workaround. Just that I haven't got the time to properly take care of shadow caster culling :). But I hope I'll be able, in the near future.
     
  48. Kaktusz

    Kaktusz

    Joined:
    Jan 17, 2015
    Posts:
    8
    Hey there, great work on the system! It was working great in 5.5 but now after I updated to 5.6, it became really glitchy (I did update the asset too). While I fixed most problems by following the previous posts on this page, I'm struggling with this:

    The black quads appeared out of nowhere. It was working at first but after a few days of not opening this scene, the bug started happening. This also happened on the demo scene you provided (I left the scene as it was in 5.5, turned off instancing, and replaced the code with that from the new version). Regenerating/re-extracting doesn't help :/ Any ideas on how this could be fixed? Thanks :)
     
  49. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Hm... I think that it is caused due to the fact that you are using forward rendering maybe? I always used deferred when using the system.
     
  50. rsklnkv

    rsklnkv

    Joined:
    Sep 8, 2012
    Posts:
    59
    I'm having weird issue
    As soon as I get far enough from the place where game is started, I'm loosing my LOD0-LOD3 trees, only billboards are rendered, but as soon as I get close to billboard they disappear and nothing appear instead of them (regular trees should appear). If I move close enough to a place where I started everything works fine

    EDIT: it fails in treesystem.cs at line 651
    Code (csharp):
    1.  
    2. if (culling.IsVisible(cellIdx) == false) continue;
    3.  
    culling.IsVisible always returns false

    EDIT2: I've commented this string out and now everything looks fine, but I have no idea about impact
     
unityunity