-
Notifications
You must be signed in to change notification settings - Fork 186
2D Pixel Perfect Shadows
Detailed here is an approach to 2D pixel-perfect shadows using shaders and the GPU. Because of the high fill rate and multiple passes involved, this is generally less performant than geometry shadows; however, it has a number of benefits. It will be implemented in LibGDX, although the concepts can be applied to any OpenGL/GLSL framework.
The basic steps involved:
-
Render occluders (shadow casters) to a FBO; if they cast a shadow, they will be opaque, otherwise transparent.
-
Build a 1-dimensional "shadow map" from our occluders. The x-axis represents angle (theta), and the colour represents the minimum distance from light center to the nearest occluder.
-
Using the 1D shadow map, render our blurred shadows. Then render our sprites on top.
Here is a visual demonstration of the technique:
The idea is an extension of my previous attempts at shader-based shadows, which combines ideas from various sources. However, "nego" on LibGDX forums suggested some great ideas to reduce the process into fewer passes.