Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Critias Tree System [Asset Store]

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

  1. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Yes, I'll look into that too. Already partly solved the shadow popping issue + placing objects on non-terrain stuff. But, as always, things not going as planned, need more time :)
     
    Last edited: Dec 24, 2016
    No0B25 likes this.
  2. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    304
    Is this script in the repo? If not would you mind sharing it? Thanks!
     
  3. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    It's a huge mess, but I'll share it the next update.
     
    mons00n likes this.
  4. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    756
    Quick question about your system: Because my current prototype is using a pseudo-isometric view, I need a see-through shader that makes characters and important obejcts visible through big obstacles obscuring the view... like trees.
    I have written a special shader for that, but because of the limitations of how the speedtree models are set up, and me using the deferred renderer, I need to duplicate the tree and render a second speedtree object with this shaders attached.

    Can your system also use a prefab which contains both these speedtree objects? Thus, could it spawn trees which consist of two speedtree objects spawned at the same location, with different shaders?
     
  5. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Hm... As a better solution, wouldn't you want to modify the existing tree shader (I even think that there's a code snippet for dithered transparency around there) to make the trees more transparent based on your criteria? I would recommend that instead of rendering 2 trees on top of each other, which is, I think, a bad idea since the tree underneath will still be visible.
     
  6. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    ! Update !

    Based on used input and test, I've made a few improvements to the system.

    - Partly fixed tree shadow popping. Will need more time to solve this 100% correctly but it is fine at the moment and the popping goes away. Use the 'Apply Shadow Popping Correction' setting in the settings
    - Painting trees on non-terrains like placing them on cliffs, houses etc. However, they will need to be in the context of a terrain cell. Use an GameObject that owns trees that are in the managed prototype (see the BillboardTest scene from the gihub repo for a demo)
    - Being able to completely remove the terrains after you generate your trees
    - Tree colliders are dynamically set now, you can have more than 100k trees in your scene. You can enable the option 'Apply Tree Colliders'. However you can still have the default terrain tree colliders and not use my collider system. Use the 'Collider Refresh Distance' and 'Collider Set Distance' to control after how many meters the player moves the colliders are updated and at what distance the colliders will be set

    Will come back with some extra data after I manage to push this to gihub. The update will be available over the course of this day.
     
    Last edited: Dec 28, 2016
    elias_t and tequyla like this.
  7. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    756
    that most probably is a better idea from a performance point of view... I wanted to emulate the classic see-through system of isometric games of the past, which is easy and cheap to do in case of the forward renderer (just an additional pass in the shader), but fairly expensive in deferred due to the stencil buffer no being available until the forward rendered part of the pipeline. Thus additional shaders. Thus in case of speedtrees additional actual geometry (unless there would be a way to hack the speedtrees output by the modeller to allow more than one material per submesh).

    I planned to manage the additional geometry by only setting these active once an object that needs highlighting gets close to the tree or group of trees with triggers... also not free, but should release some burden to the GPU and save some drawcalls for additional CPU cycles burned. IDK, I am not looking for dense forests (these rarely mesh well with an isometric view), and I was sure that I was able to optimize this if I couldn't come up with a better way of creating such a shader in a more deferred renderer friendly way, by replacing the stencil buffer with separate render targets or something like that to get a shader that could do all steps during the deferred phase of the pipeline.


    Apart from it being a bad idea (which it probably is), does your system work with such a tree setup?
     
  8. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    One thing that comes in my mind is to modify the all-new tree collider manager and to duplicate your tree (as required) and place it under the existing tree just as you need it. If you also need to disable the trees on top you can make a modification in the 'TreeSystem' script not to draw the trees that are closer than, let's say, 20 meter of your character but render instead your custom-materialed trees.

    So, my system could work with such an approach, but not as default. You have to get your hands through it.

    And, unfortunately, I don't think I have time (there's a lot on my head) to implement a so specialized solutions, I prefer to implement more 'general' ones that benefit the most of people in my little spare time.
     
  9. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Does this new update enable me to move tree placement data between scenes even if terrain is not present?
     
  10. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Yes, I think you can simply grab the tree cell holder, the tree system and drop them wherever you need.

    If you can't update me with the exact problem, and I'll look into it since, I've said I'll fix this in this update.
     
  11. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Ok, thanx! Will try it out : )
     
  12. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Having some cliffs that require some foliage on them? No problem! Painting trees on non-terrains is now possible!

    TreesOnNonTerrain.png
     
    OCASM likes this.
  13. No0B25

    No0B25

    Joined:
    May 2, 2016
    Posts:
    70
    Hey there,

    I just tested the update out and the fix for the shadow popping is working just like it should! :) Painting trees on non-terrain will also come in handy for sure. Thank you very much for that. I have got one more bug/annoyance though I think. Whenever trees for the first time change from billboard to 3D after entering play mode, they seem to be invisible for a few frames. This only happens the first time, so when I revisit the same place again, they don't flicker when changing from billboard to 3D. I'm very sure my SpeedTrees are set up correctly. Any ideas?
     
  14. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Hm... I've just tested and I found another issue, the billboard when in transition at a certain distance also have the full model shadows that should only be visible if the model is a mesh.

    For the models flickering, I've saw that there's a slight distance where the model becomes invisible (I think I should use '>=' instad of '>' in the billboard shader code) but I can't duplicate what you have told me. I am not saying that there is no problem, but I can't replicate it. Do you have a video or anything of it? Does it happen in the default demo?
     
  15. No0B25

    No0B25

    Joined:
    May 2, 2016
    Posts:
    70
    Because I have a pretty dense forest, I need to use a rather small tree distance for it to be viable performance-wise. When I set the distance to 50 in the demo and walk around (without running), the effect is very visible for me with bushes and trees popping in. Right now I'm on a notebook with a GTX870M with driver 373.06, but it's just as visible on a desktop GTX680 with the same driver.

    EDIT: I've got a video from your demo: http://cdn.che.moe/zoovli.mp4
     
    Last edited: Dec 29, 2016
  16. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Yes, I managed to duplicate it. But the overall quality is terrible at that view distance :). I think I never noticed it by now since I've only used view distances larger than 150m. And when the billboards switch based on angle it still looks quite very very bad, the popping is quite notice-able. And some trees turn out invisible, I've saw that too.

    Well, I'll look into it, and try to see how it can be improved at that tiny distance, but what I really recommend lowering the density and increasing the view distance to at least 100m.

    One thing that I am sure that I'll improve is the billboard switch based on the view angle. Even the Unity ones look quite bad when the angle switches. I really really want to improve that with a fade between the trees billboard angles.

    Couldn't saw the video, was marked as a virus by my intivirus, sorry.
     
  17. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    756
    Totally understandable that you don't want to spend your time on specialized solutions like that, and I am not afraid to get my hands dirty at all... just wanted to know if you see a way to get this to work in context of your system.

    To be totally honest, I am not 100% anymore if I will stick with the deferred renderer in the end or if I move back to the forward renderer. If I do that (for other reasons), this should be a one-shader thing and no longer require so much hoops to jump through just to get around Unity hijacking the stencil buffer for their deferred renderer.

    Anyway, will give your system a test run. Thanks for the replies!
     
    Assembler-Maze likes this.
  18. zelmund

    zelmund

    Joined:
    Mar 2, 2012
    Posts:
    437
    thats awesome! thanks for your work man :)
     
    Assembler-Maze likes this.
  19. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Just one more question : p
    Is it possible to remove trees during runtime? And if it is, could you share a few pointers on the process?

    Edit: Also, looking at the repo, i think it might be a good idea to put all none "core" stuff in an Examples folder inside CritiasTreeSystem folder, its a bit of a mess now if i want to import it into my project with all the folders : )
     
    Last edited: Jan 3, 2017
  20. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Hey, everything important should be in the folder 'CritiasTreeSystem', there's nothing else outside it, last time I've checked.

    For removing trees at runtime, the most difficult part would be to 'disable' a billboard. One solution that comes in my mind is a boolean (bit, whatever) sent in the shader so that you can 'if' it out of visibility. Another step would be the removal of the tree from the cell list.

    I've already thought at that, wanted to try that out for destructible trees. For example in some kind of scenario to be able to mark a tree as invisible and create one of your 'destructible' trees at that spot and blow it out.

    If you also want serialization for that (a.k.a save-game) you will have to figure out that by yourself :)
     
  21. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Ok, seems a bit complicated then...
    I dont need it right now, so have to think about it for a bit : p

    Regarding the examples, i just meant that many ppl likes to import not just the core stuff, but also the examples so they can play around, and at the moment its a lot of folders : )

    Btw, you can create a Quad from code using GameObject.CreatePrimitive(PrimitiveType.Quad), the quad reference is a bit confusing i think so maybe its a good idea to get rid of it?

    Edit: Moving the trees to another scene worked just fine, thank you for fixing that!
     
    Assembler-Maze likes this.
  22. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    The disabilng is not 'that' complicated, it only sounds complicated :).

    By the way I was reluctant on the quad method due to the note:
    "Note: CreatePrimitive may fail at runtime. This will happen if your project does not reference the following components: MeshFilter, MeshRenderer, and BoxCollider or SphereCollider at runtime. The recommended way to avoid this crash is to declare private properties of these types. The stripping system will recognise their use which include them in the build so will not delete these components."

    So, I said better safe than clear :). Also at the current moment the generated is kinda bloat, since it can be extracted at runtime from the prefab, but somehow it works in the editor but when you build your game stand-alone it displays the trees with weird holes in them.
     
  23. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Ohh, ok. Never had it fail for me but i have not used it a lot. I can agree that its better to be safe : )
     
  24. marcatore

    marcatore

    Joined:
    May 22, 2015
    Posts:
    160
    Finally I had the opportunity to test your tree system.
    I've followed your documentation but I've this error when I press the "Generate trees" button.
    Code (CSharp):
    1. Can't gridify terrain [Terrain (UnityEngine.Terrain)] with cell size: 750
    I tried to replicate your demo scene creating 1 terrain 2000m large. The I've duplicated it and moved the copies.
    I've add the duplicated terrains in the Treefier script and Set the Cell Sizes to 750.

    What could be is creating that error?

    Thanks in advance

    EDIT: Fixed...the Cell Size must be the result of Terrain size divided by an integer number...so hagin 2000m as terrain size..I've put 500 to the cell size
     
    Last edited: Jan 19, 2017
  25. marcatore

    marcatore

    Joined:
    May 22, 2015
    Posts:
    160
    Now I've another problem.
    After I 've pressed the "generate trees" button I've this error

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. Treeifier.BuildTreeTypeCellMesh (UnityEngine.GameObject owner, .TreeSystemStructuredTrees cell, System.Collections.Generic.List`1 trees, .TreeSystemPrototypeData data) (at Assets/CritiasTreeSystem/Code/Treeifier.cs:739)
    3. Treeifier.ProcessTerrain (UnityEngine.Terrain terrain, Int32 cellSize, UnityEngine.GameObject cellHolder, System.Collections.Generic.List`1 extraTrees) (at Assets/CritiasTreeSystem/Code/Treeifier.cs:647)
    4. Treeifier.GenerateTrees () (at Assets/CritiasTreeSystem/Code/Treeifier.cs:436)
    5. TreeifierEditor.OnInspectorGUI () (at Assets/CritiasTreeSystem/Code/Treeifier.cs:28)
    6. UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1236)
    Again...what should be?
     
  26. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Are you testing in the test scene or your scene? Have you generated the tree prototypes first?

    With that null pointer I think that the data related to the tree prototype generation has been somehow generated in a wrong way. Try clearing the tree data folder and regenerate the tree prototypes.

    I also suggest starting with the default example level before plugging it into your own scene and reading the documentation really careful (in case you didn't).
     
  27. marcatore

    marcatore

    Joined:
    May 22, 2015
    Posts:
    160
    @Assembler-Maze you are right. I've forgot to redo the tree prototype generation.

    Now I've another problem.
    When I press "play", I can see clearly the billdboard trees but not the 3d ones.

    I'm working on a personal scene, not your but I'm trying to replicate your scene following the documentation.

    EDIT: I've found the problem. I've to set "none" as "used camera" in the TreeSystem Script.
     
    Last edited: Jan 20, 2017
  28. marcatore

    marcatore

    Joined:
    May 22, 2015
    Posts:
    160
    Probably I've found a bug...or at least an unexpected behaviour.
    If you have the terrain under the "0" Y-axis coordinates, the 3d trees become invisibile.

    Did you ever notice it?
     
  29. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Sorry, I have never encountered that, I'll check it out now. By the way have you 'regenerated' your trees after you have moved the terrain? Just asking.
     
  30. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    I just tested it now, and it replicated, I generated the trees at 0 moved the terrain at -200 Y and regenerated. When I look with the camera a little down I see the trees vanishing and when I look up they appear again.

    For some odd reason the cells are generated wrongly floating above the terrain when the terrain is at - on the Y axis. Will look into it and probs push a fix on github today.

    EDIT: Not only at - Y values stuff get bad, but at + Y values the cells are under the terrain. Probs forgot to apply the terrain's Y offset when generating the grids.
     
    Last edited: Jan 21, 2017
  31. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    A fix has been posted onto github. Fortunately it was only 1 line of code :). Feel free to pull at any time.
     
  32. marcatore

    marcatore

    Joined:
    May 22, 2015
    Posts:
    160
    great!!
    I'll download it immediately.

    Now I'm testing your asset, questions arise...
    If I'd like to test the difference from standard trees on terrain and your asset, what should I have to do?
    I'd like to compare apples Vs apples so is it correct comparing them if I press play after generated trees with your asset and the press play after I delete the "cellholder" content? I'd like to compare the same Speedtree model with the same numbers and positions. Is it possible?
     
    Last edited: Jan 21, 2017
  33. No0B25

    No0B25

    Joined:
    May 2, 2016
    Posts:
    70
    Oh boy! And I thought it was something on my end. My terrain is at -384,-384 (because it's a 768² terrain and I'd like to have it centered) and was wondering why the shadow popping remained. Now it's completely gone. Thanks!
     
  34. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Sorry for the mishap :). But if you are 100% sure that you did everything correctly, don't hesitate to post here, since it means that it's a bug.
     
  35. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Sure, just disable the 'TreeSystem' script, disable the cell holders that hold the tree billboard batches, enable the trees on the terrains and hit play.
     
  36. marcatore

    marcatore

    Joined:
    May 22, 2015
    Posts:
    160
    thank you.

    Another questions:
    - it's necessary more than 1 Terrain to make your asset working? If yes, the cell size how should be set?Should be enough to follow the rule to use a fixed number to divided the Terrain size as described in your documentation?
    - it seems that I need a square Terrain. Is it correct?
     
  37. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    1. No need for multiple terrains, it's a completely optional (very usefull though) feature.
    2. At the moment, yes. There's a plan for changing that (need a bit of code rework) but I don't have time at the moment.
     
  38. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    Hey, this looks really cool, and it's free! Anyway, I'll play around with it :)
     
    Last edited: Jan 21, 2017
  39. Frednaar

    Frednaar

    Joined:
    Apr 18, 2010
    Posts:
    153
    I just tested it on a rather large terrain (20 km) with cells at 2 km side and it works really well.
    I see that horizontal billboards are now not available due to speedtree ....

    I think a nice alternative would be to have a 3 way billboard projection like lushlodtree has
    (see the video here). This would allow to use any type of tree and also solve the horizontal issue

    If you want I believe I can put together the code to create the billboards from any type of tree (speedtree, unity, mesh), but then I would need help in integrating it into the shader itself...
     
    Last edited: Jan 22, 2017
  40. marcatore

    marcatore

    Joined:
    May 22, 2015
    Posts:
    160
    Ok. And what about the cell size?
     
  41. Frednaar

    Frednaar

    Joined:
    Apr 18, 2010
    Posts:
    153
    From what I have seen use 1 base terrain to export the trees then set the cells parameter to the number of terrains you have and the cellsize for each terrain...
    then you have to drag the same terrain also on the first cell, but you can add extra terrains and cells..

    Defining cell size per single terrain allows to have different cell sizes for different terrains (think forest near a desert) but changing the code to have a single cellsize setup automatically for each terrain should be trivial
     
  42. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    Well, there is a workaround but you require the XML data from the SpeedTree guys. I got them from a custom executable that extracted that billboard data from the speedtree '.spm'. I contacted them for that, but if you require it for something extra extra extra special you can do the same. I'm sure they'll be happy to help :)
     
  43. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    I don't understand the question, could you please explain? I think the cells don't have to be square, I think.
     
  44. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    I already got code for generating custom impostors for anything (i'm thinking at billboards for distant static meshes like buildings) but I don't think I'll do anything with it except the bare minimum my project needs.

    I think after I finish this project I'll move on to Unreal so that I don't have to write tons of code to have custom impostors, custom grass, custom trees, fixing lightmaps, begging unity months for instancing support, lack of c++ code, lack of shader node editor, lack of gridified terrains, lack of a decent terrain system working occlusion culling, a good base character controller (and the list can go on), but just focus on the gameplay part of the game and not fixing, and fixing, and fixing and fixing...

    I want the fixing part be the secondary part of the project not the primary one.
     
    jason-fisher likes this.
  45. marcatore

    marcatore

    Joined:
    May 22, 2015
    Posts:
    160
    I mean, if you have just one terrain object...can I use the cell size I like?
     
  46. marcatore

    marcatore

    Joined:
    May 22, 2015
    Posts:
    160
    It's quite sad for us because from my first tests, your system seems really powerful and I'd like to see further development.. but your position it's quite understandable .
    In any case you're the developer, this asset is free...so we can't say anything than say thank you and good luck

    Obviuosly, if you want to help us using it you're more than welcome! :)
     
  47. Frednaar

    Frednaar

    Joined:
    Apr 18, 2010
    Posts:
    153
    Spent about 1 year learning unreal, but found working with it very slow and cumbersome in respect of Unity. C++ iteration is really slow (vs C#) and Blueprints are really not an option for complex coding, also I believe the landscape terrain is not quite there... it might have improved though.
     
  48. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    No, it still has to fit the '(terrainSize.x % yourCellSize) == 0) constraint. The thing is that it must perfectly fit the terrain so that we don't have any cells going over the terrain's border too badly. Use the 'info' button for the perfect fits. It should give you quite a few size options so that it can fit all your needs. Of course, if you don't use crazy sizes like '1424' or something like that :)

    And I'm not stopping development on this right now, I'm still stuck with Unity for the next many months (and maybe one more year if the kickstarter goes well) so don't worry, we'll bring this system to a very usable state while I'm around.
     
    No0B25 likes this.
  49. Assembler-Maze

    Assembler-Maze

    Joined:
    Jan 6, 2016
    Posts:
    630
    For those interested for the Asset Store distribution method, you can find the package on the store right here!
     
  50. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    eh just realized something, so it's only support speedtree Objects? no custom trees/foliages mesh support?