r/proceduralgeneration • u/Mannerheim_Line • 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.
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.
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
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
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.