‹ benspencer.io

Real-time Global Illumination

Jul 10, 2022

Click for the live demo hosted on Shadertoy.

A collection of real-time illumination algorithms. The direct illumination component is evaluated using Stokes' analytic contour integral method with occlusion approximated using signed distance functions. The indirect component is evaluated using a progressive path tracer which bakes incident radiance into a linear grid of spherical harmonic light probes. The probes are cumulatively updated so changes to lighting and geometry are reflected over successive frames.

Full write-up coming soon.

Setup

Stage breakdown

Click for the live demo hosted on Shadertoy.

Direct Illumination

Stage breakdown

Click for the live demo hosted on Shadertoy.

Click for the live demo hosted on Shadertoy.

Incident radiance

For a perfectly diffuse object, the light reflected from its surface is simply the integral of incident radiance divided by the constant pi. There are many ways of estimating incident radiance depending on the size and shape of the light as well as the integration scheme used to compute it. For example, Monte Carlo methods solve the integral numerically by randomly sampling the domain of the integrand. Though this is a versatile technique, it may require many hundreds of samples before the residual noise drops to acceptable levels.

Since in this demo all surfaces are diffuse and the only source of direct illumination is from a simple quad, we can borrow a technique originally designed to computing form factors in finite-element radiosity. This algorithm makes use of Stoke’s theorem to transform the double integral of an area light projected onto the unit hemisphere into a simple contour integral which can be evaluated analytically. The upshot is that we can precisely calculate the incident light arriving on a diffuse surface without needing to mess around with random sampling or other approximations.

Occlusion

While the contour integral method gives us an exact value for incident radiance, it does not account for loss of energy due to occlusion by other objects. As previous stated, we could fall back on Monte Carlo sampling or even something like light mapping to calculate whether or not the light is occluded, however neither of these techniques is practical for a shader demo. Luckily, we can make use of signed distance fields to take an educated guess at how much an object may be blocking the light.

Stage breakdown

Click for the live demo hosted on Shadertoy.

Click for the live demo hosted on Shadertoy.

Indirect Illumination

Stage breakdown

Click for the live demo hosted on Shadertoy.

Click for the live demo hosted on Shadertoy.

Shadertoy demo