Shield Fluid Simulation

Project information

  • Category: Compute Shaders, Unity Shaders
  • Project date: 20 April, 2025

Shield Fluid Simulation

This project features a fully GPU-driven shield simulation for a 2D top-down spaceship game in Unity. The effect simulates ripples propagating through the ship's shield when impacted, visualized as a glowing hex grid that shimmers and fades over time—like water disturbed by a drop. Fully built using a shader & compute shader within Unity, with C# hooked in to pass the compute shader impact points.

Why I Built This

Traditional shield effects are often static or pre-animated. I wanted something reactive—something that visually communicates where and how a ship is being hit. Inspired by fluid simulations and ripple propagation, I used a compute shader to simulate dynamic impact waves, layered with a custom shader that reveals the shield’s hex grid only when active.

This system allows each ship in the scene to have its own independent, performant shield simulation—no singletons, no global state—making it modular and scalable for complex encounters.

How It Works

  • Impact Buffering: Hits are registered as UV coordinates and injected into a structured buffer on the GPU.
  • Compute Shader: Expands ripples out over time using a Gaussian-like falloff and decay.
  • Ship Mask: Prevents shield effects from leaking outside the hull's silhouette.
  • Visual Shader: Uses additive blending and a glowing hex pattern to reveal shimmering shield segments only where hit.
  • Fully Modular: Each ship has its own shield controller, making the system plug-and-play in prefab workflows.

Tech Highlights

  • Fully GPU-driven simulation—no CPU-side texture writes.
  • Custom RenderTexture swap chain for persistent simulation states.
  • Shader uses lerp(0, shieldColor, ripple * mask) logic—no conditionals—for max performance.
  • Emission strength slider in material for bloom integration.
  • Supports custom UV scaling and tiling for different ships.

What I Learned

1. UV Debugging is Everything: One bad remap can ruin a good shader. Fixing a single world-to-UV transform unlocked the whole pipeline.

2. Visual Clarity Requires Discipline: Additive glow must be controlled. By using sim * mask before blending, I avoided noisy shield spam across the screen.

3. GPU Pipelines Scale Well: Once offloaded, I could simulate 50+ active shield systems without a hiccup. Unity’s compute and render texture pipeline works—if you respect the threading model.

4. Per-Object Modularity > Singleton Design: The system is prefab-safe and works without global managers, making it ideal for large-scale tactical games.