Skip to content

Swirl Effect on Geometry and Volumes

Swirl effects are quite typical in the FX world. Whether you're new to Houdini or a seasoned pro, this guide will show you how to create a simple yet powerful swirl effect using VEX. We'll apply a rotational transformation to achieve this effect on both geometry and volume data.

Swirling Geometry

First, let's look at how to apply a swirl effect to geometry. We will use a rotation matrix to rotate the points around a specified center. Here's the VEX code you'll need:

VEXpression
vector center = point(3, "P", 0);

float mask = chramp("mask_falloff", fit(length(center-v@P), 0, chf("max_dist"), 1, 0));

matrix3 rot = ident();
float angle = chf("angle")*mask;
rotate(rot, angle , chv("axis"));

v@P -= center;
v@P *= rot;
v@P += center;

Explanation:

  • Center Calculation: We start by specifying the center of the swirl effect.
  • Distance Mask: A mask is created to control the intensity of the swirl based on the distance from the center. The chramp function allows for artistic control over the mask.
  • Rotation Matrix: A rotation matrix is created and the rotation angle is determined by the mask. The geometry is then rotated around the specified axis.
  • Transform Geometry: To apply the rotation correctly, we temporarily move the geometry to the origin, apply the rotation, and then move it back.

Swirling Volumes

The same setup can be utilized for volumes. However, since we cannot directly move voxels, we'll copy them into a new layer from a new position.

of course, same setup could be utilised for other elements like volumes. One thing to note here - we cannot move voxels (its like pixels in 3D space), but we can copy them into a new layer from a new position:

VEXpression
vector center = point(3, "P", 0);

float mask = chramp("mask_falloff", fit(length(center-v@P), 0, chf("max_dist"), 1, 0));

matrix3 rot = ident();
float angle = chf("angle")*mask;
rotate(rot, angle , chv("axis"));

vector pos = v@P;
pos -= center;
pos *= rot;
pos+= center;

f@density = volumesample(1, 0, pos);

Explanation:

  • Center Calculation: Similar to the geometry, we start by specifying the center of the swirl effect.
  • Distance Mask: A mask is created to control the intensity of the swirl based on the distance from the center.
  • Rotation Matrix: A rotation matrix is created and the rotation angle is determined by the mask.
  • Transform Volume: The new position for each voxel is calculated by temporarily moving the position to the origin, applying the rotation, and then moving it back. The voxel data is then sampled from the original volume at this new position.

By understanding and utilising these techniques, you can create stunning swirl effects in your Houdini projects. Happy swirling!