Skip to main content

✨ Caustics Generator - Dynamic Underwater Light Patterns

· 3 min read
Galidar
Founder, Galidar Studio

Real-time caustics generation using GPU-accelerated particle grids for physically-accurate underwater light refraction patterns.

Overview

Caustics are the light patterns visible underwater and on submerged surfaces, created by light refraction through the water surface. The Caustics Generator provides a flexible system for creating these effects using Hierarchical Instanced Static Meshes (HISMC).


Caustics Generator Actor

AOceanologyCausticsGenerator

UCLASS(Blueprintable)
class AOceanologyCausticsGenerator : public AActor
{
// Generate water preview mesh grid
UFUNCTION(BlueprintCallable)
void SpawnWaterPreviewGrid(
UHierarchicalInstancedStaticMeshComponent* HISMC,
float GridSize,
int GridTiles
);

// Generate caustic particle grid
UFUNCTION(BlueprintCallable)
void SpawnCausticParticleGrid(
UHierarchicalInstancedStaticMeshComponent* HISMC,
float GridSize,
int GridTiles
);

// Editor tick for real-time preview
UFUNCTION(BlueprintNativeEvent, CallInEditor)
void EditorTick(float DeltaSeconds);
};

Grid Systems

Water Preview Grid

Visualizes the water surface mesh for caustic ray calculation:

ParameterDescription
GridSizeTotal area covered in world units
GridTilesSubdivision count per axis
HISMCTarget instanced mesh component

Caustic Particle Grid

Generates light ray particles that project caustic patterns:

ParameterDescription
GridSizeCoverage area matching water preview
GridTilesParticle density (tiles × tiles)
HISMCParticle mesh instances

How It Works

Ray Tracing Approach

  1. Surface Sampling: Sample wave heights across grid
  2. Normal Calculation: Compute surface normals
  3. Ray Refraction: Calculate light ray bending
  4. Projection: Project caustic intensity to surfaces

Physical Accuracy

The system accounts for:

  • Snell's Law refraction
  • Wave-based normal variation
  • Depth attenuation
  • Light source direction

Editor Integration

Real-Time Preview

virtual bool ShouldTickIfViewportsOnly() const override;
virtual void Tick(float DeltaSeconds) override;

UFUNCTION(BlueprintCallable)
void SetEditorTickEnabled(bool bEnabled);

Enable EditorTickIsEnabled for live caustic preview in editor viewport.


Configuration

Grid Density

QualityGridTilesParticlesPerformance
Low321,024Excellent
Medium644,096Good
High12816,384Moderate
Ultra25665,536Demanding

Optimization Tips

  • Reduce grid density for distant water
  • Use LOD system for particle meshes
  • Limit update frequency for static scenes
  • Bake caustics for fixed sun angle

Integration with Underwater

Caustics work with the underwater post-process system:

ComponentCaustics Role
Underwater VolumeDefines caustic visible zone
Water MaterialReceives caustic projection
Sun DirectionPrimary light source for rays
Wave AmplitudeCaustic intensity variation

Visual Parameters

Caustic Appearance

ParameterEffect
IntensityOverall brightness
ScalePattern size
SpeedAnimation rate
Chromatic AberrationRGB separation

Depth-Based Falloff

  • Near surface: High contrast patterns
  • Mid depth: Softer, blended patterns
  • Deep water: Minimal visibility

Blueprint Integration

Setting Up Caustics

  1. Add Generator Actor to level
  2. Configure Grid size and density
  3. Assign HISMC components
  4. Enable Editor Tick for preview
  5. Adjust Parameters for desired look

Runtime Control

// Toggle caustics at runtime
CausticsGenerator->SetEditorTickEnabled(bEnableCaustics);

Performance Considerations

GPU Instancing

HISMC provides efficient GPU instancing:

  • Single draw call per grid
  • Hardware instancing support
  • Automatic LOD management

Update Frequency

ModeUpdate RateUse Case
Every Frame60 HzDynamic scenes
Fixed Interval10-30 HzPerformance mode
BakedStaticCinematic

Future Enhancements

FeatureStatus
Ray Marching CausticsPlanned
Screen-Space CausticsResearch
Volumetric CausticsPlanned
Compute Shader PathPlanned

Resources

  • Example Levels: See Maps/CausticsDemo
  • Material Functions: MF_CausticProjection
  • Documentation: Underwater rendering guide