Back to projects
Unity / Shaders2025
Stylized Water Shader
Feature-rich water shader with tessellation, planar reflections, and Gerstner wave simulation for Unity's Built-in Pipeline.
UnityHLSLShaderLabC#
TessellationPlanar ReflectionGerstner WavesVoronoiCausticsFlow MapsFoamDepth-Based Effects
Overview
A professional stylized water shader demonstrating 10+ advanced graphics programming techniques. Implements physically-based wave displacement, real-time planar reflections, Voronoi caustics, and GPU tessellation for adaptive surface detail.
Key Features
- Gerstner wave displacement with tangent/binormal calculation
- Distance-based GPU tessellation (Hull/Domain shaders)
- Real-time planar reflections via reflection camera
- Procedural Voronoi-based caustics patterns
- Flow maps for directional water movement
- Shore waves with animated foam
- Underwater fog with depth-based visibility
- Blinn-Phong specular highlights
Technical Breakdown
How It Works
- 1Vertex shader applies Gerstner wave formula: displacement based on wavelength, amplitude, and time
- 2Hull shader calculates tessellation factors based on camera distance
- 3Domain shader interpolates vertices and reapplies wave displacement
- 4Fragment shader composites multi-layer surface: reflections, refractions, foam, caustics
- 5GrabPass captures screen for refraction distortion
- 6Depth texture samples scene depth for edge foam and underwater fog
Architecture
- StylizedWater.shader — Main water shader (vertex/hull/domain/fragment)
- EnableDepthTexture.cs — Camera depth texture setup
- PlanarReflection.cs — Real-time reflection camera management
Notable Details
- •Hull/Domain shader pipeline enables up to 64x tessellation based on distance
- •Gerstner waves provide realistic ocean motion vs simple sine waves
- •Voronoi algorithm generates procedural caustic patterns without textures
- •Dual-phase UV system for flow maps prevents obvious tiling
- •Requires Shader Model 4.6+ and DirectX 11 for tessellation support
Setup & Usage
Installation
- 1
Clone repository: git clone https://github.com/SametKaras/stylized-water-shader.git - 2
Open project in Unity 2020.3+ (Built-in RP) - 3
Open Assets/Scenes/SampleScene.unity - 4
Attach EnableDepthTexture.cs to Main Camera - 5
Attach PlanarReflection.cs to water plane for reflections
Parameters
| Name | Type | Effect |
|---|---|---|
| Wave Amplitude | Range | Height of wave displacement |
| Wave Wavelength | Range | Distance between wave peaks |
| Tessellation Factor | Range | Surface subdivision density |
| Foam Threshold | Range | Depth at which shoreline foam appears |
| Caustics Intensity | Range | Strength of underwater light patterns |
Challenges & Learnings
- Mastered GPU tessellation pipeline (hull/domain shader stages)
- Implemented physically-based Gerstner wave formula for realistic motion
- Learned Voronoi procedural generation for caustics without texture lookups
- Managed reflection camera synchronization with main camera
Outcomes
- ✓Demonstrates 10+ advanced rendering techniques in a single shader
- ✓Production-ready quality suitable for stylized game projects
- ✓Includes detailed BREAKDOWN.md with mathematical foundations