How to use Chaos Scatter with Corona for Cinema 4D - Advanced Features
This is "Advanced Features of Chaos Scatter". It is a part of a larger collection of articles:
- Getting Started
- Advanced Features (you are here)
- Using Chaos Scatter with Other Features of Corona
- Performance and Troubleshooting
- 1D, 2D, and 3D Scattering
- Camera Clipping
- Using textures to control scatter transformations
- Preserve scale and rotation
- Edge Trimming
1D, 2D, and 3D Scattering
Under the "Config" tab you can choose between 3 modes:
- 1D - On splines
- 2D - On surfaces
- 3D - In bounding box
1D scattering is intended for distributing objects along splines. An example of this would be planting trees in straight or curvy lines, or placing lamps along a street.
Note: open or closed splines can be used for this, and in this mode, the instances will always be distributed along the selected splines:
2D scattering is the most common mode, where the distribute-on object's surface is considered, no matter if it's horizontal, vertical, or if it's a complex 3D object.
Note: a closed spline can be used in this mode too, and in such case, the instances will be distributed on the area enclosed by the spline's border.
3D scattering means that the instances will be scattered inside the volume of the distribute-on object's bounding box:
Note: in the case that a spherical object is selected as the distribute-on object, the instances will be scattered inside a cube (since the bounding box of the sphere is considered, and it is cube-shaped). This type of scattering is useful when a box-shaped volume needs to be populated with objects, for example:
- dust particles in the air inside a room
- fish in an aquarium
- books on a shelf
- wood next to a fireplace.
Camera clipping is a feature that limits the scattering to the camera view. Instances that are not visible will be clipped away. It is an optimization, it may improve scene parsing speed and lower memory usage, however, it can cause missing reflections or shadows (because some objects farther away from the camera will disappear). To compensate for this you can use the "Extend view" parameter. It supports various camera types (native, Corona, V-Ray).
Note: As explained above, camera clipping is purely an optimization feature! It can speed up scene parsing and lower memory usage by hiding some of the rendered objects which would be otherwise visible and therefore would need to be parsed and allocated in the memory. It must NEVER be used to limit the scattered instances to a specific area. Other features should be used for this, such as spline include/exclude and slope limitation!
Camera Clipping Parameters:
Enable: Checking this will enable the Camera Clipping feature.
- Active render camera: This mode clips the instances based on the camera view used for rendering. In this case, the clipping is not visible in the viewport unless changing clipping parameters (or running IR). This is because otherwise, the clipping would be too intrusive during regular scene work.
- Specific Scene Camera node: This mode uses a specified camera for the clipping. In this case, the clipping is always visible.
- Extended view: Specifies a uniform extension to the camera view in all directions (as distance), adding an extra zone beyond the camera view (behind the camera too) where the instances will not be clipped. This is useful for ensuring correct shadows or reflections from instances that would otherwise be clipped. The distance is in scene units.
Near and Far overrides:
- Near threshold: Specifies near threshold distance from the camera. Instances closer than that will be clipped away. The distance is in scene units.
- Far threshold: Specifies far threshold distance from the camera. Instances further than that will be clipped away. The distance is in scene units.
Known Limitations of Camera Clipping:
- Visible flickering in animations:
This issue occurs when using Camera Clipping on models which have at least one Corona Multi Shader in their material setup. The reason behind this is that when using Camera Clipping, the number of scattered models can vary between animation frames, and this affects the way different colors/textures are distributed through the Multi Shader. Note that the models are not actually changing their positions, but their colors are affected instead.
Solution: Either disable Camera Clipping or remove any Corona Multi Shaders from the materials of the scattered models. We are planning to fix this issue in the upcoming versions of Scatter.
Using textures to control scatter transformations
Another new feature of Chaos Scatter is the ability to drive the scattered objects' translation, rotation, and scale using textures or colors (or in fact, anything plugged into the respective "Texture" slot).
We will be using the below simple scene showing a forest scattered on a simple plane.
In this image, no translation, rotation, or scale adjustments are used, so all trees are positioned exactly at the plane surface, they are not leaning in any direction, and their scale is uniform.
We will be using a texture with pure red, pure green, and pure blue colors to drive the three transformations:
We need to set some translation from - to range. In this case, we will use a range from 0 to -120, 0 to 70, and 0 to 120 meters respectively. We also need to plug the RGB texture into the "Texture" slot under the Translation section:
Here is the result of our adjustments:
As we can see, the trees which originally grew on the red area were moved in one direction (X-axis), the ones on the green area were moved in another direction (Y-axis) and the trees from the blue area were moved up (Z-axis).
We can adjust the rotation in a similar way. Let's discard the previous translation changes, remove the translation texture, plug the same RGB gradient into the "Texture" slot under the Rotation section, and set the rotation XYZ ranges to 0 - 75, 0 - 60, and 0 - 80 degrees respectively:
This is the result:
The trees from the red area are now leaning 75 degrees along the X-axis, the trees from the green area - 60 degrees along the Y-axis, and the trees from the blue area 80 degrees along the Z-axis.
Lastly, we can use the RGB gradient to control the trees' scaling. Let's discard the previous rotation changes, remove the rotation texture, plug the same RGB texture into the "Texture" slot under the Scale section, and set the scale XYZ ranges to 100 - 250, 100 - 200, and 100 -200 percent respectively:
As a result, the trees from the red area are now 250% stretched in the X-axis, the trees from the green area - 200% stretched in the Y-axis, and the trees from the blue area - 200% stretched in the Z-axis.
Note: when using transformation textures, the red, green, and blue values correspond to transformations in different axes (X, Y, Z). This means that colorful textures will allow the instances to be transformed in unproportional manner (it is possible that they will be moved, rotated, or stretched in one direction more than in another direction). To make the transformations proportional, use grayscale transformation textures:
In the above example, a black-to-white gradient is used to drive the size of the trees. This way the trees will be scaled proportionally in all directions, because the R, G, and B color values are the same at any given point (for example R 50, G 50, B 50, and so on).
4. Transformation modes
So far, we only used the default "Map fixed" transformation mode. In this mode, the black and white areas of the transformation map directly correspond to the values specified in the "From" and "To" fields. This way, black areas of the map will represent the lowest allowed transformation, and white areas will represent the highest allowed transformation.
For example: black areas in the scale texture will represent the smallest allowed instances, and white areas in the scale texture will represent the biggest allowed instances.
If we switch to the "Random amount" mode, the black and white areas of the transformation map will be interpreted differently. "From" and "To" values will specify the maximum allowed randomization, black areas of the texture will represent the areas where there is no randomization whatsoever, and white areas in the scale texture will represent the areas where maximum randomization is allowed.
"Random amount" Scaling Mode - Checker texture example:
Here is an example of the same mode ("Random amount") based on a black and white Checker texture. You can clearly see that no randomization occurs on the black squares, and that full randomization occurs on the white squares:
"Map fixed" Scaling Mode - Checker texture example:
For comparison, here is the same setup as in point 10, only with "Map fixed" mode enabled, where you can see how black and white areas simply represent different scaling:
Tip: when creating all kinds of scenes with Chaos Scatter, adjusting its settings, and creating textures, Corona's Interactive Rendering is a great ally. It lets you preview your changes and decide which settings to use close to real-time.
Preserve scale and rotation
You may sometimes have a model in your scene which is not rotated correctly. This is especially common in the case of models imported from a different 3D application:
In this case, a tree model is laying on its side instead of growing upwards. This is incorrect, unless we need to render a fallen tree.
The first idea to fix this would be to use the rotation tool and rotate the object by 90 degrees:
However, if we do it, and use this rotated tree model in Chaos Scatter, we will end up with the following result:
This is because, by default, Chaos Scatter considers the local coordinate system of the model object. In this case, the tree model was originally laying on its side with its local Z axis pointing upwards. We rotated the tree, however, this did not affect the local coordinate system - it stayed the same.
When this is checked, the current rotation of the scattered tree models will be considered, so they will behave as we originally intended:
After enabling the "Preserve model rotation" option, the scattered trees are growing straight, just like the model that we see in the viewport.
The "Preserve model scale" option under Transformations > Scale works in a similar manner. If the model selected for scattering was rescaled in Cinema 4D:
- When "Preserve model scale" is disabled, the scattered objects' scale will be the same as the original model's scale when it was imported into the scene.
- When "Preserve model scale" is enabled, the scattered objects will look the same as the model after it was rescaled.
Note #1: In situations where the scattered models appear to be rotated or scaled in an unexpected way, it is a good practice to tick and untick the "Preserve model rotation" and "Preserve model scale" checkboxes and observe the behavior of the results.
Note #2: Remember that the pivot of the original object that is scattered decides the point of rotation and scaling of the instances. Moving and rotating the pivot of the original object will change the way the scattered instances are rotated and placed on the distribute-on object.
Using the Preserve Scale and Rotation options with animated instances
If the geometry of your original model is animated, for example, the vertices or faces of the mesh are changing their positions - everything will work as expected and the scattered instances will be animated too.
If the rotation and/or scale of your original model is animated (keyframes are created for the model's rotation or scale transformations), then by default this will be ignored and the scattered instances will appear static, without any kind of movement. To fix this, you need to enable the "Preserve scale" and/or "Preserve rotation" checkboxes.
Starting with Scatter 2 (bundled with Corona 9), you can trim scattered instances consisting of multiple mesh elements so that they stay within the boundaries of the distribute-on objects or the include/exclude splines. In addition to making the scattering look more refined and natural, this feature also provides a performance increase - thanks to removing some of the instances, you save RAM and make parsing time shorter.
To learn more, see also: Scatter Edge Trimming shader
Using Edge Trimming
Without using Edge Trimming
How to use it?
Edge Trimming is provided through the new Scatter Edge Trimming shader, which you can find in the material editor under the New shader -> Corona category
Note: If you also have V-Ray installed, you can find it under the New shader -> plugins category.
You need to plug the Scatter Edge Trimming shader into the opacity slot of the material of the model that you are scattering (in case of multiple models with different materials - all opacity slots of all materials used):
If your model is already using an opacity texture or shader, you can pass this existing texture map through the Scatter Edge Trimming shader using its "Default shader" slot:
Once the Scatter Edge Trimming shader is included in the material setup, we can see its effect in the rendered image (this is not visible in the viewport):
The image shows how the Chaos Scatter looks like in the viewport (the Scatter Edge Trimming shader's result is not visible in the viewport).
The image shows the result of a scattered object without using the Scatter Edge Trimming shader for their materials.
The image shows the result of using the Scatter Edge Trimming shader for the scattered object's materials.
How does it work?
If a pivot of any integral part of the instance (any sub-mesh element of the instanced model) falls outside of the area specified by the scatter, such part is not rendered. This is a simplification, but you can imagine the pivot as a point on the distribute-on object from which an element is growing.
When the Scatter Edge Trimming shader is not used:
Without the Scatter Edge Trimming shader, the whole clumps will be scattered, causing some of the flowers (sub-object elements) to grow outside of the distribute-on object.
When the Scatter Edge Trimming shader is used:
Each model is scattered the same way as when that Scatter Edge Trimming shader is not used (its pivot is placed within the boundaries of the distribute-on object), but when it's in use, the sub-mesh elements (individual flowers) are only growing inside this boundary of the distribute-on surface.
The area to consider for trimming can be specified using:
- The distribute-on object itself.
- Include splines.
- Exclude splines.
There is no need to enable any special options in the Chaos Scatter object itself.
The typical use cases of Edge Trimming include:
- Grass lawns - in case of using large grass clumps, no individual grass blades will be growing outside of the defined area.
- Carpets - in case of using large clumps of strands, no individual strands will be placed outside of the carpet area.
- Pebbles, rocks, bark chippings, or any other objects you need to distribute within a specific boundary and ensure no instances stick outside of that boundary (determined based on the mesh element pivot precision).
Known Limitations of Edge Trimming:
- Generally, the less mesh elements a model object has, the faster the Scatter Edge Trimming feature works. It may get slower when using extreme numbers of mesh elements in a single model (think 10,000 elements or more), but this should not be an issue in usual scattering scenarios (scattering grass, trees, rocks, etc.).
Note: Sometimes, it may also be worth to experiment and finding out whether to use scattering, Corona Pattern, or displacement.
See also: Displacement, Scatter, and Pattern usage differences.
- If the area where trimming is expected to occur (e.g., a narrow path defined by an exclude spline) is significantly smaller than a single to-be-trimmed model itself (e.g., a large grass patch), then the trimming may actually not happen because of optimizations used by the trimming feature. The solution is to make the model smaller (e.g., manually scale the grass patch or use scaling options in the Chaos Scatter).
- Currently, you need to manually (or using a script) connect the Scatter Edge Trimming shader to the opacity slots of each of the materials you are using for your scattered instances. This can be challenging, especially in the case of scattering models with many different materials. We are planning to improve this workflow.
To learn more about the Chaos Scatter, see also: Chaos Scatter