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

MTree - Tree creation

Discussion in 'Assets and Asset Store' started by mherpin, Aug 31, 2018.

  1. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    Hm. the process how the Branch is created is like this: Mesh for the Stem and Leafs (kind of like MTree works, just in 2dish way) => then a Rendertexture is created and out of the RT a new Branchtexture is generated. now if you would hook in to the Mesh process(recalculating Normals and Tangent space), would this actually help drawing a better Normal map? (I do not believe so) but correct me if I'm terrible wrong =)
     
  2. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    @Baldinoboy

    i believe, it will not be the same but share some results would be nice :)
     
  3. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Hey @dan_wipf,

    Sorry for disappearing. It is just a matter of normal accuracy. Here you can see the normal rotated CCW 90° with the detail corrected-
    TangentCorrected.jpg

    and here is the normal rotated manually without detail correction-
    TangentNotCorrected.jpg

    So it still looks okay but the detail is just not accurate. Do not have an issue with this at all for uses in trees that the player will not get close to the branches. Just an issue for using in things like plants and bushes that the player can inspect the branches up close. If the leaf normals are rotated without detail correction there will an artifacting look since all our brains do is look for patterns and issues in those patterns.

    With this though I can not ask for more. Really appreciate your work on it and can make use of it for things like trees! Especially considering you are doing this for free!
     
    CaliCoastReplay and dan_wipf like this.
  4. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    thanks for this info. i do not have a substance designer copy, to learn from it. but anyway, do you have thoughts on how this could be achieved in unity? => like right now it’s just stitching together a normal texture and capture/save it as new normal texture(like a collage of pictures)
     
  5. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
  6. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Messaged you on Discord but really not sure a method this could be done.
     
  7. CaliCoastReplay

    CaliCoastReplay

    Joined:
    Mar 26, 2017
    Posts:
    86
    This is thrilling stuff. Proud to have helped this community in any way I have so far!

    Really excited to try out your foliage, Baldinoboy!
     
  8. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    i need some help from you.

    i did some research about normals and how they’re displayed in world space, so i’ve catched up some shader codes which works perfectly but only if the render camera is on z axis looking towards the center. so the branch editor is having it’s meshes and textures along the y axis. camera on Y facing center.

    what i’ve tried is to rotate the worlds normals but there i’ve got stuck. i do use a 4x4 matrix to rotate the worlds normals but that seems to produce on the x rotation not correct results.

    Maybe someone else has an Idea to fix that?

    Code (CSharp):
    1. Shader "Mtree/Normal" {
    2.     Properties{
    3.         _Cutoff ("CutOff", Range(0,1)) = 0.3
    4.         _MainTex ("Albedo (RGB)", 2D) = "white" {}      
    5.         _BumpMap("Normal Map", 2D) = "bump" {}
    6.         _Axis("Axis",float) = (0,0,0)
    7.     }
    8.     SubShader{
    9.         Tags{ "RenderType" = "Opaque" }
    10.         Cull off
    11.         CGPROGRAM
    12.  
    13.         #pragma surface surf Lambert
    14.         #pragma target 3.0
    15.         #include "UnityCG.cginc"
    16.         sampler2D _MainTex;
    17.         sampler2D _BumpMap;
    18.         float _Cutoff;
    19.         float3 _Axis;
    20.        
    21.         struct Input {
    22.             float2 uv_MainTex;
    23.             fixed4 color : COLOR;
    24.             float3 worldNormal;
    25.             INTERNAL_DATA
    26.         };
    27.        
    28.         float4x4 RotationMatrix () {
    29.             float radX = radians(_Axis.x);
    30.             float radY = radians(_Axis.y);
    31.             float radZ = radians(_Axis.z);
    32.             float sinX = sin(radX);
    33.             float cosX = cos(radX);
    34.             float sinY = sin(radY);
    35.             float cosY = cos(radY);
    36.             float sinZ = sin(radZ);
    37.             float cosZ = cos(radZ);
    38.  
    39.             return float4x4(
    40.                     cosY * cosZ,    cosX * sinZ + sinX * sinY * cosZ,    sinX * sinZ - cosX * sinY * cosZ,    0,
    41.                     -cosY * sinZ,    cosX * cosZ - sinX * sinY * sinZ,    sinX * cosZ + cosX * sinY * sinZ,    0,
    42.                     sinY,            -sinX * cosY,                        cosX * cosY,                        0,
    43.                     0,             0,                                 0,                                 1
    44.                 );
    45.         }
    46.         void surf (Input IN, inout SurfaceOutput o) {
    47.             fixed4 n = tex2D (_BumpMap, IN.uv_MainTex);
    48.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
    49.             o.Normal = UnpackNormalDXT5nm(n);
    50.  
    51.             clip (c.a - _Cutoff);
    52.  
    53.             float3 worldN = WorldNormalVector(IN,o.Normal);
    54.             worldN = mul(RotationMatrix(),worldN);
    55.             worldN = normalize(worldN.xyz);
    56.            
    57.             o.Albedo = float3 ( float2(-worldN.x, worldN.y)*0.5 + 0.5,1);
    58.             o.Alpha = 1;
    59.         }
    60.  
    61.         ENDCG
    62.     }
    63.     FallBack "Diffuse"
    64. }
    65.  
     
    CaliCoastReplay likes this.
  9. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    Allright.. was fast enough to figure it out myself =)

    the rotation of the normals can be adjusted inside the Vertex part of the shader, by rotating normals and Tangents =)

    hopefully haven't tested yet it will produce correct normals with the Branch editor!
    Branch.png Branch_Normal.png

    Code (CSharp):
    1.         void vert(inout appdata_full v, out Input o)
    2.         {
    3.             UNITY_INITIALIZE_OUTPUT(Input, o);
    4.             v.tangent = mul(RotationMatrix(),v.tangent);
    5.             v.normal = mul(RotationMatrix(),v.normal);
    6.         }
    7.  
     
    CaliCoastReplay and Mark_01 like this.
  10. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    Gonna upload the new version soon! Evolution of Branch Editor.png
     
  11. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    Quast, Mark_01, Artomiano and 4 others like this.
  12. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    if anyone who uses this tool come across black normals, go to the enhancednormals shader and change inside the Rotation Matrix the value -90 to 90. i’ll change this anyway today, so it’s possible to rotate the global normals until it fits correctly!
     
  13. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    Version 2.01 is alive

    v2.01 – 19.June 2019
    Changelog:
    - Added custom normal rotation support in Branch Editor.
    - Added normal rotation support in Shader.
    - Fixed Black Color Normal Bake. => Normals are now reimported and forced to Normal mode if the Texturetypes are not declared as Normals.

    can be downloaded at https://github.com/danwipf/MTree-Addons/tree/master/Enhanced Branch Editor
     
    Baldinoboy and Mark_01 like this.
  14. Artomiano

    Artomiano

    Joined:
    Dec 1, 2014
    Posts:
    200
    Would be great to see a mesh extension: branch stumps for broken or sawed branches. Those stumps I would place on the trunk and on branches. Should be possible manually and randomized.
     
    StevenPicard and dan_wipf like this.
  15. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    i think this will be only any good when maxime updates the core mtree, like he mentioned he wants to change the way how branches are attached to the tree. if i remeber correctly, he said something about that they would no more be stuck into the tree, the seam will be neatless, which would make way much realistic trees! and if you would imagine this update with the stumps that would looks awesome!

    without the update it maybe look abit odd/edgy
     
    Mark_01 likes this.
  16. StevenPicard

    StevenPicard

    Joined:
    Mar 7, 2016
    Posts:
    859
    I wish you could work hand-in-hand with the main developer so your work could be fully integrated features of the asset.
     
    dan_wipf and Mark_01 like this.
  17. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    i’m in touch with him, so that’s allright and we have discussed what’ll transfer to the original mtree asset :)
     
  18. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Hey @dan_wipf, Sorry was offline for a while. That looks great man! Will try it out for the next tree I am putting together. Thanks again!
     
    dan_wipf likes this.
  19. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    very good. hopefully it firs your needs at it does for me !
     
  20. Juexe

    Juexe

    Joined:
    Nov 5, 2018
    Posts:
    1
    Hey guys, I'am looking at your works, and they look awesome!
    I wander if it works at runtime, which is to build a tree in code?
     
  21. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    well, i’m afraid this will not work. right now it’s an editor tool only which creates trees as meshes and saves them in your project folder. the baking process takes quite some time, so it’s useless in runtime application(freezes the framerate) and anyway it can not be included in a build => drops some errors.

    maybe it is possible if you dig in the code and modify it to your needs. as far i’ve seen it could be somehow possible, but you’ll need parallel threading or unity jobs to get faster results.. (no garantee on this information :) )
     
    CaliCoastReplay and Juexe like this.
  22. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    Just curious, anyone used an addon / tutorial? What do you think of the usage of them? thankalot dan
     
    CaliCoastReplay likes this.
  23. marcatore

    marcatore

    Joined:
    May 22, 2015
    Posts:
    160
    Sorry @dan_wipf , I'm a Mtree buyer but, at the moment I've not found a moment to try both Mtree and your addon in a deep way, I've just look your videos and it seems really useful.
    I hope to have time in the next weeks.
     
    CaliCoastReplay and dan_wipf like this.
  24. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    I uploaded a faster Version of the RaycastAO.cs file (Main Horse of the Ao Baker Button). It depend on Unity's Jobs Job System(batched Raycasts) and Net 4.x version (Parallel Threads).

    Why using this?:
    Well it was on my testing Machine 5.5x faster than the Original file =), still not an instant AO baker... (still has to make millions of Raycasts) but it prevents your machine from freezing.

    Why dll?
    Well I do want to protect MTree as good is can, but still providing you improvements as soon as they're released and ready ti use. So the best way is to use a DLL until it might be included in Mtree it self.

    You can download the file on my Github Repo, (Manual included how to Setup MTreeFasterAO.dll) =>

    https://github.com/danwipf/MTree-Addons/tree/master/MTree Faster AO
     
    Willbkool_FPCS and Artomiano like this.
  25. CaliCoastReplay

    CaliCoastReplay

    Joined:
    Mar 26, 2017
    Posts:
    86
    I have adopted your SSS shaders 100%. You're doing astonishing great work here. The more that Maxime can integrate from your additions to the main feature set, the stronger MTree will be - wish I could figure out a way to compensate you somehow, though!
     
    dan_wipf likes this.
  26. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    i’m always happy with textures, assets or a cup of coffee.
     
    CaliCoastReplay likes this.
  27. KennyGuillaume

    KennyGuillaume

    Joined:
    Mar 7, 2014
    Posts:
    11
    Hi, really liking the asset.

    I have a question though. I'm making different variations of one tree which would all use the same materials. But because now I make the trees different sizes, the bark textures are now different sizes as well. Is there a way to change how big the UV islands are with the tool, so I could make the textures all the same sizes approximately?
     
    CaliCoastReplay likes this.
  28. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    well yes you can. but you have to change the shader. you need to make the textures scale not local instead you will convert it to world space
     
    CaliCoastReplay likes this.
  29. joeee19

    joeee19

    Joined:
    Jul 14, 2012
    Posts:
    56
    Although I am using the same Prefab,the color of the tree changes in some ways,why is that?

    This phenomenon only occurs on iPhone builds.

    It does not occur in UnityEditor.


    I am using in LWRP with the following version.

    Unity 2019.1

    MTree 2.1

    iPhone7 iOS12.3.1 (Metal)
     

    Attached Files:

  30. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314

    as far as i know lwrp and hdrp are optimized for the 4.x series and not 5.x (2019.x)
     
    CaliCoastReplay likes this.
  31. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    183
    Last edited: Jul 6, 2019
    CaliCoastReplay and dan_wipf like this.
  32. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    Hi folks, I've just read now a coupple of times MTree has not a proper Undo / Redo System.. and well it kind of does have it but it's not fully implemented. So what you can do to fix this is quite simple, and I guess for those who know how to Build a Custom Inspector / Editor Window logical.

    Step 1:
    Open MtreeEditor.cs inside MTree/Editor.
    Step 2:
    Replace the 3 EditorGUI.EndchangeCheck() with those below (=> only one by one)

    Code (Nr. 1):
    1. if (EditorGUI.EndChangeCheck())
    2.         {
    3.             Undo.RecordObject(tree,("LOD Selection"));
    4.             UpdateTree();
    5.             EditorUtility.SetDirty(tree);
    6.         }
    Code (Nr. 2):
    1. if (EditorGUI.EndChangeCheck()){
    2.             Undo.RecordObject(tree,"Quality Tab");
    3.             UpdateTree();
    4.             EditorUtility.SetDirty(tree);
    5.         }
    Code (Nr. 3):
    1. if (EditorGUI.EndChangeCheck())
    2.         {
    3.             Undo.RecordObject(tree,"MTree Properties");
    4.             UpdateTree();
    5.             EditorUtility.SetDirty(tree);
    6.         }
    Save the file and Undo / Redo function works on any change made when editing the Tree
     
    Last edited: Jul 7, 2019
    CaliCoastReplay likes this.
  33. julesd

    julesd

    Joined:
    Sep 30, 2016
    Posts:
    26
    Is there a tree collision system? And if so is it saved with the prefab?
     
  34. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    No. After baking you need to add a Collider manually.
     
    CaliCoastReplay likes this.
  35. Lacostic

    Lacostic

    Joined:
    Nov 29, 2017
    Posts:
    14
    Hi,
    Does anybody faced with script errors in Unity 2019.1.9f1?
    Just bought this really great asset, but seems like it works only in standard 3D projects (
    Some help?
     
  36. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    i do use 2019.1 but just for experimentals.. (no errors on my mac book)

    can you upload the error messages?

    edit:
    i’ve read your review on the asset store. Hdrp is not supported yet on 5.x versions of the asset(2019.x)
    it’s only supported on 2018 (4.7 or 4.8)

    edit2:
    i might upload tomorrow hdrp support fort 2019.1

    what version do you use of the SRP?
     
    Last edited: Jul 17, 2019
  37. Lacostic

    Lacostic

    Joined:
    Nov 29, 2017
    Posts:
    14
    Just edited review )
    Beg my pardon, seems like it was the only way to contact with developer

    It would be cool to see update tomorrow, looking forward for it.
    I used different RP versions from 5.7.2 to 5.16.1 in new empty project and got bunch of script errors messages anytime
    Sorry, I'm not very familiar with Unity, I trying to use it for cinematic videos.
    Here is screenshot with error messages
    Screen Shot 2019-07-17 at 19.37.19.png
     
    dan_wipf likes this.
  38. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    yeah, that’s defently the hdrp which is uncompatible with 5.x (diffrent approach of how custom expressions are handled)
     
  39. Lacostic

    Lacostic

    Joined:
    Nov 29, 2017
    Posts:
    14
    Waiting for update!
    Because in editor it works perfectly, great work!
    Screenshot 2019-07-18 at 02.04.25.png
     
  40. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    sorry to dissapoint you, but i cant do it right now(my macbook doesnt play along, have to do it on my pc, if you have amplify i can send you the progress files, and you could finish it your self!)
     
  41. Lacostic

    Lacostic

    Joined:
    Nov 29, 2017
    Posts:
    14
    Well, I'm really wish to help you but I think my skills with scripts aren't good enough (
    And moreover I have no PC computer.
    But thank you! Though there's no needs to do it right now, still waiting for update desperately!
     
  42. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    what kind of update?
     
  43. Lacostic

    Lacostic

    Joined:
    Nov 29, 2017
    Posts:
    14
    I mean this, no chance?
    edit2:
    i might upload tomorrow hdrp support fort 2019.1
     
  44. Lacostic

    Lacostic

    Joined:
    Nov 29, 2017
    Posts:
    14
    And by the way, it works without WindNode and LeafWindNode scripts, just become static of coarse
     
  45. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    yep.. that’s what the big diffrence in hdrp is. they changed the way how you can create custom nodes(code based nodes) in 2018 you use an external file and attach it to the shader. in 2019 it’s an internal based node with a text field solution
     
  46. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    For preparation to HDRP 5.x i've updated the MTree shaders with provided Code from Maxime Herpine.(Amplify Shader Code).

    Thats new / Improved:

    - Sub Surface Scattering (Improved)
    - Translucency (Improved)
    - Bark Detail Map with blending from bottom to Height (new)


    Well it's not a lot but porting it to Amplify makes sense, so it'll be easy to create several Version (Normal / HDRP / LWRP) with just a few clicks.

    Everybody can adjust the Shader to fit's its needs with Amplify..

    HDRP 5.x and maybe LWRP 5.x will be provided next week someday


    Asset Package can be downloaded at Github: https://github.com/danwipf/MTree-Addons
    MTree-Addons/MTree Shaders/Mtree Amplify Shaders.unitypackage

    This will replace the standard Leaf / Bark Shader from MTree.
     
    Last edited: Jul 21, 2019
  47. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    Is anyone interested to get my updates/upgrades on the Asset Store (Still free of charge), or do you prefere as it is?

    Just thought about that it’s easier to stay on Track with the updates, unless you Clone the repo..

    Would be nice to have some Feedback about this.

    dan
     
    Artomiano and CaliCoastReplay like this.
  48. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    I prefer with github personally. Whatever is easier on your end though works for me
     
    dan_wipf and Willbkool_FPCS like this.
  49. blacksun666

    blacksun666

    Joined:
    Dec 17, 2015
    Posts:
    214
    It's a lot quicker to get updates out of github as there is no need to wait for Unity to approve the update.
     
    dan_wipf likes this.
  50. dan_wipf

    dan_wipf

    Joined:
    Jan 30, 2017
    Posts:
    314
    That’s so true!

    Well i just didnt heard a thing from Maxime Herpin, since a month or two. Hopefully he will return and not abandon this Asset.