Skip to content
Niffoxic

The Blood Curse

AAA-quality, horizon-scale water in Unreal Engine 5.8: a custom GPU FFT ocean for 0.10–0.38 ms, plus real-time blood fluid and a slime enemy.

Type
Water simulation · UE 5.8 · HLSL compute
Role
Solo: simulation, compute and material shaders, optimisation, gameplay code, benchmarks and the automated capture tool
Stack
Unreal Engine 5.8 · C++ · HLSL compute · Render Dependency Graph · FFT · Position-based fluids · Gameplay Ability System
The Blood Curse

A four-cascade FFT ocean to a 50 km horizon for 0.10–0.38 ms of GPU time, with seven presets from reference to low-end.

GPU time for the whole ocean simulation, across seven quality presets
0.10–0.38 ms
to the horizon, with wave cascades from 19 m to 1 km and a 9-level grid that follows the camera
50 km
cheaper blood-fluid neighbour search: 9.3 ms brute force to 0.93 ms with a sorted grid
10×
of game-thread time per extra slime enemy; render thread and GPU stay nearly flat
~15 µs

Overview

Game water has a scale problem. Spectral FFT oceans reach the horizon cheaply but never react to anything, while particle fluids react properly but only over a few metres. I reviewed ten papers on this trade-off, then built both ends myself for a dark-fantasy action game, as custom compute shaders in my own Unreal plugin (no Niagara, no engine Water system). The centrepiece is a blood-red Tessendorf ocean that runs to a 50 km horizon. I treated its cost as an optimisation problem: every technique I tried is kept as a selectable preset, so a project can pick the quality it can afford, from 0.38 ms down to 0.10 ms of GPU time. Up close, a position-based GPU fluid handles thick blood that splatters, clings and drips, and a slime enemy shows the same thinking applied to gameplay.

The full reel, with captions: the ocean's seven presets on one camera path, with the game's panel showing live GPU time, then the blood fluid and the slime.

What I built

  • Tessendorf FFT ocean A Phillips spectrum, an inverse FFT per cascade and an assemble pass that writes choppy displacement, analytic slopes and accumulated Jacobian foam. Four band-limited cascades (1 km, 271 m, 73 m and 19 m patches, with non-integer ratios to hide tiling) cover everything from swell to ripples.
  • Horizon-scale grid A camera-following grid of 9 LOD levels, 50 cm cells near the camera and doubling each level, with a flat skirt out to a 50 km horizon. The material snaps vertices to each level's lattice, so the grid moves with the camera without swimming or cracking.
  • Fused and batched pipeline The reference path runs 6 dispatches per cascade. The fused path evaluates the spectrum while loading the row FFT and assembles while storing the column FFT: 2 dispatches per cascade. Batched, all four cascades share those 2 dispatches.
  • Kernel and memory options Radix-2 or radix-8 Stockham FFT kernels, FFT sizes of 128, 256 or 512, fp16 intermediates, staggered updates for the slow large cascades, and in-shader mip generation instead of the engine's per-mip passes.
  • GPU blood fluid Position-based fluids with density constraints, XSPH viscosity, adhesion and surface tension. A counting-sort grid handles the neighbour search; particles are gathered into a 3D density volume that the material ray-marches, with a custom shadow pass so the volume casts correct shadows.
  • Slime enemy Built on the game's Gameplay Ability System combat. Lean, squash, wobble, hit flash and puddle melt are damped springs written to Custom Primitive Data, and the vertex shader bends a sphere from them, so every slime shares one material and stays batched.
  • Measured and recorded automatically GPU timestamp queries, a live stats panel in the game, and a scripted camera tour that launches the game and records every clip with ffmpeg, with no human input.

Results

8 figures
The Ultra preset: four cascades at 512², radix-8 FFT and in-shader mips. The panel shows live numbers from the running game, not from editing.
FIG. 1The Ultra preset: four cascades at 512², radix-8 FFT and in-shader mips. The panel shows live numbers from the running game, not from editing.
Every optimisation is kept as a selectable preset rather than replacing the last one, so the same ocean can run as a hero shot or on a low-end GPU.
FIG. 2Every optimisation is kept as a selectable preset rather than replacing the last one, so the same ocean can run as a hero shot or on a low-end GPU.
The Low preset: three cascades at 128², the slowest ones updating every 2nd and 4th frame, for 0.10 ms.
FIG. 3The Low preset: three cascades at 128², the slowest ones updating every 2nd and 4th frame, for 0.10 ms.
Blood bursts against a wall and splats on the floor: a position-based GPU fluid, ray-marched as a surface. 0.03–0.45 ms depending on how many particles are alive.
FIG. 4Blood bursts against a wall and splats on the floor: a position-based GPU fluid, ray-marched as a surface. 0.03–0.45 ms depending on how many particles are alive.
Blood gathers on a ceiling, drips and pools on the floor, held up by adhesion and surface tension. 0.3–0.8 ms.
FIG. 5Blood gathers on a ceiling, drips and pools on the floor, held up by adhesion and surface tension. 0.3–0.8 ms.
The fluid's cost was the neighbour search. Sorting particles by grid cell every substep keeps neighbours next to each other in memory.
FIG. 6The fluid's cost was the neighbour search. Sorting particles by grid cell every substep keeps neighbours next to each other in memory.
The slime enemy: it wanders, hops to chase the player, winds up and lunges for real damage, splits when hit and melts into a puddle.
FIG. 7The slime enemy: it wanders, hops to chase the player, winds up and lunges for real damage, splits when hit and melts into a puddle.
The same slimes with the translucent jelly look. One sphere mesh and one material for every slime; all the jiggle is in the vertex shader.
FIG. 8The same slimes with the translucent jelly look. One sphere mesh and one material for every slime; all the jiggle is in the vertex shader.

Hard parts

  • Finding where the time goes: the radix-8 kernel only wins at 512² (13–15% faster) and is slightly slower at 128², where a fixed ~0.09 ms floor dominates. In-shader mips beat the engine's mip generation at every size (0.157 → 0.125 ms at 256²) and look identical.
  • Keeping alternatives honest: fp16 intermediates halve memory but gave no measurable speed-up on the test GPU, so they stay an option, not a default.
  • Making thick fluid stable: the tensile correction had to be normalised by the constraint gradient in centimetre units, or the blood boiled. Negative pressure, per-iteration correction and velocity are clamped.
  • Shadows of ray-marched volumes: virtual shadow maps ignore pixel depth offset, so the volume casts through its own shadow-pass march, and the translucent jelly look draws its shadow from a hidden opaque twin.

Limits

What it doesn't do yet
  • The ocean and the fluid are separate systems today.
  • The ocean is large but doesn't react to objects, and the blood fluid runs inside a bounded box.
  • The next step is coupling them, so near-field splashes and wakes feed the ocean.
Harsh Dubey

Harsh Dubey

Graphics and game programmer. MSc Games Engineering (Distinction), University of Warwick.

About me