Skip to content
ImagineWorld

Distributing Instances onto a Mesh

node_idnode-book_procedural-3d-modeling-using-geometry-nodes-in-blender_chapter-05-distributing-instances-onto-a-mesh
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num5
chapter_titleDistributing Instances onto a Mesh
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

Chapter 5 — Distributing Instances onto a Mesh

Section titled “Chapter 5 — Distributing Instances onto a Mesh”

In this chapter, we will learn how to distribute instances onto our mesh. To do that, we first need to distribute points onto a Grid primitive, and only then can we distribute instances on those points. Being able to distribute instances on our mesh is crucial when we want to scatter multiple objects around our scene; for example, in a forest scene where rocks, grass, and leaves are scattered throughout the scene.

We will also look at how to randomize these instances and the use cases that randomization presents. Randomization is one of the most important factors for photorealism, as it can be the make-or-break for many of our scenes. We will also learn the first steps in making a useful Geometry Nodes project.

In this chapter, we will be covering the following subjects:

  • Distributing points onto a Grid primitive
  • Instancing objects on points
  • Randomizing instances
  • Experimenting with Group Inputs
  • Exercise – creating a grassy field
  • Using Group Inputs to add sliders to the modifier

Some figures in this chapter show the full Blender setup, including node trees, outcomes, and parameter settings. For easier viewing and readability, these figures are also available in the book’s GitHub repository.

You can find the exercises and demos from this chapter in the common .blend file in the GitHub repository.

The first topic we will be covering in this chapter is distributing points onto a Grid primitive. These steps can also be applied to any other mesh. This skill is crucial to any project in Geometry Nodes.

To get started with this demonstration, we will have to think about what we want to achieve. In this case, we want to distribute points onto a grid. To do this, we will need a total of three nodes: the Grid node primitive, the Distribute Points on Faces node, and the Join Geometry node:

Figure 5.1: The different nodes you’ll need

Let’s start by explaining what these three nodes will do in this demonstration:

  • The Grid node: This will be the base input, the mesh that we will get started within the Geometry Node editor – in this case, a Grid primitive.
  • The Distribute Points on Faces node: This node will, as the title of this node suggests, distribute points on the faces of an inputted mesh. The output of this node will only contain the points.
  • The Join Geometry node: As mentioned, the previous node, Distribute Points on Faces, will output just the points. To add back the base mesh, we will need to use the Join Geometry node to join the original mesh with the Points geometry.

Now, we’ll jump into building the node tree.

We will start by visualizing a Grid primitive. To do this, we will not need the Group Input node because we are using a primitive node as our base mesh input. So, you can go ahead and remove the Group Input node:

  1. Let’s start the process of building a node tree by creating a 5 -meter by 5 -meter grid. We can do this by adding a Grid node primitive and setting Size X and Size Y to 5 meters each. We won’t make use of the Vertices X and Vertices Y values. So, we can put these values to 2. The reason that we won’t put these on 0 or 1 is that you need at least one face to distribute points onto. So, we will need a minimum of four vertices to make up one face.
  2. The next step is to connect the Grid node to the Group Output node to visualize this node primitive.

If you did everything correctly, your window should now look like Figure 5.2:

Figure 5.2: Visualizing the grid

Now, it’s time to distribute the points onto the grid, as the heading of the section describes:

  1. To do this, press Shift + A to open the Add menu. Let’s head over to Point, and then we’ll click Distribute Points on Faces.
  2. When you drop this node onto the node cable, the node will be automatically connected.

If you’ve followed these steps correctly, your node tree should look like Figure 5.3:

Figure 5.3: The current node setup

As you can see on the Viewport, the grid disappears. This is normal because the Distribute Points on Faces node will only output points. If we want to make the grid appear again, we will have to use a Join Geometry node to join the grid and the points together.

This is how you can do that:

  1. Go ahead and press Shift + A.
  2. Then, click on Geometry.
  3. Finally, press Join Geometry to add a Join Geometry node.

Note

If you find it difficult to remember these categories, you can also use the search function to search for all of your desired nodes.

  1. Let’s drop the Join Geometry node into our editor between the Distribute Points on Faces node and the Group Output node. We will see that nothing changes. This is because we’re not joining anything together yet.
  2. Let’s drop the output of the Grid node into the multi-connection input of the Join Geometry node.

If you’ve followed these steps correctly, you will now see the Grid primitive with various points scattered along the surface, as shown in Figure 5.4:

Figure 5.4: The current node setup

Congratulations! You now know how to scatter points onto a grid or plane.

Now that you’ve learned how to distribute points onto a mesh, let’s learn how to instance objects onto these points. For this, we will need the Instance on Points node.

To start instancing objects, we will have to input the base mesh along with our instance object.

We will be continuing with the same project from the last section:

  1. To get started, add an Instance on Points node. We need to drop this node in between the Distribute Points on Faces node and the Join Geometry node. Drop it on the node cable highlighted in Figure 5.5:

Figure 5.5: Node cable where the node should be dropped

  1. We want to have a bare input of just the points since the Instance On Points node only accepts a Points input in the first socket. That is why we have to place the node right after we distribute the points onto the grid.

When you drop this node onto the node cable, Blender will auto-connect the node to the Points input, which is correct.

  1. Now, we will need to choose an object to instance. Let’s add a simple Cube node primitive as our instance object. Let’s give the Cube node a size of 0.3 meters on each axis; we choose 0.3 because it looks the best in this scenario. Let’s plug in the mesh output of the cube into the Instance input on the Instance on Points node.

If you’ve followed the preceding steps correctly, your node tree should look like Figure 5.6:

Figure 5.6: Instancing objects onto a grid

There are two problems we see in Figure 5.6 at first sight:

  • The cubes are intersecting into the grid
  • The cubes are intersecting with other cubes

Luckily, the customizability of Geometry Nodes makes this really easy to fix. We look at these fixes in the sections that follow.

Let’s start with the first problem of the cubes intersecting into the grid. To fix this, you simply have to change the location where the instances (or cubes) are placed. To do this, let’s add a Translate Instances node after the Instance on Points node. We need to place it after the Instance on Points node because otherwise, we will be raising the points, which we don’t want. We will be raising the Z translation to 0.2 meters. This will raise the cube 0.2 meters up the Z axis:

Figure 5.7: Translate Instances node

We will see that the cubes are now raised from the surface. We can now check that issue off the list.

The cubes are intersecting with other cubes

Section titled “The cubes are intersecting with other cubes”

The next problem, the cubes intersecting into each other, is easier to fix than you might think. All we have to do is change the distribution method that the Distribute Points on Faces node uses. This will change the way that the cubes are distributed.

Let’s use the Poisson Disk distribution method, as this allows us to define a minimum distance that the points should follow. Let’s give the node a Distance Min value of 0.4 meters. The node should end up looking like Figure 5.8:

Figure 5.8: Poisson Disk distribution method

When we look back at our Viewport, we can see that the cubes are socially distanced from each other:

Figure 5.9: Distance Min on instanced objects

We can now see that both issues are fixed. Let’s now move on to the next step.

Now that you know how to distribute points onto your mesh and place instances on those points, it’s time to learn how to randomize these instances. Randomization is important because the human eye is very good at noticing patterns in geometry. To fix this, we have to randomize factors in our projects. For this, we will be using the Random Value node shown in the following figure:

Figure 5.10: Random Value node

This node will output various random values for other flows of the node tree, thanks to the multivalued field node connection.

The Random Value node can output various data types. When clicking on the selection box at the top of the node, you can see a list of all the different data types this node can generate:

Figure 5.11: Different data types

For this part of the tutorial, we will be randomizing the rotation of the cubes:

  1. Let’s choose the Vector data type from the list since we want to have a different random value for each of the X, Y, and Z axes.
  2. To link this Random Value node to the project from Figure 5.9, we will need to add a Rotate Instances node. This node needs to be added after the Translate Instances node; otherwise, the cubes will be translated in a different direction following its rotation value.
  3. Let’s plug the Random Value node into the Rotation input of the Rotate Instances node.

If you’ve followed these steps correctly, your node tree should look like Figure 5.12. As you can see, each cube is now randomly rotated:

Figure 5.12: Your current node tree

As you might notice in Figure 5.12, the Rotate Instances node does not make use of the degrees system; instead, it makes use of the radians system.

To explain radians quickly, 1 radian equates to about 57°. Radians are useful in this use case because radians are dimensionless, so they can just be treated as numbers. They define a very natural description of an angle.

For a full circle, we will need 6.28 radians, because 2 times pi equals 6.28. This equates to 360°.

Let’s enter 6.280 as our Max value on each axis in the Random Value node. This will allow the cubes to rotate in any direction:

Figure 5.13: Max values of randomization to get a full rotation

We have now learned how to distribute points onto a mesh, how to instance objects onto these points, and how to give these objects a randomization using the Random Value node.

Next, we’ll experiment a bit with Group Inputs since they can enhance the user experience with the help of your node tree.

Group Inputs (see Figure 5.14) can be seen as easy-access variables in our modifier stack:

Figure 5.14: Group Inputs

They make it easier for the end user to change commonly used variables right from the modifier stack.

We can add various Group Input values by adding in a Group Input node (this gets automatically added when you create a node tree) and sliding an input node connection into the dark gray node connection on the Group Input node, as seen in Figure 5.15. Sliding an input node into this dark gray node connection will automatically add a Group Input to your modifier. You will mostly be using Group Inputs when you have values that you want to have easy access to – for example, the density of grass:

Figure 5.15: Group Inputs

Group Inputs also have advanced settings for when you want to have finer control over the different data types, the names of your values, and the min-max limits of your values. To access the advanced settings of Group Inputs, head to the right-hand side of the Geometry Node editor, where the add-ons reside. Instead of clicking on an add-on, let’s click on the Group tab. We will see the various inputs that we have put into our Group Input node:

Figure 5.16: Group Inputs advanced settings

We can edit various things about these values, such as the type of the value, the name of the value, the default value, and a minimum and maximum value. This addition to the Geometry Nodes system will make it easier for you or an end user to easily modify key variables of your node tree right from the Modifier tab.

In this exercise, we will be creating a grassy field using the nodes we learned in this chapter. We will start by distributing points onto a terrain mesh, then we will make and instance blades of grass, and then we will give these blades of grass some randomization.

In this section, we will think about what steps we need to complete to achieve the goal of creating a grassy field. We will need to model a basic terrain mesh and distribute some points on it; we will also need to model a single blade of grass to use as an instance object. After that, we will randomize the rotation of each blade of grass. To finalize this project, we will also show you how to link materials to your procedural mesh.

In this section, we will talk about the nodes (shown in Figure 5.17) that we will need to create a grassy field:

Figure 5.17: The nodes you’ll need for this exercise

It’s a good practice to have a clear idea about the nodes required for an exercise. Here are the nodes we will need for creating a grassy field:

  • A Group Input node to input the terrain mesh
  • A Distribute Points on Faces node to distribute points on the terrain mesh
  • An Instance on Points node to place grass on the terrain mesh
  • An Object Info node to load in an instance object
  • A Random Value node to add randomization to each blade of grass
  • A Join Geometry node to join the points and base terrain back together after distributing the points
  • And lastly, a Rotate Instances node to rotate each blade of grass

Next, we will be showing you how to model the various assets we will need for this project.

While we can model the terrain procedurally in the Geometry Node editor, this will be covered in the more advanced chapters of the book. For now, we will explain this exercise by modeling the various assets in Edit Mode.

Let’s start by creating a new project in Blender and clearing the default scene because we don’t need the included Camera, Cube, or Light nodes.

Add a Plane node and press Tab to enter Edit Mode.

Let’s subdivide this plane, and start pulling up parts of the plane with proportional editing. Once you’re happy with your terrain, you can continue to the next step, where we’ll model a single blade of grass.

In Object Mode, add a Cylinder node with a vertex count of 3:

Figure 5.18: Cylinder with vertex count of 3

The reason why we only want three vertices is that we will instance these objects a lot, so to save your computer’s performance, you should have as few vertices as possible.

Let’s scale down the top face to make it look like a blade of grass. We can also add horizontal loop cuts to the vertical lines of the cylinder to give it a bit of randomization.

Once you’re happy with the blade of grass, let’s continue to the next step.

Let’s head over to the Geometry Nodes workspace inside of your current project. The Geometry Nodes workspace button can be found at the top of your screen, as shown in Figure 5.19:

Figure 5.19: The Geometry Nodes workspace button

In the workspace, click the terrain mesh and then click the New button to add a new node tree to the terrain mesh.

Let’s start building our node tree by adding a Distribute Points on Faces node and dropping it between the Group Input and Group Output nodes. You can change the Density and Seed values until you are happy with the result.

The Group Input node will make sure that the terrain mesh from Edit Mode will be used in the Geometry Node editor:

Figure 5.20: Your current node tree

In your project, you will see that the terrain mesh itself is not visible anymore, so let’s make it visible again by using a Join Geometry node as we’ve done previously in this chapter. We will join the Group Input node connection together with the distributed points.

If you’ve followed the steps correctly, your node tree should look like this:

Figure 5.21: Your current node tree

Now, we’ll instance a blade of grass on each of these points as we’ve done before in this chapter. The difference now is that we will use an existing object as an instance object – in this case, the blade of grass.

We can do this by adding an Object Info node. You can find this node by using the Search function in the Add menu:

Figure 5.22: The Object Info node

This node will place any existing object as a node in the Geometry Node editor. We have various options here: the first input is an object selection box to choose your desired object, and the second checkbox defines whether the object should be imported as an instance or not.

At the output side of this node, we see four output node connections. Location, Rotation, and Scale will define each of these attributes as a vector output. The last output, Geometry, will define the geometry of the chosen object. Follow the next steps:

  1. Select your blade of grass in the object selection box and check the As Instance Boolean value so that it will be imported as an instance.
  2. Drop in an Instance on Points node after the Distribute Points on Faces node.
  3. Now, connect the Geometry output of the Object Info node to the Instance input of the Instance on Points node:

Figure 5.23: Your current node tree

We can see that the grass appears now, but it is way too large:

Figure 5.24: Grass appears too large

  1. We can set the scale of the grass by turning down the Scale value of the Instance on Points node. Pick a scale that looks like how grass looks in real life.

Note

You might face an issue where the blades of grass are situated in the middle of the terrain rather than on the terrain; you can fix this by changing the origin point of the blade of grass. After that, the blades of grass will be nicely situated on the terrain.

Just as with the previous demonstration we performed, in the next step, we will be giving randomization to the grass.

Let’s now randomize the rotation of the blades of grass. For that, we will be using a Random Value node as we used before in this chapter.

Let’s set this node to Vector and put X max and Y max on 0.3 and put Z max on 6.28. This will allow the grass to rotate more on the Z axis than it will on the X and Y axes.

Let’s plug this Vector output value into the Rotation input of the Instance on Points node.

This is also a good moment to experiment with different shapes of grass or to modify some values to get a result that you are satisfied with:

Figure 5.25: Your current node tree

If you’ve followed the steps correctly, your node tree should look like Figure 5.25.

Let’s add a material to your grass now. Start by heading over to the Shading workspace at the top of your screen.

Add a new material to the terrain object. Give this material a dark green color to appear like grass. Let’s name the material Grass:

Figure 5.26: The Shading workspace

As you can see from Figure 5.26, the grass is not affected by the material; this is because the material has to be linked inside the Geometry Node editor. Let’s head back to the Geometry Node editor to fix this.

Let’s add a Set Material node to add the material to the blades of grass:

Figure 5.27: The Set Material node

Let’s drop in this node at the end of your node tree to append all the mesh. Let’s also select the material you created previously.

Note

You might not be able to see color in the Geometry Nodes Viewport. To fix that, switch your Viewport mode to Material Preview; this can be done by pressing Z in the Viewport.

If you’ve executed the steps successfully, this part of your node tree should look like Figure 5.28:

Figure 5.28: Your current node tree

Congratulations! You’ve now finished this node tree. In the next section, we’ll learn how to use Group Inputs to make our node tree easier to use.

Using Group Inputs to add sliders to the modifier

Section titled “Using Group Inputs to add sliders to the modifier”

To finish off this exercise, let’s make it easier for end users of this node tree to control different variables.

In the Experimenting with Group Inputs section, we explained how to use this feature in Blender. Now, it’s time to put these skills to the test:

  1. We will add Group Input variables to these values:
    • Density
      • Scale
      • Seed
  2. Let’s drag the gray node connection from Group Input to the values that you want to be included in the modifier. That’s how you add Group Inputs!

Figure 5.29: Final render of the grassy field

Finally, you can see in Figure 5.29 what the grass looks like.

In this chapter, we discussed how to distribute points on a mesh. Following that, we talked about how to instance objects onto these distributed points, and to complete the chapter, we showed you how to randomize these objects using the Random Value node.

In the next chapter, we will show you how to work with the Spreadsheet.