# Lighting ## Forward ``` for each triangle: for each pixel: for each light: shade(pixel, light) ``` - Overdraw penalty. - Client must specify all lights (for the object) up front. ## Deferred ### Forward Pass The forward pass generates: - Depth - Texture ID - Texture coordinates Sampling of textures is deferred to avoid overdraw penalty. ### Pixel-centric Shading ``` for each pixel: for each light: shade(pixel, light) ``` - Need a pixel-in-volume test. - Inefficient if most pixels are not affected by a light. - Ok: ambient, directional. - Bad: point, area. ### Light-centric Shading ``` for each light: volume <- project light volume for each pixel in volume: shade(pixel, light) ``` - Need to project the light volume. - Shades only the pixels that are covered by the volume. - For ambient and directional, the volume is all space. ## Clustered ### Cluster Generation ``` for each light: volume <- project light volume to NDC for each cluster: test(cluster, volume) ``` - Need a volume-AABB test (the cluster is an AABB in NDC space.) - Lighting then proceeds as in deferred.