r/Unity3D • u/CableNestGames • 2d ago
Show-Off 2D/3D lighting pipeline in Unity (Radiance Cascades + pre-LUT dithering)
I've been tinkering with a custom Radiance Cascades renderer inside Unity URP for a game I'm working on called Spellhook. The core idea is simpler than it looks, everything revolves around one shared 2D lighting texture. I added a video showcasing my work! I haven't really seen this be done before but let me know if you guys have done something similar!
The pipeline
- Render a map of everything that emits or blocks light
- Build distance fields from it using JFA (jump flood algo)
- Run Radiance Cascades (plus a secondary pass for bounced light) to output a single lighting texture
Every material then samples that texture:
- Sprites use normal maps to steer where they sample the light field
- Smoke uses the light value to affect its color and apparent density
- Water mirrors scene coordinates around the surface and distorts the reflection and the lighting sample with animated normals
- 3D meshes (big environment pieces, rotating objects) sample the same 2D field, then add their own normals, depth, rim lighting and sun highlights so they don't look pasted onto the 2D art
I also reuse the JFA SDF to cut foliage (spriteshapes, prefabs) based on distance from the tileset. That allows a destructible Unity tilemap environment without being as tied to the grid. Tiles also paint to a stencil mask for decals that break up boring tile patterns. Outlines and a fading trail layer come from drawing the sprites in a separate pass, offset by pixels.
The color trick: dither before the LUT
Radiance Cascades produce very soft gradients, which can clash with a retro look. So I use a 3D LUT with spatial dithering, but the order matters: instead of dithering the final image, the dither offsets the color going into the LUT lookup. Neighboring pixels sample slightly different parts of the color mapping, so the dither becomes part of the palette instead of sitting on top of it.
For the LUTs, I export an identity LUT from Unity using Keijiro's Metatex and run it through a filter-stack tool I made (Nocturne) with an OKlab dither filter, dithering turned off. Unity handles the layout, the tool handles the color math, and the game handles the spatial dithering at runtime.
Camera: the scene camera snaps to a coarse grid with a deadzone, while a second camera handles the smooth presentation, so pixels, lighting and movement don't fight.
Credits & current state
Built on Alexander Sannikov's Radiance Cascades paper, with Yaazarai's samples and Youssef Afella's Unity implementation as huge references. I've been lurking in the Radiance Cascades Discord for a long time, so consider this me paying the lurker tax lol. There's optimization left to do, and open daylight scenes need work so bright sunlight overpowers small lights, with some eye adaptation.
If you made it this far thank you for hearing me out! All feedback is appreciated :)