Search Unity

[Released!] Custom tree importer

Discussion in 'Assets and Asset Store' started by larsbertram1, Aug 19, 2014.

  1. Low_on_Mana

    Low_on_Mana

    Joined:
    Jun 18, 2018
    Posts:
    37
    Hello! I just picked up the asset and am having a little difficulty setting up my asset to function on import. I'm trying to follow the tutorial in the documentation as best as I can but It all seems so arcane and confusing. Is there perhaps a video tutorial in which the process is shown? I'm particularly lost when it comes to naming conventions and unity said that my test object crashed upon import.

    I've tried checking out the demo assets in 3ds max to see what it is i'm doing wrong but that just made things even more confusing. Any help is appreciated!

    3ds Max 2017, Unity 2019 2.5f1
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i am not familiar with 3dsmax – but all you have to do is painting edge flutter into the green color channel of the leaf planes:
    set outer vertices to green = 0.2 e.g. and inner vertices and the pivot to 0.0 like shown in the screenshot below.

    you may bake ambient occlusion to vertex color alpha.
    and you may mark bifurcations using vertex color blue.
    that is all about vertex colors – or did i miss something?



    Bildschirmfoto 2019-10-09 um 20.17.15.png
     
  3. Low_on_Mana

    Low_on_Mana

    Joined:
    Jun 18, 2018
    Posts:
    37
    Thank you for your response! In my inspection of the demo assets I think I've identified the equivalent to the vertex color you're suggesting (it uses RGB sliders 0-255). Can you please enlighten me as to how the naming conventions work? I think that my import crashed due to improper object names.
     
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hmmm, naming is described in depth in the docs...
     
  5. Low_on_Mana

    Low_on_Mana

    Joined:
    Jun 18, 2018
    Posts:
    37
    I know, I'm sorry to ask you to repeat information and I appreciate your patience (i'm still quite new to this!), but I had a very difficult time parsing the information in the documentation. In one of the demo assets (the palm tree specifically) some of the leaves were labeled as "mesh" while others had names including what I believe is phase variation labels. Is this because only those that were labeled are intended to have that phase variation? If I don't want the leaves to swing, is a generic name suitable?

    Lastly, if I want an object to include things such as phase variation, tumbling, and turbulence, does that mean that the object name will end up looking something like "leaf 01_xp03_xt20_xlpr" ?
     
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    that is way beyond what i can recall from memory, sorry.
    just start with no per level tags. and then add more and more over time.
    sorry if i can't be more precisely here.
     
  7. Low_on_Mana

    Low_on_Mana

    Joined:
    Jun 18, 2018
    Posts:
    37
    Thank you! Your responses have been very helpful. It's required a lot of trial and error but I'm finally starting to produce some results.

    Is a trunk/bark object vital? I have a fern that doesn't have a formal "trunk", and I'm worried that the hierarchy might require a dummy object or something.
     
  8. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,694
    yeah create a "null" object as root. it works, i did this before for plants and ferns.
     
  9. Low_on_Mana

    Low_on_Mana

    Joined:
    Jun 18, 2018
    Posts:
    37
    Awesome, thanks!
     
  10. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,694
    if i recall correctly, u need to create an empty root(xyz 0) then make an empty child called trunk(xyz 0) and then attach all your leafplanes under the trunk object. that should work
     
  11. Low_on_Mana

    Low_on_Mana

    Joined:
    Jun 18, 2018
    Posts:
    37
    I'm getting the following error when importing my objects. Is this supposed to happen?


    Code (CSharp):
    1. A default asset was created for 'Assets/Party Van/Asyle - Ferntree_afsTREE.FBX' because the asset importer crashed on it last time.
    2. You can select the asset and use the 'Assets -> Reimport' menu command to try importing it again, or you can replace the asset and it will auto import again.
    3. UnityEditor.AssetDatabase:Refresh()
    4. AFSTreeMeshPostprocessor:OnPreprocessModel() (at Assets/Import/Custom Tree Importer v3/CTI/Scripts/TreeMeshPostprocessor AFS.cs:113)
    5. UnityEditor.AssetPostprocessingInternal:PreprocessMesh(String)
    6. UnityEditorInternal.InternalEditorUtility:ProjectWindowDrag(HierarchyProperty, Boolean)
    7. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    8.  
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    of course not :)
    the importer errors on trying to fix the material names (line 113).
    i don't know which version of unity you use and why it errors – but you should be able to get around it by:
    1. remove "afsTREE" from the file name and reimport it.
    2. it will be imported without any processing.
    3. select the fbx in the project tab, then go to the inspector so you see the import settings.
    4. go to "materials" and find "naming". in unity 2019 it is under "remapped materials" -> "on demand remap"
    5. set "naming" to "From models material"
    6. apply
    7. finally add "afsTREE" to the file name.
    now the importer script should skip the step that errored.
     
    florianalexandru05 likes this.
  13. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Hi. I plan to move our scenario to the HDRP and we use the Oak, Birch and Confiers CTI trees.
    Do you think an HDRP port around february will be possible.
     
  14. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i think, it is possible. at least a quick workaround to get them up and running.
     
    keeponshading likes this.
  15. Low_on_Mana

    Low_on_Mana

    Joined:
    Jun 18, 2018
    Posts:
    37
    Worked well, thanks! only thing now is it's saying
    "
    No Vertex Colors found.
    UnityEngine.Debug:Log(Object)
    AFSTreeMeshPostprocessor:OnPostprocessModel(GameObject) (at Assets/Import/Custom Tree Importer v3/CTI/Scripts/TreeMeshPostprocessor AFS.cs:318)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
    "
    I assume this is when it checks the dummies holding the hierarchy intact? This model in particular uses one to hold Tree and another to hold Trunk.


    One more thing! I have a bush that has berries on it. How can I arrange the hierarchy to allow the berries to sway as well? Best I can do is get the bush to sway but the berries stay in place. If I try attaching the berry meshes to the leaf meshes, they work, but now the materials are shared and they turn invisible (they use a different material, on the leaf texture, those coordinates are transparent).


    Unity 2019.2.5/3ds Max 2017
     
    Last edited: Oct 13, 2019
  16. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    ah, that is fine and just an info.
     
  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you only have 2 materials. so berries must use the leaf material and you have to include them there somewhere in your texture.
     
  18. florianalexandru05

    florianalexandru05

    Joined:
    Mar 31, 2014
    Posts:
    1,813
    Hello Lars, I'm kinda here to ask another kinda silly question to you! Is there any way to make the billboard script bake higher texture sizes like 2k and 4k? I think I saw something in the script and tried changing the sizes but it didn't work. The billboards are fine but when I use it on a bigger or wider tree they look pretty bad.
     
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i am not really into it right now. but it should be possible... you just have to find all lines where you have to change it.
     
  20. florianalexandru05

    florianalexandru05

    Joined:
    Mar 31, 2014
    Posts:
    1,813
    Oh thanks alot, I'll try it! ;):D
     
  21. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    what for? :)
     
  22. florianalexandru05

    florianalexandru05

    Joined:
    Mar 31, 2014
    Posts:
    1,813
    For making me learn on my own!! :p Changing a few things and I found that i can change the rows and columns. I managed to change the final render image size to what I want but the bakes are still at the same resolution. Might have any hints to what part of the code that might be? I'll keep trying!! :D'
     
  23. Low_on_Mana

    Low_on_Mana

    Joined:
    Jun 18, 2018
    Posts:
    37
    Since that plant isn't using a bark texture, I was just using that. I would like it to be a separate object so that when the berries are picked, they disappear (it also means their material can be different, so I can have them unlit to make them easier to spot). If it's not possible to give them a separate material, do I need to attach them and then swap the bush out with an identical copy that doesn't have the berries?
     
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    untested, but from a first look at my old code:
    (11) public int imageWidth = 256;
    (12) public int imageHeight = 512;
    (302) finalTexture = new Texture2D( 1024, 1024, TextureFormat.ARGB32, false );
     
    florianalexandru05 likes this.
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    bark and leaf are not just "visual" materials... they are used by the importer to apply certain calculations and skip others. so vertices using the bark material will not get edge fluttering e.g.
    creating them as separate objects is not an easy task: bending is a complex thing which starts at the trunk and gets propagated through all the levels of the hierarchy up to the last leaf plane.
    right now i am not sure if you could just use empty transforms to reconstruct the hierarchy.
    but at least you can duplicate you bush, attach the berries in the hierarchy, then get rid of most of the parent meshes by deleting all triangles except from 1 per mesh. import, then export as fbx and kill that orphan tris.
    unlit is not supported by the shaders. you would have to write your own one.
    this would be the easiest way. it also keeps the number of game objects low in your scene.
     
  26. Low_on_Mana

    Low_on_Mana

    Joined:
    Jun 18, 2018
    Posts:
    37
    Thanks for the help!

    I'll go with the swapping then, I should have specified that I was using the bark material in 3ds max to give the berries a different material ID and in Unity, using a different shader altogether to give the materials the desired appearance.
     
  27. Low_on_Mana

    Low_on_Mana

    Joined:
    Jun 18, 2018
    Posts:
    37
    Sorry for the questions, but I've just tried making a new tree and for some reason the trunk doesn't bend very much and the branches bend away, detaching from the trunk. From what I read in the documentation, this suggests that the trunk isn't being told to bend properly. I can't imagine what the issue is, though. I've tried freezing the transformation of the branches, I've double checked that the pivots are correctly placed along the intersection with the bark, and I've even made sure the bark has enough geometry with which to bend. Any ideas?
     
  28. Low_on_Mana

    Low_on_Mana

    Joined:
    Jun 18, 2018
    Posts:
    37
    friendly bump, hoping for some help. Thanks!
     
  29. florianalexandru05

    florianalexandru05

    Joined:
    Mar 31, 2014
    Posts:
    1,813
    Yeah, those where the first things I tried but it didn't work. I managed to make the final image 4k but the bakes remained the same. I played with some of those values, got some things changed and got my gf to mess around with it for fun but it doesn't work, we both suck lol. Anyway, bottom like is that I tried a bigger resolution test on the bilboards and it doesn't make any difference anyway, the cutout looks the same for some reason. So I finally realized that it was a bad idea from the start lol. I guess the billboard is intended to be a fast solution and it's really good and effective at what it does and in some instances I'm really glad I'm using it and I suppose people should make their own billboards anyway which is exactly what I'm gonna do for some trees ;) No need to bother yourself with this, the problem for me was that it doesn't look that good for wide trees with different branches in all directions but it's just right for tall trees. One of my friends is making really amazing looking billboards with the cti leaf shader so I guess I'll do that two. :cool:
     
  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you may check the orientation of your fbx. simply remove all cti related stuff from the file name, reimport the fbx and drag it into the scene view. then have a look at the transform: rotation must be 0,0,0.
    another possible break chance: wrong materials (names).

    i always recommend to start with only 3 or 4 very basic shapes like in the tutorial: a cylinder for the trunk, one cylinder as child branch and a simple plane as leaf geo. set up the hierarchy properly, adjust the pivots and assign the 2 materials. then import it into unity only adding afsTREE to the file name.
    look if you get any errors, look if the tree actually is flattened into a single mesh, then test bending by adding a wind zone.

    once you have set up your working file properly you may replace the simple geo and add more and more.
     
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you have to take mip maps into account: the shader always tries to find the best matching size (mip level) for the billboard on screen: so if your billboard is not higher than 512px on screen you will never benefit from a higher res than 1k.
    right. it was made for tall, thin trees. a 3x3 grid would be better for large or wide trees.
    alpha testing is another story. again mip maps play an important role and alpha tends to become a single gray color over the mips. please check "Mip Maps Preserve Coverage" in the texture import settings of the billboard's albedo/alpha tex as well as on your leaf texture and play around with its settings.
    you may also change the cut off value of the leaves while baking the billboard.
     
    florianalexandru05 likes this.
  32. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    Will this asset help me use my tree creator trees in the Universal render pipeline?
     
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    nope, but Lux LWRP Essentails does: it comes with tree creator shaders.
     
    Lars-Steenhoff likes this.
  34. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    Next iteration on the cti shaders for HDRP:
    please notice the LOD transitions as far as shadows are concernde (mesh to billboard) compared to built in (sphere/cube).

     
  35. Noogy

    Noogy

    Joined:
    May 18, 2014
    Posts:
    132
    Hello @larsbertram1, I'm having a bit of an issue converting over to URP. I've taken the steps outlined in your doc, including updating the shader names. The leaves shader seems to be fine, but I can't get the bark shader to work. Nothing but pink. Are you certain there aren't any extra steps necessary there? Thanks.

    Edit: Specifically, pink in the editor, no rendering at all at build.

    Update, I've finally been able to get an error out of unity:
    Shader error in 'CTI/LWRP LOD Bark': redefinition of 'Light' at Lighting.hlsl(40) (on d3d11)

    Commenting out:
    #include "Includes/CTI LWRP Lighting.hlsl"
    seems to fix it, but is this the right solution?
     
    Last edited: Oct 25, 2019
  36. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    oh, i missed that include. commenting it out is absolutely fine.
    it does not do anything in LWRP as the all the code in the file in wrapped in:
    #ifndef LIGHTWEIGHT_LIGHTING_INCLUDED
    this fails when it comes to URP...

    thanks for pointing this out.
     
    Lars-Steenhoff and Noogy like this.
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i have submitted version 3.19 which brings the first preview of the HDRP shaders.
    feedback is welcome!
     
  38. Talavaj

    Talavaj

    Joined:
    Sep 22, 2013
    Posts:
    41
    "3.19 which brings the first preview of the HDRP shaders."

    Awesome!
    What Unity build should we expect the HDRP shaders to work in, the most recent? Or all across the board?
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    unity 2019.3.0b8 and HDRP 7.1.2.
     
    florianalexandru05 likes this.
  40. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,694
    ive send u an email regarding split up meshes ( so one mesh for a tree) ive set the barnches attachment to vertex color blue but they still get detached. im using lwrp
     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    version 3.19.including the HDRP preview shaders is available.
     
  42. GotAThing

    GotAThing

    Joined:
    Jan 10, 2019
    Posts:
    14
    Awesome!! thats made my day, will take a look now :)
     
  43. Talavaj

    Talavaj

    Joined:
    Sep 22, 2013
    Posts:
    41
    Tested the HDRP shaders in 2019.3.0b9 and most features seems to be on point for me.
    The only issues I noticed is that my translucency map seems to get ignored (all parts of the branch are translucent even if my translucency channel is all black) and that the camera goes black whenever it penetrates the mesh of a tree in scene view, but it works just fine in play.

    And also, some of my branches are going crazy, but I assume this is because they were assigned vertex colors since I originally made these trees for the cti tessellation shader.
    The branches and trunks without vertex color information work as expected.

    The only thing I'm not super thrilled about is the removal of the specular map input.
    The default specular in unity standard shader is far too overblown, I would appreciate there being at least a slider to allow us to drag this value down to something reasonable.

    Other than that, looks great so far! screen_5333x3000_2019-11-03_22-00-36.jpg screen_5333x3000_2019-11-03_22-07-11.jpg
     
    Last edited: Nov 3, 2019
  44. Noogy

    Noogy

    Joined:
    May 18, 2014
    Posts:
    132
    Hi @larsbertram1, some thoughts on the URP and HDRP implementations. I'm sort of playing with both pipelines as I'm not sure which I want to use moving forward.

    URP, are there any light limits in the shader? My materials using the CTI URP/LWRP shaders seem to have trouble with multiple lights in the scene (whereas the URP/Lit shaders are fine). The only other shaders I've had this problem with are the Toony Colors asset, and I'm trying to work with that author regarding the same issue. Basically the lights will flicker or toggle depending on the camera angle.

    HDRP, the crossfade implementation is a bit glitchy, lacking the nice fade of built-in/URP versions. Also, I'm having a lot of trouble with leaf normals. I use a one-side leaf material, and I can't quite get the HDRP shaders to respect the authored normals, whereas it's fine in built-in/URP.
     
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    nope. i do get glitches in 2019.2. – just like i get with the built in lit shaders. this should be fixed in urp and 2019.3.

    i can not confirm this either... transitions in the included test scene are smooth, way smoother than the built in transitions (have a look at the cube/sphere lod group).
    normals look fine for me too. the shader will always rotate the normals according to tumble strength and leaf turbulence. you may try to set both to 0 to see if this fixes your issue.

    edit: did you notice that the leaf material expects a regular normal map?
     
  46. Noogy

    Noogy

    Joined:
    May 18, 2014
    Posts:
    132
    Hmm, maybe it's something with my setup. I've been trying this on various 2019.3 betas and haven't been able to figure it out. It's almost like these specific shaders are ignoring the scene/camera light limits.

    Ah, I hadn't realized this was required, I never used a normal before (i'm working with a somewhat stylized look). I'll check out your demos and see if I can get this working.
     
  47. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    as the shader uses the built in transmission lighting translucency is treated as "thickness". so pure black will be thickness = 1 - 0 (black) = 1. the amount of transmitted light for a thickness of 1 depends on the settings of the diffusion profile used. but even if you remap thickness in the profile to e.g. 0 – 8 you will not be able to suppress all transmission... that is how hdrp lighting works.

    built in transmission lighting does not support a custom specular value. you have to tweak the "index of refraction" in the diffusion profile instead.

    hmm, have you tried to lower "leaf noise"?
     
  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    actually i have to check it with 2019.3. right now the shaders uses lwrp lighting code. i may have to get rid of this regarding urp.
     
  49. Talavaj

    Talavaj

    Joined:
    Sep 22, 2013
    Posts:
    41
    "hmm, have you tried to lower "leaf noise"?"

    The trunk mesh, is what I meant.
    The leaf meshes themselves are all fine.

    This is what happens to some of my branches:
    Untitled-3.jpg

    They are part of the "trunk" mesh.
    The other branches on my trees which are done the same way are working just fine.
    But these I painted green vertex color to lower the strength of the tessellation on them in the CTI lod bark tessellation shader.

    So I'm assuming that the Bark HSLS shader is picking up the green vertex color on the trunk mesh and applying flutter to itself as if it were a leaf.

    I also played around with the foliage diffusion profile as you suggested.
    And remapping the translucency to Y- 8 and masking out the branches in the albedo a little did the trick.
    Everything seems to look great now!

    EDIT:

    Weird, the same weirdness is now happening also on my LODs, which I don't remember adding any vertex colors to.
    But they were auto retopologized, so some random vertex color action may have resulted from that.
    Untitled-5.jpg
     
    Last edited: Nov 4, 2019
  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i guess you are right...

    you may try the attached new include which should suppress edge fluttering on the bark properly:
     

    Attached Files: