Light & the rendering equation光与渲染方程
Lessons 04–06 made geometry appear correctly — the right triangles, at the right depths, with clean edges. But everything is still flat and unlit: we never said how much light leaves a surface, or why. Lesson 01 wrote the rendering equation as a north star and moved on. Now we earn it from the ground up, out of radiometry — the physics of measuring light — so that lessons 08–12 can each take responsibility for approximating one piece of it. 第 04–06 课让几何正确地显现——对的三角形、对的深度、干净的边缘。但一切仍是扁平、无光照的:我们从没说过一个表面射出多少光、以及为什么。第 01 课把渲染方程当作北极星写下就走开了。现在我们要从头把它挣出来,从辐射度量学——测量光的物理——出发,好让第 08–12 课各自负责近似它的其中一块。
Five moves. (1) Build the radiometric ladder flux → irradiance → radiance, and see why radiance — constant along a ray, exactly what a pixel measures — is the star of the whole track. (2) Derive Lambert's cosine law: grazing light is dim because a fixed beam spreads over more area, so irradiance ∝ cosθ — the widget makes this visible. (3) Define the BRDF fr as the material's fingerprint and state its three laws. (4) Assemble the reflectance integral over the hemisphere, and derive the famous diffuse ρ/π from energy conservation with a worked number. (5) Add emission and recursion to recover the full rendering equation, and map the rest of the course onto its terms.
五步走。(1) 搭起辐射度量学的阶梯:辐射通量 → 辐照度 → 辐射亮度,看清为何辐射亮度——沿光线不变、恰是像素所测之量——是整门课的主角。(2) 推导朗伯余弦定律:掠射光暗,是因为固定的光束摊到了更大的面积上,故辐照度 ∝ cosθ——控件把这一点可视化。(3) 把 BRDF fr 定义为材质的指纹,并陈述它的三条定律。(4) 在半球上装配反射积分,并由能量守恒推出著名的漫反射 ρ/π,配一道算得出的数。(5) 加上自发射与递归以恢复完整的渲染方程,并把余下的课程映射到它的各项上。
1 · The radiometric ladder: flux, irradiance, radiance辐射度量学的阶梯:通量、辐照度、辐射亮度
To simulate a light measurement we first need units for "amount of light." There are three rungs, each one dividing the previous by a smaller and smaller region of the world. Climb them least-to-most.
要模拟一次对光的测量,我们首先需要“光的多少”的单位。共有三级台阶,每一级都把上一级除以一块越来越小的世界的范围。由少到多地爬上去。
- Radiant flux Φ — total power, in watts (W). A 5 W lamp emits 5 joules of radiant energy per second, full stop. It has no notion of where or which direction; it is one number for the whole source.辐射通量 Φ——总功率,单位瓦特 (W)。一盏 5 W 的灯每秒发出 5 焦耳辐射能,仅此而已。它不含“何处”或“哪个方向”的概念;对整个光源只是一个数。
- Irradiance E — power per unit area, in W/m². Now we ask how densely that power lands on a surface: E = dΦ / dA. Move a page twice as far from the lamp and the same flux spreads over four times the area, so E drops fourfold — the inverse-square law falls straight out of "power ÷ area."辐照度 E——单位面积上的功率,单位 W/m²。现在我们问那份功率有多密地落到一个表面上:E = dΦ / dA。把一页纸挪到离灯两倍远,同样的通量摊到四倍的面积上,于是 E 降为四分之一——平方反比律直接从“功率 ÷ 面积”掉出来。
- Radiance L — power per unit area per unit solid angle, in W/m²/sr: L = d²Φ / (dA cosθ dω). This is the amount of light travelling along a single ray — through a tiny area, packed into a tiny cone of directions. It is the finest rung, and the one that matters.辐射亮度 L——单位面积、单位立体角上的功率,单位 W/m²/sr:L = d²Φ / (dA cosθ dω)。这是沿单独一条光线传播的光量——穿过一小块面积、挤进一个小小的方向锥里。它是最精细的一级,也是要紧的那一级。
A solid angle ω is the 3-D analogue of a 2-D angle: as a plane angle is arc length over radius (radians), a solid angle is area on a sphere over radius² — measured in steradians (sr). The whole sphere is 4π sr; a hemisphere is 2π sr. In spherical coordinates, where θ is the angle from the pole (the normal) and φ the azimuth, a differential patch of directions is
立体角 ω 是二维角的三维类比:正如平面角是弧长比半径(弧度),立体角是球面上的面积比半径²——以球面度 (sr) 计量。整个球是 4π sr;半球是 2π sr。在球坐标中,θ 是与极轴(法线)的夹角、φ 是方位角,一小片方向的微元为
The sinθ is not decoration: near the pole (θ→0) a band of directions is tiny, near the equator it is fat, and sinθ is exactly that weighting. Integrate it over the hemisphere and you recover ∫02π∫0π/2 sinθ dθ dφ = 2π sr — a self-check we will lean on in section 4.
那个 sinθ 不是装饰:靠近极轴(θ→0)时一圈方向很小,靠近赤道时很宽,而 sinθ 恰是这个权重。把它在半球上积分,你会得到 ∫02π∫0π/2 sinθ dθ dφ = 2π sr——这是第 4 节要依靠的一次自检。
Two facts make L the quantity graphics is built on. First, radiance is constant along a ray in vacuum: as light travels from surface to eye, area and solid angle trade off inversely (things look smaller and subtend a proportionally smaller cone), so L in equals L out — a surface does not look dimmer just because it is farther away (its image shrinks, but each point keeps its brightness). Second, a pixel measures radiance: a sensor integrates the radiance arriving along the cone of rays it accepts. So the Lo on the left of the rendering equation is literally the pixel value. Every ray we trace in lessons 10–11 carries a radiance; every shading computation in lesson 08 outputs one.
有两个事实让 L 成为图形学赖以立身的量。其一,辐射亮度在真空中沿一条光线保持不变:光从表面走向眼睛时,面积与立体角成反比地此消彼长(物体看起来更小,同时张成一个成比例更小的锥),于是入射的 L 等于出射的 L——一个表面不会仅仅因为更远就显得更暗(它的像缩小了,但每一点仍保持自己的亮度)。其二,像素测量的正是辐射亮度:传感器把沿它所接受的光线锥到达的辐射亮度积分起来。所以渲染方程左边的 Lo 字面上就是像素值。第 10–11 课里我们追踪的每一条光线都携带一个辐射亮度;第 08 课里每一次着色计算都输出一个。
2 · Lambert's cosine law — why grazing light is dim朗伯余弦定律——为什么掠射光是暗的
Irradiance was "power per unit area," but power arriving from a given direction depends on the angle at which it strikes. Take a parallel beam — sunlight — of fixed cross-sectional width. Hit a surface head-on (θ = 0 from the normal) and the beam's footprint on the surface exactly equals its cross-section. Tilt the surface to angle θ and the same beam now smears across a footprint of width 1/cosθ — wider, so the same power is diluted over more area.
辐照度是“单位面积上的功率”,但从某个方向到来的功率取决于它打上表面的角度。取一束固定横截面宽度的平行光——阳光。正面直射(与法线夹角 θ = 0),光束在表面的足迹恰好等于它的横截面。把表面倾斜到角度 θ,同一束光如今抹在一块宽 1/cosθ 的足迹上——更宽了,于是同样的功率被稀释到更大的面积上。
Power is conserved, area grew by 1/cosθ, so irradiance shrinks by exactly cosθ:
功率守恒,面积增大了 1/cosθ 倍,所以辐照度恰好缩小 cosθ 倍:
That single cosθ = (ω·n) is the ubiquitous cosine factor in the rendering equation — the (ωi·n) we met in lesson 01 and glossed as "Lambert's law." It is not a property of any material; it is pure geometry, the price of hitting a surface off-axis. It is why the poles of a lit sphere are bright and the terminator (where θ→90°) fades to black, and why the low winter sun warms less than the same sun overhead in summer. The widget below makes the footprint spreading literal.
这个单独的 cosθ = (ω·n) 就是渲染方程里无处不在的余弦因子——第 01 课遇到、被一笔带过为“朗伯定律”的那个 (ωi·n)。它不是任何材质的属性;它是纯粹的几何,是偏离法线打到表面所付的代价。它解释了为什么被照亮的球两极明亮、而晨昏线(θ→90° 处)淡入黑暗,也解释了为什么冬天低垂的太阳,比夏天头顶同一个太阳更不暖和。下面的控件把足迹的铺开摊到明面上。
3 · The BRDF — the material's fingerprintBRDF——材质的指纹
Now the material. When irradiance dEi arrives from direction ωi, some fraction is reflected toward the eye direction ωo as outgoing radiance dLo. The ratio — reflected radiance out, per unit irradiance in — is the bidirectional reflectance distribution function:
现在轮到材质。当辐照度 dEi 从方向 ωi 到来,其中一部分被反射到眼睛方向 ωo,成为出射辐射亮度 dLo。这个比值——每单位入射辐照度所反射出的辐射亮度——就是双向反射分布函数:
Its units are 1/sr (radiance over irradiance = (W/m²/sr)/(W/m²)). Note the division is by irradiance, which already carries the cosθi of section 2 — that cosine belongs to the geometry, not the material, which is why it sits outside fr in the integral. A mirror, chalk, and brushed steel are three utterly different functions of (ωi, ωo); the BRDF is exactly what distinguishes materials. It obeys three physical laws, and a model that breaks any of them is not physically based:
它的单位是 1/sr(辐射亮度比辐照度 = (W/m²/sr)/(W/m²))。注意分母是辐照度,它已经带上了第 2 节的 cosθi——那个余弦属于几何、而非材质,所以它在积分里位于 fr 之外。镜子、粉笔、拉丝钢是关于 (ωi, ωo) 的三个截然不同的函数;BRDF 恰恰是区分材质的东西。它遵守三条物理定律,破坏其中任何一条的模型都不是基于物理的:
| Law | Statement | Why it must hold |
|---|---|---|
| Non-negativity | fr ≥ 0 | A surface cannot reflect a negative amount of light in any direction. |
| Helmholtz reciprocity | fr(ωi, ωo) = fr(ωo, ωi) | Light paths are reversible; swapping source and eye gives the same value. This is what lets a path tracer start rays from either the eye or the light. |
| Energy conservation | ∫Ω fr cosθo dωo ≤ 1 | A passive surface cannot reflect more energy than it receives (the excess, 1 − that integral, is absorbed). |
| 定律 | 陈述 | 为何必须成立 |
|---|---|---|
| 非负性 | fr ≥ 0 | 表面不可能向任何方向反射“负”的光量。 |
| 亥姆霍兹互易性 | fr(ωi, ωo) = fr(ωo, ωi) | 光路可逆;交换光源与眼睛得到相同的值。正是这一点让路径追踪器可以从眼睛或光源任一端发出光线。 |
| 能量守恒 | ∫Ω fr cosθo dωo ≤ 1 | 被动表面反射的能量不能多于它接收的(多出的部分 1 − 该积分被吸收)。 |
4 · The reflectance integral, and the diffuse 1/π反射积分,与漫反射的 1/π
A surface point does not receive light from one direction but from the whole hemisphere Ω above it. To get the total reflected radiance toward the eye, integrate the contribution fr · dEi over every incoming direction — substituting dEi = Li cosθi dωi from section 2:
一个表面点并非从单一方向接收光,而是从它上方整个半球 Ω 接收。要得到射向眼睛的总反射辐射亮度,就把贡献 fr · dEi 在每个入射方向上积分——代入第 2 节的 dEi = Li cosθi dωi:
This is the reflectance equation — the rendering equation minus emission (next section). Now specialize to the simplest material, the ideal diffuse (Lambertian) surface, which by definition looks equally bright from every direction: its fr is a constant, independent of ωi and ωo. Call it fr = k. What must k be? Energy conservation pins it. Illuminate the surface so that its total reflected fraction (the albedo ρ, between 0 and 1) is whatever we choose; then
这就是反射方程——渲染方程减去自发射(下一节)。现在特化到最简单的材质,理想漫反射(朗伯)表面,它按定义从每个方向看去都一样亮:它的 fr 是常数,与 ωi 和 ωo 无关。记它为 fr = k。k 必须是多少?能量守恒把它钉死。以某种方式照亮表面,使其反射的总比例(反照率 ρ,介于 0 与 1)等于我们所选之值;那么
The integral ∫0π/2 cosθ sinθ dθ = ½ (it is ∫ u du with u = sinθ), and the azimuth contributes 2π, so the hemisphere-with-cosine weight is exactly π — not 2π. Solving, k = ρ/π. That stray π in every diffuse shader is this integral; drop it and a white (ρ=1) surface would reflect π ≈ 3.14× the light it receives, manufacturing energy from nothing.
积分 ∫0π/2 cosθ sinθ dθ = ½(令 u = sinθ 即 ∫ u du),方位角贡献 2π,所以“半球带余弦权重”恰好是 π——而非 2π。解出 k = ρ/π。每个漫反射着色器里那个多出来的 π 就是这个积分;去掉它,一个白色(ρ=1)表面就会反射 π ≈ 3.14× 于它接收的光,无中生有地制造能量。
A directional light (sunlight) delivers irradiance E⊥ = 1000 W/m² on a surface facing it squarely. The surface is diffuse grey, albedo ρ = 0.5, so fr = ρ/π = 0.5/π ≈ 0.159 sr⁻¹. The light arrives at θi = 60° from the normal, so the actual irradiance on the surface is E = E⊥ cos60° = 1000 × 0.5 = 500 W/m² (section 2's cosine). For a single directional source the hemisphere integral collapses to one term — no dω — and the reflected radiance is Lo = fr · E = 0.159 × 500 ≈ 79.6 W/m²/sr. Crucially, because the surface is Lambertian this same Lo is seen from every viewing direction — the eye's position does not appear in the answer.
一束方向光(阳光)在正对它的表面上提供辐照度 E⊥ = 1000 W/m²。表面是漫反射灰色、反照率 ρ = 0.5,于是 fr = ρ/π = 0.5/π ≈ 0.159 sr⁻¹。光以偏离法线 θi = 60° 入射,所以表面上的实际辐照度是 E = E⊥ cos60° = 1000 × 0.5 = 500 W/m²(第 2 节的余弦)。对单个方向光源,半球积分坍缩为一项——没有 dω——反射的辐射亮度是 Lo = fr · E = 0.159 × 500 ≈ 79.6 W/m²/sr。关键在于:因为表面是朗伯的,每一个观察方向看到的都是同一个 Lo——答案里根本不出现眼睛的位置。
5 · Emission + recursion = the rendering equation自发射 + 递归 = 渲染方程
Two additions complete the picture. First, some surfaces emit light on their own — lamps, the sun, a glowing screen — contributing a term Le that owes nothing to incoming light. Add it to the reflectance integral and you have Kajiya's 1986 rendering equation, the exact statement of light-surface equilibrium — the same line lesson 01 wrote down:
两处添加使画面完整。第一,有些表面自己发射光——灯、太阳、发光的屏幕——贡献一项 Le,它与入射光无关。把它加到反射积分上,你就得到了 Kajiya 1986 年的渲染方程,光与表面平衡的精确陈述——正是第 01 课写下的那一行:
Second, and this is the sting, the incoming radiance Li(x, ωi) is not free data. The light arriving at x from direction ωi is whatever other surface lies along that direction — and what that surface sends toward x is its own Lo. So Li at one point is Lo at another: the equation defines Lo in terms of itself, all over the scene. It is recursive — an integral equation, not an algebraic one. That single fact is the entire reason global illumination is hard: to shade one point correctly you must, in principle, already have solved every other point (a red couch bleeding onto a white wall, light bouncing twice under a table). The Li term is the recursion; everything expensive in rendering descends from it.
第二,也正是扎心之处,入射辐射亮度 Li(x, ωi) 不是白给的数据。从方向 ωi 到达 x 的光,正是沿该方向躺着的那个别的表面——而那个表面朝 x 送来的,是它自己的 Lo。于是此处的 Li 就是彼处的 Lo:方程用 Lo 自己来定义 Lo,遍及整个场景。它是递归的——一个积分方程,而非代数方程。仅此一点,就是全局光照之所以难的全部原因:要正确地给一个点着色,原则上你必须已经解出了其他每一个点(红沙发把颜色渗到白墙上、光在桌下弹两次)。Li 这一项就是递归;渲染中一切昂贵之处都从它衍生。
Now the payoff: the rest of the course is a catalogue of which piece of this one equation each technique chooses to approximate.
现在是回报:余下的课程,就是一份目录,记录每种技术选择去近似这一个方程的哪一块。
| Lesson | What it does to the equation | Cost / fidelity |
|---|---|---|
| 08 · Shading & PBR | Drops the recursion and the integral; sums fr Li (ωi·n) over a few explicit lights only. | Real-time; misses all indirect light. |
| 10–11 · Ray / path tracing | Actually evaluates the integral, sampling Li by recursively tracing rays (Monte Carlo). | Offline; converges to the true answer. |
| 12 · Real-time GI | Precomputes or fakes the recursive Li — lightmaps, probes, screen-space tricks. | Real-time; approximate indirect light. |
| 课 | 它对方程做了什么 | 开销 / 保真度 |
|---|---|---|
| 08 · 着色与 PBR | 丢掉递归与积分;只对少数几个显式光源求和 fr Li (ωi·n)。 | 实时;漏掉所有间接光。 |
| 10–11 · 光线 / 路径追踪 | 真正计算这个积分,通过递归地追踪光线来采样 Li(蒙特卡洛)。 | 离线;收敛到真实答案。 |
| 12 · 实时全局光照 | 预计算或伪造递归的 Li——光照贴图、探针、屏幕空间技巧。 | 实时;近似的间接光。 |
Where this points next接下来指向何处
We now have the physics: light is measured in radiance, a surface reflects it through its BRDF weighted by the geometric cosine, integrated over the hemisphere, plus emission — and the incoming term makes it recursive. The very next lesson takes the cheapest possible cut. Lesson 08, Shading & PBR, throws away the recursion and the integral entirely, keeps only a handful of explicit light sources, and asks: what fr models a real material — diffuse, glossy, metal, dielectric — cheaply enough to evaluate once per light per pixel at 60 FPS? That is where the microfacet BRDFs, the Fresnel term, and the whole "PBR" vocabulary of roughness and metalness come from. Everything in lesson 08 is a legal, energy-conserving fr plugged into the equation we just derived.
现在我们有了物理:光以辐射亮度计量,一个表面通过它的 BRDF、乘以几何余弦、在半球上积分来反射光,再加上自发射——而入射项使它递归。紧接着的下一课取最便宜的一刀。第 08 课着色与 PBR 彻底扔掉递归和积分,只保留少数几个显式光源,然后问:什么样的 fr 能足够便宜地模拟真实材质——漫反射、光泽、金属、电介质——以至于能在 60 FPS 下每像素每光源求值一次?那正是微表面 BRDF、菲涅耳项,以及粗糙度与金属度这整套“PBR”词汇的来处。第 08 课里的一切,都是插进我们刚刚推出的方程里的、一个合法且能量守恒的 fr。
Light is measured on a ladder: flux Φ (W, total power) → irradiance E (W/m², per area) → radiance L (W/m²/sr, per area per solid angle). Radiance is the star: constant along a ray in vacuum, and exactly what a pixel measures. Lambert's cosine law — a fixed beam spreads over area 1/cosθ, so dE = L cosθ dω — is pure geometry, the (ωi·n) factor. The BRDF fr = dLo/dEi (units 1/sr) is the material's fingerprint and must be non-negative, reciprocal, and energy-conserving. The reflectance integral Lo = ∫Ω fr Li cosθi dωi sums the hemisphere; ideal diffuse gives fr = ρ/π (the π is the cosine-weighted hemisphere). Adding emission Le and the recursive Li (other surfaces' Lo) yields the full rendering equation — and that recursion is why GI is hard. Lessons 08 / 10–11 / 12 each approximate a different piece.
光按一架阶梯计量:通量 Φ(W,总功率)→ 辐照度 E(W/m²,每面积)→ 辐射亮度 L(W/m²/sr,每面积每立体角)。辐射亮度是主角:在真空中沿光线不变,且恰是像素所测之量。朗伯余弦定律——固定光束摊到面积 1/cosθ 上,故 dE = L cosθ dω——是纯几何,即那个 (ωi·n) 因子。BRDF fr = dLo/dEi(单位 1/sr)是材质的指纹,必须非负、互易、能量守恒。反射积分 Lo = ∫Ω fr Li cosθi dωi 对半球求和;理想漫反射给出 fr = ρ/π(那个 π 是带余弦权的半球)。加上自发射 Le 与递归的 Li(其他表面的 Lo),便得到完整的渲染方程——而那份递归正是全局光照难的原因。第 08 / 10–11 / 12 课各近似其中不同的一块。
Interview prompts面试题
- Define flux, irradiance, and radiance, with units. (§1 — flux Φ is total power (W); irradiance E is power per area (W/m²); radiance L is power per area per solid angle (W/m²/sr), one more division each rung down.) 定义通量、辐照度、辐射亮度,并给出单位。(§1 — 通量 Φ 是总功率 (W);辐照度 E 是每面积功率 (W/m²);辐射亮度 L 是每面积每立体角的功率 (W/m²/sr),每下一级多除一次。)
- Why is radiance the quantity a pixel measures, and what does "constant along a ray" mean? (§1 — a sensor integrates incoming radiance over its cone; in vacuum area and solid angle trade off inversely so L is unchanged along the ray — a surface's brightness doesn't fall with distance, only its image size.) 为什么辐射亮度是像素所测之量,“沿光线不变”是什么意思?(§1 — 传感器在其锥内对入射辐射亮度积分;真空中面积与立体角反向抵消,故 L 沿光线不变——表面亮度不随距离下降,只有它的成像尺寸变小。)
- What is a solid angle, and why does dω = sinθ dθ dφ carry a sinθ? (§1 — steradians = area on the unit sphere; the sinθ weights bands of directions, tiny at the pole and wide at the equator, and integrates to 2π over the hemisphere.) 什么是立体角,为什么 dω = sinθ dθ dφ 带一个 sinθ?(§1 — 球面度 = 单位球面上的面积;sinθ 给方向带加权,极点处小、赤道处宽,在半球上积分得 2π。)
- Where does the (ωi·n) cosine come from, and is it part of the material? (§2 — pure geometry: a fixed beam's footprint widens by 1/cosθ at incidence θ, diluting irradiance to ∝ cosθ; it lives outside the BRDF because it is not a material property.) (ωi·n) 这个余弦从何而来,它属于材质吗?(§2 — 纯几何:入射角 θ 时固定光束的足迹变宽 1/cosθ,把辐照度稀释到 ∝ cosθ;它在 BRDF 之外,因为它不是材质属性。)
- Define the BRDF and state its three laws. (§3 — fr = dLo/dEi, units 1/sr; non-negativity, Helmholtz reciprocity fr(ωi,ωo)=fr(ωo,ωi), and energy conservation ∫Ω fr cosθ dω ≤ 1.) 定义 BRDF 并陈述它的三条定律。(§3 — fr = dLo/dEi,单位 1/sr;非负性、亥姆霍兹互易性 fr(ωi,ωo)=fr(ωo,ωi)、能量守恒 ∫Ω fr cosθ dω ≤ 1。)
- Which term makes the rendering equation recursive, and why does that make GI hard? (§5 — Li: the light arriving at x is the Lo of other surfaces, so Lo is defined in terms of itself scene-wide — an integral equation needing every point solved to shade any point. And why is the diffuse constant ρ/π? because the cosine-weighted hemisphere integrates to π.) 渲染方程里是哪一项使它递归,为什么这让全局光照变难?(§5 — Li:到达 x 的光是其他表面的 Lo,故 Lo 在全场景范围内用自身定义——一个积分方程,要给任一点着色须先解出每一点。以及漫反射常数为何是 ρ/π?因为带余弦权的半球积分为 π。)