6-Way Lighting Shader

Adding baked directional lighting to 2D sprite sheets for enhanced depth.

Texture Setup

[Texture Preview Image]

One of the textures used for testing the effect.

Unity Shader Graph

Shader Graph

Full graph setup with custom lighting functions.

The Goal

I wanted to improve the look and depth of the effects in our games. I came across a very useful method of adding baked directional lighting into sprite sheets and using a shader to read this information. This works on particle systems as well as on regular meshes.

Implementation

This method is called 6-way lighting and is achieved by baking lighting information into the RGBA channels of two textures.

First Texture Packing

  • R - Top Down Lighting
  • G - Right Hand Lighting
  • B - Bottom Up Lighting
  • A - Left Hand Lighting

Second Texture Packing

  • R - Back Lighting
  • G - Free to use
  • B - Front Lighting
  • A - Alpha

Future Optimization

This Shader-Graph demonstrates how the setup works in Unity. I plan to move this across to HLSL when I use it in a production environment for performance gains. In this graph, I have included custom functions to allow me to access the light direction and color of a directional light.