On this page |
The Shallow Water Solver supports the creation of various fields, but you can also use fields as inputs to drive the simulation.
Note
The Shallow Water Solver is a 2D solver and fields are evaluated using only two coordinates. By default, the solver uses the XZ plane, and the water’s height is used for the Y axis. This also applies to incoming fields.
Velocity, acceleration, vorticity ¶
Note
This workflow is based on an already existing Shallow Water Solver network. If you don’t know how to set up a simulation, please visit the Shallow Water Solver intro page for a detailed description.
In the solver’s Output tab you can find checkboxes for three fields: velocity
, acceleration
, and vorticity
. The first two fields are vector fields and they consist of a XYZ components. As mentioned in the note, the normal component (Y by default) is not relevant. vorticity
is a scalar and there’s only one value. To get an impression of the water’s different fields, you can visualize them.
-
Add a Grid to the simulation network.
-
Check, if Orientation is the same as the HeightField node’s parameter.
-
The Grid and the Heightfield nodes' Size parameters should match. If the Heightfield’s size is
20x20
, for example, use these values for the Grid. -
Increase the Grid node’s Rows and Columns to get enough sample points, e.g.
50
for both parameters. -
Add a Volume Trail node.
-
Connect the Grid to its first input and the Shallow Water Solver to the second input.
-
Under Velocity Volumes you can choose, which field you want to visualize. The drop-down menu on the parameter input’s right lists all available fields. Choose
vel.*
. -
If you don’t like the default colors, go to Ramp and choose Custom Ramp. Now, adjust the Color Mapping gradient.
-
For a better view of the trails, add a downstream Transform node, then shift the visualization along the positive Y axis until you can see the trails.
Go to the solver and turn on Output Acceleration (accel). You can now find the new field in the Velocity Volumes drop-down menu.
-
With
accel.*
, the trails are shorter and there are rapid changes. You probably have to change the Volume Trail’s Maximum value to see any differences. Theaccel
field stores the Lagrangian horizontal acceleration experienced by water at each point.
If you also turn on Output Vorticity (vorticity), you can inspect the exported vorticity
field. This scalar volume stores the local rotational motion at each point, with larger absolute values indicating faster spinning. Positive (negative) vorticity values signal that rotation is in the counter-clockwise (clockwise) direction when viewed from above. Since this is a scalar field, it’s better to use the Volume Slice SOP to visualize it.
-
Add a Volume Slice node.
-
Connect its input to output of the Shallow Water Solver.
-
Set Source Group to
@name=vorticity
. -
Change Visualization Ramp to Custom Ramp.
-
Set a symmetric Visualization Range (for example,
-1
to1
). -
Click the button on the right of Color Mapping and select Two-Tone.
The above steps will visualize the vorticity with a harsh cutoff at the value of 0
. This helps differentiate areas of positive and negative local spin.
Force ¶
Under the solver’s Bindings you can see an empty Force Mask Layer. Force masks can be created like any other mask, e.g. through a HeightField Paint or a HeightField Mask by Object node.
Note
Please visit the Shallow Water Solver page for detailed information on how to create masks.
One idea is to create a force field from an animated object’s velocity field. This approach simulates a collision effect with displaced water.
Heightfield setup ¶
The heightfield is the solver’s collision geometry. The quality of the simulation strongly depends on the scene’s scale.
-
On obj level, create Geometry node and dive into it.
-
Inside the Geoemtry node, add a HeightField.
-
Set Size to
5x5
. -
Set Grid Spacing to
0.01
-
Add a HeightField File node and connect it to the Heightfield operator’s output.
-
Under File, add the path to a displacement, for example beach pebbles or a rocky ground.
-
Under Layer Name, enter
height
. -
Adjust Height Scale until you get the proper vertical displacement.
Paint the mask ¶
The following mask tells the solver where to source water.
-
Add a HeightField Paint node and connect it with the previous Heightfield File operator’s output.
-
Move the mouse over the viewport and press Enter to enter the drawing mode.
-
Use to scale the brush size and paint on the heightfield. Red spots indicate the source areas.
-
Add a downstream HeightField Copy Layer and set Destination to
source
. -
Reset the old
mask
with a downstream HeightField Mask Clear.
Sphere collision setup ¶
A fast moving sphere can lead to instabilities or other simulation glitches, e.g. water inside the sphere. For better control over the sphere’s speed, you can use expressions instead of animations keys.
-
Add a Sphere node.
-
Under Center.X, enter
sin($FF*3)*0.25
to create an oscillation with an amplitude of0.25
in positive and negative X direction. -
Under Center.Z, enter
$FF*0.015-1.5
to create a slow linear motion along the Z axis starting at-1.5
. -
For Rows and Columns enter
50
to get enough velocity sample points.
The sphere’s motion is now turned into a velocity field.
-
Put down a Time Shift node and clear its Frame expression by ⌃ Ctrl + ⇧ Shift + clicking it. Connect its input to the animated Sphere node. This will serve our rest geometry for deforming scattered points.
-
Add a Pyro Source node and connect the animated Sphere node to its first input. Wire the Time Shift node to its second input.
-
Set Mode to Volume Scatter.
-
Add Point Velocity node and connect it with the Pyro Source. This node caclulates the velocities.
-
To create a field from the velocity, add a Volume Rasterize Attributes node and connect it with the previous node.
-
Under Attributes, add
v
- the velocity. -
Set Voxel Size to
0.008
-
Add a Name node and connect it with the Volume Rasterize Attributes node’s output.
-
Go to Group and enter
@name=v
to isolate the velocities. -
Set the group’s Name to
vel
to make the velocity field available to the solver.
Heightfield and velocity fields are now merged and will serve as an input for the animated force mask.
-
Add a Merge node and connect Name and HeightField Mask Clear nodes to its input.
-
Add a downstream HeightField Mask by Object. Connect the Merge node to the first input, and the Sphere to the second input.
-
Add another downstream HeightField Copy Layer and set Destination to
force
. -
Reset the old
mask
with a downstream HeightField Mask Clear.
Solver setup ¶
The solver brings everything together and creates the water. The sphere’s velocity is also converted into to a force field that will be used by the solver to push water.
-
Add a Shallow Water Solver and connect it with the HeightField Mask Clear node’s output.
-
Under Setup go to Velocity Diffusion and enter
0.0005
to blur the velocity field and dampen the waves. -
Set Source Scale to
0.03
to reduce the amount of sourced water. -
Turn on Force Frequency and choose Once per Frame to tell the solver that there’s an animated
force
mask. -
Go to the Bindings tab. Under Force Mask Layer, enter
force
. -
You can also visualize the water. Under Output go to Visualization and choose Color by Water Layer.
-
Play the simulation; if you encounter instabilities, go to the Simulation tab and increase Substeps.
The video shows the sphere, slightly displacing the surrounding water.