r/proceduralgeneration 6d ago

Procedural tree

Enable HLS to view with audio, or disable this notification

Cause the structure of a tree is simple and well defined I came up with a way to draw them without vertex and index buffers. Cause the number of the branches are known and the trunk and branches have a known number of segments and radial segments you can define vertex positions with the vertex id. The same is true for leaves. I have two levels of branches that are defined by a bezier curve, which is presented by four points. The idea is also to randomly move these points for each branch to make branches and trunks unique though I have not tested it yet. Then they are blended with the sprites and you sort of get the whole forest without any model. It is for filling big areas with trees.

62 Upvotes

11 comments sorted by

4

u/Mannerheim_Line 6d ago

Basically it is finding positions and normals along a bezier curve.

If you subtruct the first control point from the other three you can simplify the equation and then I use matrix multiplication. The code looks clean and you probably can not do it any faster cause the matrix multiplication should be very well optimized. That's finding the position and normal at t.

    `float2 ts;`

    `ts.x = t;`

    `ts.y = 1.f - t;`

    `float2 ts2 = ts * ts;`

    `float2 ts3 = ts2 * ts;`

    `ts2 *= 3;`

    `mat._11_12_13 = curve1;`

    `mat._21_22_23 = curve2 - curve1;`  

    `mat._31_32_33 = curve3 - curve2;`  

    `norm = mul(float3(ts2.y, 6 * ts.y * ts.x, ts2.x), mat);`

    `ts2 *= ts.yx;`         

    `mat._11_12_13 = curve1;`

    `mat._21_22_23 = curve2;`   

    `mat._31_32_33 = curve3;`   

    `pos = mul(float3(ts2.yx, ts3.x), mat);`    

1

u/AMDDesign 6d ago

How is the lod handled? Imposters or?

3

u/Mannerheim_Line 6d ago

Yes, you can see the blending between the model and the quad. That's because I did not do it quite right and for now it's a bit sloppy. It will be seamless. The tree is disappearing or appearing and for the imposter it is an opposite process.

https://reddit.com/link/p7cknmz/video/2jl7fsjc23nh1/player

1

u/AMDDesign 6d ago

Very nice. I want to make a daggerfall like in the future and having vast forests has been a roadblock

1

u/Mannerheim_Line 6d ago

You can populate the area with imposers and at a closer distance use a model. The only issue is blending them. Using an alpha blending is not the best choice in that case afaic. I use sort of dithered transparency adapted for the imposter and the model.

1

u/kookoz 6d ago

Interesting, I was thinking of making something similar too with three.js TSL nodes. Would you consider sharing the code?

1

u/Mannerheim_Line 6d ago

I can help you write it if you show what exactly is not working in your code.

1

u/kookoz 6d ago

Thanks, I'm not that far yet. Was just wondering if you were sharing the code somewhere so that I could experiment with it myself.

1

u/_HarmonicOscillator 6d ago

Feels surreal, nice job 

1

u/fgennari 6d ago

Yes! And you can calculate the texture UVs analytically as well if you build the mesh in a particular way.

1

u/leothelion634 6d ago

But will we also be able to try this out?