- Edited
Create trees with wind effect
- Godot_v4.0-beta9/10
- Tree It (4/1/2023)
Based on the Making trees tutorial.
This is not a tutorial, but rather a hint, a short note to a tutorial on creating trees. This tutorial suggests taking the tree model from SketchFab. But there is another way to do it. If you use the free program TreeIt (no need to register to download, for what a huge thank you to the author), you can skip the step "Paint with vertex colors" — the program will do it yourself.
The program is constantly updated. You can guess about the new version of the program, you can by the date of release.
The program has an additional library of trees.
Choose the desired type of tree and use settings to achieve a suitable result.
Next, the tree model is exported to .fbx
Godot 4 well understands the format .fbx
The resulting file is placed in a scene and begin editing:
New Inherited Scene → Open Anyway
The scene will have several Tree_* nodes (Tree_0; Tree_1 etc.)
Need to go into each of these nodes
MeshInstance3D → Mesh → Surface 0 → Material → Vertex Color
Uncheck the box "Use as Albedo".
And Convert to ShaderMaterial.
In the shader you need to add the lines from the tutorial the code to create the sway of the leaves . Replace them with the vertex block.
Only in the line :
float strength = COLOR.r * sway_strength;
must be replaced by COLOR.r
(red channel) with COLOR.b
(blue). The point is that Tree It itself paints the tree to implement sway from the wind and you don't have to do it manually.
This section should look like this:
uniform float sway_speed = 1.0;
uniform float sway_strength = 0.05;
uniform float sway_phase_len = 8.0;
void vertex() {
UV=UV*uv1_scale.xy+uv1_offset.xy;
float strength = COLOR.b * sway_strength;
VERTEX.x += sin(VERTEX.x * sway_phase_len * 1.123 + TIME * sway_speed) * strength;
VERTEX.y += sin(VERTEX.y * sway_phase_len + TIME * sway_speed * 1.12412) * strength;
VERTEX.z += sin(VERTEX.z * sway_phase_len * 0.9123 + TIME * sway_speed * 1.3123) * strength;
}
By setting variables in the global uniform can change the strength of the wind across the scene.
It should look like this: