Point Culling inside other instances

The Idea

The newest implementation of Geometry Nodes inside Blender has sparked the imagination of a lot of people with endless possibilities. One of the most clear examples is to use it to randomly distribute objects over a mesh’s geometry, this way you can create cool VFX, procedural terrains, etc. For this I wanted to create a procedural terrain generator, you would have a collection of big elements, one of pebbles and one of grass, and the geometry nodes would give you all the customizable options you could dream of. But I ran into a problem…

The Issue

The issue sprung from the combination of several layers of instances being spawned. In particular, grass being spawned inside the big elements. I tried using a Geometry Proximity node, but this only worked for small objects (in the example, pebbles), since in bigger objects, the separation between faces would allow for grass to still spawn inside the bigger objects.

I tried many solutions, from Mes Boolean nodes to trying to calculate everything by maths. I kept running into the same issue, the solutions either were too resource intensive, or simply didn’t work for different shapes, or when the terrain was not uniform. Until I found a solution using Raycast!

The Solution

The idea is to project a Raycast from above, and use it as a mask to eliminate the points that were inside the objects. To achieve this, no worries, it is quite simple, this is what you do:

First you calculate the instances as you prefer for the big objects, being either from a hand placed collection or from a Distribute Points on Faces, whatever works better for your project. Then, you use a Realise Instances node, so they are calculated individually, instead of as a big bounding box. You connect that node to the Raycast Node’s Target Geometry socket, this will tell the Raycast which geometry to look for, so you can leave the Ray Direction as 0,0,-1, since the ray looking from above will give us the more accurate result. Then, you connect the Is Hit socket from the Raycast into a Boolean Math Node and change the Operation to Or. Finally you can use a Delete Geometry node, connecting the result of the Boolean Math into the Selection socket.

Now, you can use that geometry node to calculate the places where you want grass growing, and there you have it, a lower impact solution on your computer resources!

Of course, depending on the type of geometry you are working, this solution might not be perfect for you, but you can play with the angle of the ray (using the instance’s positions for example), to get the same result.

I hope this was helpful, and you can download a test file here.

Back to Tutorials