Course contentsShow
← Unreal Engine Game Development
Lesson 519 of 8807. Visual Fidelity and RenderingFree lesson

Simulating Fluid and Refractive Surfaces

Create advanced water and glass materials using depth-based refraction, chromatic aberration, and screen-space reflections for high-end optical accuracy.

In this lesson, you will learn how to build high-fidelity water and glass materials by manipulating how light bends and fragments as it passes through a surface.

To achieve a convincing refractive look in Unreal Engine, we move beyond simple transparency and focus on the interaction between the surface and the scene behind it. When light enters a material like water or glass, it doesn't just pass through; it changes speed and direction—a process we simulate using Refraction in the Material Graph.

Depth-Based Refraction and Chromatic Aberration

The core of a high-end refractive material is the SceneColor node. By using SceneTexture: SceneColor in conjunction with SceneTexture: SceneDepth and the PixelDepth node, you can calculate the distance between the refractive surface and the objects behind it.

To create Chromatic Aberration, you sample the SceneColor texture three times, slightly offsetting the Red, Green, and Blue channels based on the surface normal and the viewing angle. This mimics how glass disperses light:

// Logic for a simplified refraction offset
float3 RefractionOffset = (VertexNormalWS * RefractionIntensity);
float2 Offset = ScreenUV + (RefractionOffset.xy * DepthFade);

// Sample individual channels for color fringing
float R = SceneTextureLookup(Offset + Distortion, 14, false).r;
float G = SceneTextureLookup(Offset, 14, false).g;
float B = SceneTextureLookup(Offset - Distortion, 14, false).b;

Integrating Screen-Space Reflections

For high-end surfaces, refraction alone feels "flat." You must combine it with Screen-Space Reflections (SSR). Since we are using Lumen, ensure your material’s Refraction input is set to a non-zero value, and your Roughness is low. This triggers the engine to calculate dynamic reflections on the surface while maintaining the depth-based distortion of the objects visible beneath.

Use a DepthFade node to ensure the transition between the refractive surface and the objects behind it is soft, preventing harsh "seams" where the mesh intersects with the geometry of your scene. This ensures that the deeper the water or thicker the glass, the more the light is distorted and absorbed, grounding the effect in physical reality.

Key Takeaway: Realistic refraction relies on using scene depth to scale your distortion and splitting RGB channels to simulate light dispersion, all while maintaining Lumen-enabled reflections for surface-level detail.