Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411423 Posts in 69363 Topics- by 58416 Members - Latest Member: JamesAGreen

April 19, 2024, 12:45:04 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Generating Trees and other Vegetation procedurally
Pages: [1]
Print
Author Topic: Generating Trees and other Vegetation procedurally  (Read 10544 times)
nikki
Level 10
*****


View Profile
« on: December 25, 2009, 05:16:06 PM »

Hello there !
I am looking into this and found out about L-systems, and other methods to create vegetation/trees randomly.
Has anybody here had any experience in them? And would you be so nice to tell about it ?

Logged
mobilebros
Level 0
*


View Profile
« Reply #1 on: December 25, 2009, 09:13:01 PM »

I second this request... but in lieu of trying to be helpful, here's a site that talks about a few algorithms that may be of interest, especially the natural phenomena section: http://krazydad.com/bestiary/
Logged
nikki
Level 10
*****


View Profile
« Reply #2 on: December 26, 2009, 03:16:56 AM »

I've found some interresting links aswell :
http://algorithmicbotany.org/papers/#abop
http://www.vterrain.org/
http://pcg.wikidot.com/pcg-algorithm:plant-generation

But there is a lot of academic research and closed source information in those links, and i don't understand those crazy mathematical scribbles  Who, Me? .......
Logged
Core Xii
Level 10
*****


the resident dissident


View Profile WWW
« Reply #3 on: December 26, 2009, 04:00:38 AM »

You should check out Context Free. It's a simple program for generating essentially L-systems. It'll help you understand how to proceed with procedural plants.

I generated the plants in these mockups with it: (I didn't put that much effort into it, I can do better)





A closer look at the generated plants:

« Last Edit: December 26, 2009, 04:07:52 AM by Core Xii » Logged
kiwi
Level 0
***


View Profile WWW
« Reply #4 on: December 26, 2009, 04:25:52 AM »

Here's an article that shows how to draw fur in XNA http://www.sgtconker.com/2009/10/article-fur-rendering/
The same basic principle can be applied to draw grass or conifers
Logged

kometbomb
Level 0
***


View Profile WWW
« Reply #5 on: December 26, 2009, 05:00:28 AM »

I don't know if this is an L-system or something else (like the Koch snowflake) but here's how to create some 3D trees by recursively replacing seed data, much like in a L-system:

1. First you have a triangle, let's say this is a "root" triangle
2. Subdivide into 4 triangles (i.e. add midpoints to each edge and connect them)
3. Adjust the midpoints upwards
4. The new center triangle should now be called the "trunk" triangle. The other triangles still are root triangles but mark them finished, i.e. they won't be subdivided
5. Extrude the trunk triangle along the normal. The sides should be "bark". Also, add random variation to the new triangles
6. Repeat step 5, generally each iteration will make the tree taller
7. Now that the tree is tall enough (i.e. some trees have the branches much closer to ground), that topmost trunk triangle should be divided to any number of triangles called "branch". Make sure the branch normals point outwards from the trunk so the branches go more to the sides.
8. Do the same as in step 5. Also, make sure the newly generated branch triangles get smaller in each iteration
9. Repeat the branching as much as you see fit
10. The final phase should be something like midpoint subdivision, which makes the triangular trunk more circular. You can also add some randomness since nature is not so symmetrical. Some trees like pines should probably have less polys along the branch.



Now you have a 3D tree (without leaves), and a lot of triangles. The triangle types tell you what texture to use. Leaves can be created by making the branches create new polys along the edges (so the branches have fins like a rocket) and applying some nice transparent texture that has small branches and leaves drawn in.

As an L-system, you could think this something like (B = bark, T = trunk, R = root, Br = branch):

R -> R T R -> R B T B R -> R B B T B B R -> R B B Br Br B B R -> R B B B Br B B Br B B B R etc.
Logged

zamp
Level 1
*



View Profile
« Reply #6 on: December 26, 2009, 12:18:31 PM »

Try look into self repeating fractals. Using fractals is the easiest way to get plantation (shrubs etc)
http://images.google.fi/images?client=opera&rls=en&q=plant%20fractal&sourceid=opera&oe=utf-8&um=1&ie=UTF-8&sa=N&hl=fi&tab=wi

For trees (pine tree). The basic method is:
1. make any size trunk
2. split trunk from top to bottom with ^(1.1-2) increments
3. add branches to splits
4. apply same algorithm for trunk splitting to branches but with different values (random seed)
Logged
Mikademus
Level 10
*****


The Magical Owl


View Profile
« Reply #7 on: December 28, 2009, 12:35:23 PM »

If you want to really learn the things, I recommend the book "The Computational Beauty of Nature" by Gary Flakes to you.
http://www.amazon.com/Computational-Beauty-Nature-Explorations-Adaptation/dp/0262561271
Logged

\\\"There\\\'s a tendency among the press to attribute the creation of a game to a single person,\\\" says Warren Spector, creator of Thief and Deus Ex. --IGN<br />My compilation of game engines for indies
mobilebros
Level 0
*


View Profile
« Reply #8 on: December 29, 2009, 08:22:35 PM »

Wow this is a pretty sweet list, especially that context free art application.... now if I only had the courage to learn another "language"
Logged
nikki
Level 10
*****


View Profile
« Reply #9 on: December 30, 2009, 07:03:32 AM »


On    Hand Point Right  my DEVLOG    Hand Point Left I just have started with some experiments .
eventually i could whip up a tutorial .
But first i'll have to master ..



Logged
nikki
Level 10
*****


View Profile
« Reply #10 on: January 03, 2010, 03:38:24 AM »

Another related question.

Whilst making the generative tree, somebody pointed me at the niceness of trees that move by the wind, Originally I had planned on generating tree and saving that image (as a single image) , when you want the wind, or any other movement i'm guessing this needs to be improved.

If you break the tree up in a few images, (trunk, branch with leaves, branch with leaves etc) I could move those images about.

I wouldn't know how though. A simple rotation is not really what i am aiming at, its looking more like a sinus warp or something.

Anybody here got some ideas ?
Logged
Tycho Brahe
Level 10
*****

λx.x


View Profile
« Reply #11 on: January 03, 2010, 03:42:20 AM »

If you take a look on openprocessing there are usually quite a few l-system sketches, and a couple (if I remember rightly) that move around, as if they were in the wind.
Logged
nikki
Level 10
*****


View Profile
« Reply #12 on: January 03, 2010, 05:27:08 AM »

well the moving part wouldn't be the hardest.
especially not if you keep all the data.
I believe it's a matter of changing some angles here and there.

But what I fear of that method is keeping all the data (for all the branches and everything)
in memory, and worse applying calculations on a lot of those sets during runtime.

I think it's alot faster if i'd break a tree up in a few! branches , save those images locally, and warp the images to give the 'same' effect.
that way i could re-use more assets, and have less calculations and draw routines.


right?
[goes off to google some more about this]
Logged
Tycho Brahe
Level 10
*****

λx.x


View Profile
« Reply #13 on: January 03, 2010, 05:57:09 AM »

Hmm, it shouldn't be TOO heavy on memory unless you had a lot of them...
At least, you would probably have about 2^n nodes (where branches split) or branches, although that might be too much, I don't know...
Logged
kiwi
Level 0
***


View Profile WWW
« Reply #14 on: January 03, 2010, 07:53:03 AM »

I think you should try it, optimize it as much as you can, and if it works,keep it.
As far as spacial complexity goes, I don't think you have to worry about that, most computers have enough memory for games to hog.
Also let's think for a moment, let's say that every tree is made through a level 5 recursion. Then you'll have 1+a+a^2+...+a^5 nodes (which I presume are actually points in space) where a is the number of branches you use to make the tree which again I presume is on average 3.
That's (1-3^6)/(1-3) nodes = 364 nodes per tree. But each node is actually a point, which in turn is made out of two floats that take up 32 bits in memory, so each node takes up 64 bits.
So each tree would take up 364 * 64 = 23,296 bits in memory, that's roughly 23 kB. So for 10-20 trees you'll end up having somewhere under 500kB (gross approximation) which isn't that much if you ask me.

One way I can think of to optimize this thing would be to make just 2-3 trees that you reuse throughout the game. So at the beginning of the level you generate 3 trees, you apply the wind effect and any transformation you might have in mind on them and then you render each one on the screen 3-4 times something like that.
If you'd like to have more variation you could scale/skew the tree before you render it on the screen.

Or you could try to use the GPU to generate the vegetation procedurally, but I'm not that sure how easy it would be to implement because I've never tried it.
Anyway, good luck in your research, hope you manage to find what you need.
Logged

nikki
Level 10
*****


View Profile
« Reply #15 on: January 03, 2010, 05:57:53 PM »

most of your presumptions are super right !
only not this part
Quote
So for 10-20 trees

The terrain i am going for will represent 1024 x 1024 meter, in the case of a delicious forest this would mean alot more then 10-20; more like 2500-5000 i'm guessing

So the skewing,flipping and scaling option had crossed my mind aswell.
And same as with you, the GPU i don't know nothing about it. Could look into that but i think another time Smiley

I'll make some tests and show.
I hope
thanks
Logged
nikki
Level 10
*****


View Profile
« Reply #16 on: January 06, 2010, 08:26:58 AM »


The swaying trees test is done
the link points to the devlog, over there is a screenshot and the test application (win directx).

I am curious if someone has slowdowns, memoryleaks,driver issues or other nastiness..

edit: A much nicer test is done
« Last Edit: January 07, 2010, 01:30:20 PM by nikki » Logged
eigenbom
Level 10
*****


@eigenbom


View Profile WWW
« Reply #17 on: January 06, 2010, 05:59:10 PM »

Here are some random procedural tree refs Smiley Panspermia is a great vid, I'd love to see that kind of worl in a realtime game.

http://www.karlsims.com/panspermia.html
http://citeseer.ist.psu.edu/old/414011.html
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.29.9928
http://members.chello.nl/~l.vandenheuvel2/TReal/ (algo: http://portal.acm.org/citation.cfm?id=218427 )
Logged

Golds
Loves Juno
Level 10
*


Juno sucks


View Profile WWW
« Reply #18 on: February 10, 2010, 05:33:54 AM »

Ran across Frecle's Tree[d] today.



Looks like a great free tool for creating leaf/branch textures for use in doing fancy billboarded trees.

My friend Dan is using it for texturing the trees in his latest project:



Anyway.  looks pretty rad.
Logged

@doomlaser, mark johns
Zaratustra
Level 7
**



View Profile WWW
« Reply #19 on: February 10, 2010, 05:52:05 AM »

google for "speedtree"
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic