Population Masking Techniques

From Terragen Documentation from Planetside Software
Revision as of 19:02, 11 February 2021 by Redmaw (talk | contribs) (Added Further Reading section with links to other Populator wiki pages.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Terragen is often praised for the quality of its atmosphere, clouds and skies, but equally important is Terragen’s implementation of populations, that is, its ability for creating many instances of 3D geometry in a scene. The fact that Terragen can handle billions of instances is incredible.

Setting up populations[edit]

Let’s get familiar with Terragen’s population controls in an empty scene first. From the Objects Node List click on the “Add Object” button and select “Population” then “Tgo object”, and choose a 3D object to instance.

Add population to project.

Notice two new nodes show up in the Object Node List. The first new node represents the population and the second node represents the object being populated or instanced. With the population node selected click on the “Populate Now” button at the bottom of the population's Distribution tab.

Two new nodes added to project.

A bunch of bounding boxes appear to show each instance of the object. Reduce the number of instances so you can better see what’s going on. Change the “Object Spacing in a,b” values to “100”, and recalculate the population by clicking the “Populate Now” button again.

The bounding boxes represent each instanced 3D geometry.

Now we see fewer instances, randomly scattered around the terrain as defined by the “Area length a,b” settings. Changing the value in one or both of the area length fields will resize the area’s width or length.

Use the Area length a,b setting to control the number of instanced objects in the population.

The “Spacing variation” value sets the maximum allowable distance that an instanced item can be offset from the object spacing values. Setting this value to “0” will cause the instanced items to be positioned as defined by the object spacing values, and they will all appear to be neatly lined up in rows and columns.

When the Spacing variation is set to zero, the instanced objects are neatly positioned in a grid-like pattern.

Now the instanced objects are lined up, but still have random rotations. Align them by setting the Maximum Y Rotation value to 0 on the Rotation tab and recalculating the population.

The rotation of each instance object is set on the Rotation tab.

Now all our instances are aligned in rows and columns. If you used a tree as your object you should now see an orchard instead of a forest.

Masking with the Camera's Field of View[edit]

Terragen also has the ability to create populations that are only within the camera’s field of view. Enable the “Clip to camera” checkbox on the Distribution tab and recalculate the population.

By enabling the Clip to camera checkbox the instanced objects will only appear in the camera's field of view.

Notice that all the trees behind the camera have disappeared. By placing instanced items only where they will be visible in a shot reduces the number of instances, and allows you to have more instances in the field of view. Optimizing your populations in this way leads to faster scene loading, calculating and rendering times.

Masking with Painted Shaders[edit]

“Masking” is the term used to limit the instanced items to certain areas. Instead of masking the population by the camera’s field of view, let’s mask it by a paint shader. First allow the 3D Preview to completely refresh, then click on the “Pause” button at the top of the 3D Preview pane. From the main menu click on the “Paintbrush” button to start or stop a Painted Shader paint session, then select “Start Painting Shader” and “Create and paint new shader”.

To start painting a mask, click on the Paintbrush button at the top of the 3D Preview.

In the dialog window append a description to the “Name” field, so it will be easy to identify our mask later on. Change the brush type to “Use view-relative brush” under the Brush tab, which will change the brush size based on our perspective view of the scene.

In the Painted shader the brush size can be set to an absolute size in metres or a view-relative size.

Left click and drag to start painting the mask on the terrain. When you’re done click on the Paintbrush button and select “Stop painting”.

To end the painting session, click the Paintbrush button and select Stop painting.

To apply the mask you just painted, click on the green “Plus” button next to the “Use density shader” and select the “Assign shader” option from the drop down menu and select the name of the mask you just painted. You can also do this in the Node Network pane by dragging a connecting line from the painted shader node’s output to the population’s density input. Either method will enable the “Use density shader” checkbox.

Assign the Painted shader as a mask via the Uses density shader setting.

Uncheck the “Clip to camera” checkbox and recalculate the population.

Populating the terrain using the Painted shader as a mask.

The instances are now generated only where the mask was painted. To reverse this, check the “Invert density shader” checkbox and recalculate the population.

Invert where the 3D objects are instanced by checking the Invert density shader checkbox.

Masking with Simple Shape Shaders[edit]

If you want to create a common shape for a mask, like a square, rectangle or circle, use Terragen’s built-in “Simple shape shader - Colour” node.

Bring up the “Quick Node Palette” in the Node Network pane pane by pressing the “N” key or the “Tab” key, then start typing the word “Simple”, and choose the “Simple shape shader - Colour” node.

Using the Quick Node Palette to add nodes to the project.

You can choose the shape used by the Simple Shape Shader and reposition it as desired.

Options for the Simple shape shader.

Combining Masking Shaders[edit]

We can combine these two shaders together with an “Add colour” node from the Quick Node Palette.

Combine two shaders with the Add colour node.

Drag the output of the Painted shader into the Main Input of the Add colour node and the output of the Simple shape shader into the Input 2. Then double click on the Add colour node to bring up its interface. Click on its “Open shader preview” button and zoom out as necessary to view the results of combining the two nodes into one.

Connecting the two shaders via the Add colour node.

When the two shaders overlap the resulting value is greater than 1.0 so these areas appear brighter in the preview. Let’s add a “Colour adjustment” shader to clamp the highest value at 1.0.

Clamping the maximum colour output via the Colour adjustment shader.

Now drag the output of the Color adjustment shader to the population’s Density shader input and recalculate the population to see the results.

Assign the Colour adjustment shader as the population's Density shader.

Masking with Power Fractal Shaders[edit]

You can use Terragen’s “Power fractal” node to create organic shapes as masks. Add a Power fractal node the same way as the other nodes and open its preview window.

We want to create a high contrast noise pattern that doesn’t have a lot of detail. Under the Colour tab set the “Colour contrast” to “1” and the “Colour roughness” to “0”. Then use the “Colour adjust” slider to get a good balance between light areas and dark.

Adjust the contrast of the fractal noise pattern via the Power fractal shader's Colour tab.

Experiment with the different types of noise patterns under the “Tweak Noise” tab.

Terragen has a number of different types of fractal noise patterns available.

Under the Warping tab, use the “Lead-In warp effect” and “Lead-in warp amount” to create swirling wave-like patterns.

Give the fractal noise pattern a swirling wave-like pattern via the Warping tab settings.

Now, you can adjust the size of the fractal pattern using the “Feature scale” and “Lead-In scale” settings on the Scale Tab. If you’re unsure of the sizes to choose, use the built in measuring tool to sample the distances.

Adjust the size of the fractal noise pattern via the Scale tab settings.

In the Node Network pane, copy and paste an instance of the Color adjustment node previously used, and connect the Power fractal node to it. Adjust the “White point” as necessary to eliminate most of the grey areas, and then connect the node to the population’s Density input, and recalculate the population.

Use a Colour adjustment node to adjust the brightness of the fractal noise pattern being used as a mask.
The resulting population using the fractal noise pattern as a mask.

Masking with Distribution Shaders[edit]

The final type of mask we’ll explore is the Distribution shader, which allows us to limit populations by altitude and slopes. To see this effect better, disable the Simple shape shader that’s applied to the default scene’s Fractal terrain node.

The terrain should no longer be flat beneath our population. Increase the area of our population and recalculate it so that the instances sit on the new terrain. Hovering the mouse pointer over the terrain updates the XYZ coordinates and slope values displayed beneath the 3D Preview. We can use these values to set the limits of our constraints in the Distribution shader.

Disabling the Simple shape shader in the default scene removes the area of flat terrain.

Click on the green Plus button next to the population's “Use density shader” setting and select “Create new Shader”, then “Colour Shader”, then “Distribution shader v4”.

Adding a Distribution shader as the mask for the population.

Limit the tree population to the crest of the mountain ridgeline. The Y axis shows that it’s about 200 meters high, so under the Altitude constraints tab, enable the “Limit minimum altitude” checkbox and set the “Minimum altitude” value to “200” and the “Min alt fuzzy zone” value to “0”. The fuzzy zones allow for soft transitions to take place, but for now we want to see a definite cut-off point to the population. Time to recalculate the population.

Setting the Distribution shader's altitude constraints.

Now reduce the “Minimum altitude” to “50” meters and enable the “Maximum altitude”, setting it to about “200” meters, with a fuzzy zone of “0” as well, then recalculate the population.

Final Distribution shader's altitude contraints.

Finally, we’ll limit the maximum slope to about 15 degrees, so that the trees only grow on the flat parts of the hillside and not the steeper slopes. Final Distribution shader's slope constraints.

As you can see, using these basic masking concepts allow you to completely control where your instances are placed, and like many other tools in Terragen, these masking techniques can be applied to other shaders as well, not just to populations.

Further Reading[edit]

Working with Populations
This page introduces you to populations and how to work with them.

Population Instance Editing
This guide describes how you can edit individual instances in a population to precisely control your scene.

Population Instance Caching
This page tells you how to make use of population instance caching to speed up population loading.

Tutorial: Population Colour Tinting Techniques
This tutorial shows you how to use the tinting tools to change the colours of instances in lots of interesting ways.

A shader is a program or set of instructions used in 3D computer graphics to determine the final surface properties of an object or image. This can include arbitrarily complex descriptions of light absorption and diffusion, texture mapping, reflection and refraction, shadowing, surface displacement and post-processing effects. In Terragen 2 shaders are used to construct and modify almost every element of a scene.

A single object or device in the node network which generates or modifies data and may accept input data or create output data or both, depending on its function. Nodes usually have their own settings which control the data they create or how they modify data passing through them. Nodes are connected together in a network to perform work in a network-based user interface. In Terragen 2 nodes are connected together to describe a scene.

A sample refers to a value or set of values at a point in time and/or space. The defining point of a sample is that it is a chosen value out of a continuous signal. In Terragen 2 it is usually a mathematical (procedural) function that is being sampled.