Compute Shader Outline Baking

Project information

  • Category: Compute Shaders, Shadow Baking, Unity Shaders
  • Project date: May, 2025

Compute Shader Shadow Baking

This tool bakes shadow silhouettes of objects using a GPU-only pipeline in Unity. Designed for mobile performance, it captures prefab silhouettes from a top-down view, applies a series of compute shader passes to blur and stylize the shadow, then outputs a compressed texture. The result is packed into a shared texture atlas for ultra-cheap runtime shadows with support for translucent “stained-glass” effects.

Why I Built This

Dynamic shadows are expensive—especially translucent ones. Mobile platforms can’t afford full screen shadow maps or custom post-process passes per object. I needed a way to preserve visual quality without runtime cost. So I leaned into baking.

This tool allows shadows to look soft, colorful, and hand-crafted without needing any real-time processing. It fits seamlessly into prefab workflows and keeps runtime draw calls extremely low through GPU instancing with a baked texture atlas.

Objects can be fully dynamically moved around the play space and rotated seamlessly without any issue. If you weren't told these were baked you'd likely never know.

This tool collectively dropped over 500 draw calls during runtime and brought speeds of 30-40 fps up to a crisp smooth 60 fps instantly for us on low end devices.

How It Works

  • Silhouette Capture: An orthographic camera renders a prefab into a RenderTexture from the top view.
  • Compute Shader Processing: A multi-pass pipeline expands the shape, adds blur, and applies a stained-glass coloration effect for semi-transparent objects.
  • Compressed Output: The final result is stored as a compressed channel packed texture to keep it memory-light.
  • Atlas Packing: All shadows are combined into a unified Texture2DAtlas, using prefab IDs and JSON for lookup.
  • Runtime Performance: Shadows are rendered as quads with MaterialPropertyBlock overrides, costing 1 instanced draw call for all shadows on screen.

Tech Highlights

  • Compute shader driven pipeline with thread group optimization.
  • Custom stained-glass shadow effect with configurable color tint and transmission strength.
  • Zero CPU-side reads—entire pipeline remains on GPU.
  • Supports both opaque and transparent shadow variants per asset.
  • Instanced and batched draw call system using shadow quad prefabs with MaterialPropertyBlock IDs.

What I Learned

1. Stylized Shadows Require Custom Blur: Gaussian blur isn’t enough—stained-glass effects need contrast-preserving expansion, which required tuning kernel weights per channel.

2. Transparent Shadows Are Hard: Managing transmission color and opacity at runtime on mobile is really hard. Baking can be a life saver.

3. Atlas Packing is a Lifesaver: Combining all shadows into a single texture with ID indexing let me bypass Unity’s instancing limits on per-instance textures.

4. Mobile GPU Pipelines Benefit from Batch-Oriented Thinking: By offloading everything to setup-time, I achieved dynamic-looking shadows with zero runtime cost on GPU-bound platforms.

5. Reuse Old Code: This system was a modified alteration of my ouline baking tool (also posted in my portfolio pieces). I was able to adapt it over in about a day and we had shadows optimized in a single day. We saw over 500 draw calls vanish and giant performance gains. I always build modularly and this was a great reminder as to why I do it.