intermediate

#9 2D Lighting

Point light and glow

Lighting in 2D shaders works by calculating how far each pixel is from a light source and fading brightness with distance. A point light uses the inverse-square law — intensity / (distance * distance) — to create realistic falloff, bright near the source and dimming quickly. A softer glow uses intensity / (distance + epsilon) instead. The iMouse uniform lets the light follow your cursor, making the scene interactive. Tone mapping with col / (col + 1) prevents colors from blowing out to white.

Key Concepts

Try this shader live in the Shader Sandbox editor with real-time preview.
Open in Sandbox

Source Code


    
← Previous Noise Next → Intro to Raymarching

All Tutorials