1. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  2. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  3. All Unity Pro perpetual license customers: your special offer to subscribe is ready! Click here.
    Dismiss Notice
  4. Unity 5.5 is now released.
    Dismiss Notice
  5. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  6. Unity 5.6 beta is now available for download.
    Dismiss Notice
  7. Get prepared for the Tizen Mobile App Incentive Program! Read more about the upcoming program here.
    Dismiss Notice
  8. Enter the Microsoft Developer Challenge for a chance to win prizes. Read more about it here.
    Dismiss Notice

L-Systems for Unity (free script included)

Discussion in 'Works In Progress' started by chanfort, Oct 6, 2014.

  1. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    I created startup point for L-Systems implementation for Unity. Here are first results, as well as free script, which allows to create these plants.
    I also made possibility to create small forests of these randomly generated trees, however, as script is not very well optimised and as there are large amount of polys, current approach might be not very practical.
    Suggestions, impressions and other things are welcome in this discussion.
    Screen Shot 2014-10-06 at 00.45.21.png Screen Shot 2014-10-06 at 00.46.37.png Screen Shot 2014-10-06 at 00.49.13.png View attachment 114661
    Screen Shot 2014-10-06 at 00.47.33.png
     

    Attached Files:

    Last edited: Oct 6, 2014
    EBR, Kurt-Dekker, Eric2241 and 2 others like this.
  2. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
  3. KirbyRawr

    KirbyRawr

    Joined:
    Jul 23, 2012
    Messages:
    877
    This can be an awesome plant/tree creator if you continue with it.
    Good luck!
     
  4. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    Thanks, I am looking to bring this to something similar like in TreeSketch:
    http://algorithmicbotany.org/TreeSketch/
    It took me just one day to build this system from primitive cones. However, it may took longer till we will have realistic trees like in nature.
     
    calmcarrots and KirbyRawr like this.
  5. KirbyRawr

    KirbyRawr

    Joined:
    Jul 23, 2012
    Messages:
    877
    Looks so cool i wish you good luck!
     
  6. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    This weekend news:
    Screen Shot 2014-10-13 at 01.55.07.png 1. Rewritten vertices, normales, uvs and triangles arrays. This allows to remove non visible vertices and to smoothly spread tree branches.
    2. It looks like even with almost 1M vertices FPS are still very high.
    3. This tree is currently only on 2d plane (perpendicular to camera view in the figure) as I still didn't found why in 3d it messes up. It might be a quick trick, so keep eye onto it.
     

    Attached Files:

    moure and KirbyRawr like this.
  7. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    I continued to look at this issue for last days but I got unable to find the issue why in 3d tree messes up. Unfortunately I was unable to find the solution. Here is the result how it looks like with the issue.
    Screen Shot 2014-10-14 at 20.19.34.png Screen Shot 2014-10-14 at 20.20.06.png
    If somebody would be interested, a bit of help would be needed. This script will remain as free and everyone will be able to use it.

    Now here are some of my remarks.

    The idea.

    The script is based on generating primitive cones, given here. In my script cones got removed caps, so branch endings are open. Once first cone is made, bottom side of next cone takes all vertices positions from the first cone top side. Recursively continuing this gives continuous single branch spreading.

    Each cone (segment) has a possibility to create a seed for new branch. When it happens, segment location and rotation is recorded as a new branch initial point. New branch starts to be generated once the old one is completed.

    In 2d plane I was manually assigning rotation for Vector3 (0f,0f,1f), so branches could rotate in z direction by given angle. The same is for any (x,0f,z) direction if parent branch is going along y axis (to (0f,1f,0f) direction). However, if parent branch is not going to (0f,1f,0f), similar effect appear like in pictures above.

    I will keep an eye to the issue, but to bring these trees to life, I need a bit help. Feel free to post here or in a message if you interested. And remember, my posts are "never dead".
     

    Attached Files:

    KirbyRawr likes this.
  8. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Messages:
    5,847
    Very nice work. I am working on L-systems, but with prefab brances, so i cant pinpoint this exact problem with this approach.

    But one guess is that it gets the start points from the end points of the parent cylinder, like the single branch case. That is what it seems to do from the pic, plus this explains why it would be fine if the cylinder was looking at the Y axis.

    EDIT:
    Also if the angle changes, the shape would change accoringly, so it will vary, again like the pics show. My guess is that you have to decouple the branch start point from the parent end points, or use an angle close to parent local Y axis, so the skew is not evident.
    .
     
  9. KirbyRawr

    KirbyRawr

    Joined:
    Jul 23, 2012
    Messages:
    877
    I would like to help but i really don't have a lot of time since i'm working on othe projects some of them for free, but i will try to take a look at it :)
    Thanks for your work!
     
  10. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    Thanks a lot for replies. I just found and fixed some issues related with that, but not completely.
    Screen Shot 2014-10-15 at 03.00.13.png Screen Shot 2014-10-15 at 03.02.22.png
    I added more parameters and corrected initial rotations for new branches. Now connection points looks much better. However, I notice another issue to exist here. Small trees looks ok, but once I am creating a bit larger trees, I noticed that 3, 5, 7... order branches are likely to point up like candles. 2, 4, 6... order branches are looking good - they are twisting like they expected to.
    I am calculating new branch rotation with perpendicular vector3 to parent branch and finding it with Vector3.Cross(). However, I suspect that something weird is happening when I am applying Vector3.Cross() second time and so on. Is anyone familiar with something like that?
     

    Attached Files:

  11. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    Hey, nasos, well, the issue here was not that branches start point changes its shape, but that tree branching angles are incorrect. So tree skeleton is calculated not correctly. This would be the same also for prefabs or other things you use to visualise skeleton lines.
     
  12. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Messages:
    5,847
    I think we say the same thing :), if the angle was right it would not show this flattening effect so much.

    From the pics it seems you start the branch at the end of the previous cylinder, unless i am mistaken :)

    If this is the case, there is no way to avoid some degree of flattening unless one cylinder is directly above the other one. And i am sure if you play with the angles in the right way, it could show perfect, just a give a smaller angle to the start branch to avoid the flat look and move from there accordingly
     
  13. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    well, it's not about flattening. This flattening is quite easy problem, as I could simply rotate and stretch initial part of segment, that it would be along the direction of new branch (it's just a few lines of code). The issue here is that angles are assigned not as I wish. For one branches they are 7 degrees, as I assign, but other branches start with degrees close to 90 and I can't find why is that happening.
     
  14. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Messages:
    5,847
    I see. How do you do the rotation ? Use Quaternion or Euler ?
     
  15. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    Quaternion and then multiply by vector3. I apply segment final rotation first and then rotated segment offsetting to it's position.
     
    Last edited: Oct 16, 2014
  16. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    I continued to look at the issue. Now I made parent branches to stop spreading once child branch is created. This is the picture.
    Screen Shot 2014-10-16 at 01.46.16.png
    I would expect from my code that branches would spread spherically to all directions. But there is still the trend for branches to move up. Does anyone got any ideas what can be wrong here?
     

    Attached Files:

    KirbyRawr and judah4 like this.
  17. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    Something better is coming up :). Branches are now not staring upwards, but spherically to all directions. However, they are all pointing to (0,0,0), but not to their local growth point as I want :(
    Screen Shot 2014-10-16 at 13.57.42.png
    Still can't find out what's wrong going on here...
     

    Attached Files:

  18. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    Finally, after so long confusion I sorted out this issue. Now the trees looks like in this picture and their branches are spreading from their local points. I think you can now get idea what I mean in previous posts.

    Screen Shot 2014-10-17 at 21.06.30.png
    I will now keep looking at some more fundamental spreading rules to bring up larger variety of species. At some point I will need to add textures and leaves. However, I am not sure yet about leaves - got any ideas how to make them?
     

    Attached Files:

  19. KirbyRawr

    KirbyRawr

    Joined:
    Jul 23, 2012
    Messages:
    877
    You can place quads for the leaves based on the lenght of the cones maybe?
    Oh and by the way, awesome job you are doing, i think you should work more on this and do a tree editor or a bush editor and sell it on asset store
     
  20. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    I may try to think - maybe I will setup some prefabs for leaves at the beginning.

    Well, could be that new asset will come up. But my plans currently are more related with my current uRTS asset, where I want to combine most natural things for RTS games - from battles to nature environment. In uRTS is already implemented 3dSprites system, which allows to use well aligned images instead of using 3d object in actual game. If I will make realistic trees, I can make any kind of details (even millions of polygons per model) from them to be visible in game.
     
    KirbyRawr likes this.
  21. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    I think "dead trees" (without leaves) will be ready soon for Asset Store :)
    Screen Shot 2014-10-19 at 02.51.25.png
    Screen Shot 2014-10-19 at 02.56.58.png
     
    KirbyRawr likes this.
  22. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    My trees are starting to show some life. But there is a big winter coming ahead... :)
    Screen Shot 2014-10-29 at 23.55.29.png
    Screen Shot 2014-10-30 at 02.15.16.png
     
    Last edited: Oct 30, 2014
    nasos_333, judah4 and KirbyRawr like this.
  23. Pawl

    Pawl

    Joined:
    Jun 23, 2013
    Messages:
    80
    Hey chanfort, this is looking pretty good. I've done some undergrad work with L-System fractals myself, so I hold this topic dear to my heart and encourage you to keep at it!

    Do you plan to offer something unique that Unity's tree system or SpeedTree can't provide?
     
  24. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    Hi Pawl, nice to hear from you. Well, my goals are not to compete with Unity tree system or SpeedTree. My goals are to bring reality from nature into Unity.

    Are you still working sometimes with L-Systems?
     
  25. KirbyRawr

    KirbyRawr

    Joined:
    Jul 23, 2012
    Messages:
    877
    Hey Chanfort this looks cool, keep it up, if you make a affordable and good tree creator i will buy it for sure.
     
  26. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    I just started to add leafs with various rotations and alignments. But still not achieving results which we see in nature:
    Screen Shot 2014-11-02 at 02.31.27.png Screen Shot 2014-11-02 at 02.33.22.png
    I found the issue that leafs looks very flat as I am using textures on plane. Does anyone know how to treat this issue?
     
    KirbyRawr likes this.
  27. KirbyRawr

    KirbyRawr

    Joined:
    Jul 23, 2012
    Messages:
    877
    You can do like a split in the middle of the planes and put the middle vertex a little up, it will give them a little 3D effect.
    Also change the shader you are using maybe it helps you to achieve something cool :D
     
  28. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    Thanks, I may try it :)
     
    KirbyRawr likes this.
  29. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    There is another issue: leafs are transparent
    Screen Shot 2014-11-02 at 16.34.04.png
    I am using "Particles/Alpha Blended" shader for leafs, as it gives nice transparency in these planes, where it should be transparent. Does anyone know if this is currently the best shader for these kind of "decals"?

    Oh, and here is the texture I am using:
    mapple_leaf.png
     
  30. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    I just find out that there is shader "Unlit/Transparent Cutout" with which things go much better:
    Screen Shot 2014-11-02 at 18.48.04.png
    So as it is unlit, there will be no lighting effects for a while :( . Other shaders I tried seems to be broken... Particle ones even making more distant leafs in a front of LOS, i.e. most distant leafs are shown first if looking from the bottom side. Only when looking from the top decals are shown correctly...
     
    KirbyRawr and red2blue like this.
  31. KirbyRawr

    KirbyRawr

    Joined:
    Jul 23, 2012
    Messages:
    877
    Mmmm if you want i can do some shader for you ; )
    And maybe you can include vertex color generation to the leafs so you can bend the leafs/branch via shader, like the wind from unity.

    If you have anything for talk, like skype etc.. pm me, if not we can talk here or via pm about the shaders, i will give you them for free : )

    Edit:
    [​IMG]
     

    Attached Files:

    Last edited: Nov 2, 2014
    red2blue likes this.
  32. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    I just played with these shaders and vertices and here are some results even for small tree models. This one contains about 40k vertices (not millions) and is done "on the single click":
    Screen Shot 2014-11-02 at 23.28.41.png
    It also has different textures for top and back sides of leaves. And in general it looks a bit more realistic. So realism does not always depend on number of vertices - it depends on where and how we place them...
     
    KirbyRawr likes this.
  33. KirbyRawr

    KirbyRawr

    Joined:
    Jul 23, 2012
    Messages:
    877
    Yeah that's a little high for a single tree : / , around 3000 or 5000 is the normal i think, because if you do lods it's not a problem.
     
  34. Pawl

    Pawl

    Joined:
    Jun 23, 2013
    Messages:
    80
    I don't work with them much anymore, but this is an example of what we achieved on a student game project with L-System fractals in 2009 (the game is called Kabloom). After generating the tree shape using the L-System rules, we used a single tree branch model that was scaled, rotated & translated to build the tree. We also used another model for the tree trunk.

    [​IMG]

    If you look closely, unfortunately you can see a seam where the models meet, but hey we were just students! =P

    [​IMG]

    This was the paper I based the L-System implementation from:
    http://algorithmicbotany.org/papers/abop/abop-ch1.pdf
    http://algorithmicbotany.org/papers/abop/abop-ch2.pdf
     
    Last edited: Nov 3, 2014
  35. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    Hey Pawl, your trees looks lovely. You are very welcome to our discussions here.
     
  36. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    Soon we may have something to decorate for upcoming Christmas:
    Screen Shot 2014-11-09 at 00.33.26.png

    And it's elder sister:
    Screen Shot 2014-11-09 at 01.01.36.png
     
    Last edited: Nov 9, 2014
    KirbyRawr likes this.
  37. KirbyRawr

    KirbyRawr

    Joined:
    Jul 23, 2012
    Messages:
    877
    It looks really cool, maybe you can make the branches less perfect?
     
  38. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    Yes, I am looking forward now how to add small rotation upwards at the endings of branches and some small variations. I also need to work out with spruce needles, but I haven't textures yet for them :(
     
    KirbyRawr likes this.
  39. KirbyRawr

    KirbyRawr

    Joined:
    Jul 23, 2012
    Messages:
    877
    It's looking good even without textures : )
     
  40. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    Well, rotation at the endings of branches is here:
    Screen Shot 2014-11-09 at 16.10.08.png
     
  41. orb

    orb

    Joined:
    Nov 24, 2010
    Messages:
    2,078
    This needs a non-branching option, for tentacles :)
     
  42. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    What is that?
     
  43. orb

    orb

    Joined:
    Nov 24, 2010
    Messages:
    2,078
    I meant an option that just grows the core stems :)
     
  44. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    you mean to grow older segments and keep pushing everything along branches?
     
  45. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    First attempts to add spruce needles. I also generated small forest from several spruces. However, polycounts are still also impressive :)
    PicturesMod.png
     
    KirbyRawr likes this.
  46. KirbyRawr

    KirbyRawr

    Joined:
    Jul 23, 2012
    Messages:
    877
    It's looking really awesome : ) Keep it up but try to optimize them hahaha.
     
  47. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    I know. Well, distant trees will go onto 3dSprites, which I am using, so polycounts doesn't matter there. The problem is for nearby trees, which should be nice to keep as full models. I am also looking for a way to export these trees to fbx.
     
  48. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    Starting to get better results.
    mosaic21.png mosaic22.png
    Unfortunately 2/3 of vertices on these trees are in leaves (spruce needles), as I am approximating each leaf as a plane from 4 vertices. Does anyone know what can be best approaches for leafs? Maybe it is possible somehow to group them?
     
    KirbyRawr likes this.
  49. KirbyRawr

    KirbyRawr

    Joined:
    Jul 23, 2012
    Messages:
    877
    The leafs are usually render by texture with large faces, but this is very realistic and awesome, did you lower the polys?
     
  50. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Messages:
    454
    No, polys are still the same. But if you see, there are branches now at the endings of trees, what means, that quite large amount of branches deep in the tree is avoided.

    With "hard" wooden part of the tree (branches) it's easier, as I can use tubes with 6 walls instead of 18. This will move polycount roughly 3 times down. Another thing, which can be more useful is to make segment lengths only rotation dependent. This can free up quite large amount of polys from hard part.

    However, leaves... I am confused how to set up these larger faces. Are they some kind of volumes around endings of branches, where texture is applied on their surfaces?
     
    KirbyRawr likes this.