Foliage
Last updated
Last updated
For this example, we'll be using the following meta graph as base:
To spawn the foliage, we will need to do line traces against a physics scene. Create a new one:
Add a new Generate Marching Cube Collider node to your meta graph, assigning the physics scene you just made to it:
This node will populate the physics scene with marching cube colliders we can use to line trace our foliage against.
Create a new foliage asset:
In the foliage asset, switch to the Foliage Graph at the top right:
Add the following nodes:
To convert the Vector2D output of the Generate Halton Position 2D node to a Vector, just drag the Vector2D pin to the Vector one. Make sure to set the Z value to 1000000.0.
Make sure to also assign your physics scene and a mesh.
This graph does the following:
Generate some 2D positions using a Halton random generator
Line trace against the colliders we generated earlier
Assign a mesh to the hit positions
Render the hit positions
Back into your meta graph, create the following node:
You should now see spheres being spawned in your level!
If you increase your Distance Between Positions in your foliage graph to 500:
You'll get less dense spheres:
To restrict the slope at which your foliage spawns, you can use the following logic:
20 is the max spawn angle in degrees here. This gives you the following (with tuned noise settings):
Follow Brush & Channels, but keep our current meta graph. This should get you setup with some simple brushes and a voxel channel. Alternatively, follow Installing Example Content.
Add the following nodes at the end of your foliage:
This will query the distance from MyChannel at the foliage position, and only select foliage which are less than 10m away from the brush.
This results in this behavior:
Spawning foliage on foliage is just a matter of outputing foliage colliders into a new physics scene, and tracing against that physics scene.
Make a new physics scene, name it FoliagePhysicsScene:
Duplicate your foliage graph, and add the following at the end:
Make sure to add your new foliage in the Generate Foliage node of your meta graph.
You should be getting something like this:
In your "small foliage" graph, add a new line trace node tracing against our foliage physics scene. Merge the result back into our main attributes:
You should now see foliage being spawned on top of other foliage!
You can create foliage collection to make it easier to reference your foliage in your meta graph
You can toggle Debug on the line trace nodes. This will show you the traces being done
Just like with brush assets, you can make foliage asset instances!
You can increase the LOD of your line traces. Going from LOD 0 to LOD 1 will be ~8x faster