The water and cloud nodes (prefix ELEM) are few, only seven.
They are few because I decided not to rebuild what already exists.
What I did not build
Wave spectra are already produced by SideFX's nodes.
So ELEM_OceanExport does not make waves. It takes the Ocean Spectrum and only writes the spectrum out as .exr files and a manifest.json, to be read by an FFT on the game side. I checked that the written values match Ocean Evaluate to 1e-6 m, and I fixed the rules for the axis mapping (Unreal's X is Houdini's X, Y is Z and Z is Y) and for using meters.
I also did not make breaking-wave simulation an HDK node.
SideFX's FLIP and Labs' VAT are already C++, so an asset (HDA) is enough. Where existing pieces are enough, I do not rebuild them. That was the call for this group of nodes.
Shallows: solving when a wave arrives
ELEM_ShoreField takes a heightfield and writes water depth, distance to shore, wave arrival time, direction, shoaling and slope into shore_* layers.
Arrival time comes from solving |∇T| = 1/c(h) (the eikonal equation) with the fast sweeping method, where the wave speed c comes from linear dispersion.
const float a = SYSmin(x > 0 ? t(i - 1) : kFar, x + 1 < s.w ? t(i + 1) : kFar);
const float b = SYSmin(y > 0 ? t(i - s.w) : kFar, y + 1 < s.h ? t(i + s.w) : kFar);
const float next = eikonalUpdate(a, b, float(slowness(i) * s.cell));
if (next < t(i)) { change = SYSmax(change, t(i) - next); t(i) = next; }A 1024² cook takes about 0.8 s.
The wavelength at 2 m depth is within 0.002% of the dispersion formula, and the refraction angle is within 0.002 degrees of Snell's law.
Caustics: scatter light forward
ELEM_Caustics refracts photons leaving the water surface and splats them onto a floor.
The photon count is conserved, so flat water gives exactly 1 for brightness. The old asset started photons from the rest position, but the new version starts them from the displaced position, so the lines sit where the displaced crests focus them.
It can also export a looping flipbook.
It re-cooks the input at shifted times, packs the frames into a grid, and refuses to export unless the loop closes to within 5% of the average frame-to-frame change.
Clouds: join spheres into a distance field
ELEM_Cloud lays spheres (blobs) along curves and points and unions them into a distance field.
It then adds fractal noise for bumps, optionally runs an advection pass to shred the edges, and finally outputs a density volume. Quality is a switch between draft (guide curves only) and final (the full volume cook).
The bumps and advection also run in OpenCL, and fall back to the CPU on failure.
if (displaceCloudSdfOpenCL(sdf, params.displace, gpu_err)) {
used_gpu_displace = true;
} else {
gpu_fallback_msg.sprintf("GPU displace failed (%s); falling back to CPU.", /* ... */);
if (!Weather::displaceCloudSdf(sdf, params.displace, err)) return false;
}Resolution is set by voxel size: Low is 0.4, Medium 0.2, High 0.1 and Ultra 0.05.
High and Ultra are heavy, so they are for final looks.
What I threw away
The first wave nodes (the Gerstner-wave ELEM_Ocean, ELEM_Waves, ELEM_WaveFoam and ELEM_WaveSpray) were deleted because SideFX's spectrum is better.
ELEM_FlipGPU (an OpenCL FLIP) is labelled "experimental", and its README says not to claim any speed without a matched comparison.
Summary
For this group of nodes, I decided between the HDK and an asset by asking whether the thing already exists.
What I did decide to build is what is hard to write as an asset, like the shore node that solves an equation. Keeping a record of deleted nodes also speeds up the next decision.
Next: rigging and motion nodes.
Comments