Algorithm Search⌘K

Modeladvanced

Oren-Nayar reflectance model

Also called Oren-Nayar model.

A diffuse model for rough surfaces made of Lambertian V-cavity facets. Compared with Lambert, it scatters more light back toward the light source and gives rough objects a flatter look.

The Oren-Nayar model describes the diffuse reflection of rough matte surfaces such as clay, plaster, concrete, sand and cloth. A Lambertian surface has a constant BRDF, so a Lambertian sphere lit from the viewer is bright in the center and dark at the rim. Real rough objects do not look like that: Oren and Nayar (1994) showed a clay vase that is almost equally bright over its whole surface, and the full moon is a well-known case of the same effect. They modeled the surface as many small V-shaped cavities whose faces are Lambertian, and computed the reflection with masking, shadowing and interreflection between the faces. The result has a roughness parameter σ\sigma; at σ=0\sigma = 0 it is Lambert's model. Their qualitative model, the form used in most renderers, is

f(l,v)=ρπ(A+Bmax⁡(0,cos⁡(ϕv−ϕl))sin⁡αtan⁡β),f(l, v) = \frac{\rho}{\pi}\Big(A + B \max\big(0, \cos(\phi_v - \phi_l)\big) \sin\alpha \tan\beta\Big),

with A=1−0.5 σ2/(σ2+0.33)A = 1 - 0.5\, \sigma^2 / (\sigma^2 + 0.33), B=0.45 σ2/(σ2+0.09)B = 0.45\, \sigma^2 / (\sigma^2 + 0.09), α=max⁡(θl,θv)\alpha = \max(\theta_l, \theta_v) and β=min⁡(θl,θv)\beta = \min(\theta_l, \theta_v). The roughness lowers the reflection near the normal and adds a term that is large when the viewer is near the light (backscatter).

The machine

The surface. A height field made of long symmetric V-cavities, each with two flat Lambertian faces of albedo ρ\rho. The slopes of the faces have a Gaussian distribution with mean 0 and standard deviation σ\sigma (in radians), and the cavities have all orientations in the plane (Oren and Nayar 1994, Sections 3 and 4.3). The cavities are much larger than the wavelength, so geometric optics applies, and much smaller than a pixel.

Directions. ll and vv have the polar angles θl\theta_l and θv\theta_v from the normal and the azimuths ϕl\phi_l and ϕv\phi_v. All vectors point away from the surface.

The full model. For one cavity orientation the paper computes the radiance of each face with masking and shadowing, plus a two-bounce interreflection term, and averages over the Gaussian distribution. The average has no closed form, so the paper fits a functional approximation (Equation 27) with three coefficients C1C_1, C2C_2, C3C_3 and a separate interreflection term.

The qualitative model. Section 4.4 drops C3C_3 and the interreflection term, which numerical tests showed to be small, and keeps the formula above (Equation 30). The constants 0.33, 0.09 and 0.45 are fitted to the numerical model, so they are tuning, not derived values. For rendering with unit vectors, sin⁡αtan⁡β=sin⁡θlsin⁡θv/max⁡(cos⁡θl,cos⁡θv)\sin\alpha \tan\beta = \sin\theta_l \sin\theta_v / \max(\cos\theta_l, \cos\theta_v) and cos⁡(ϕv−ϕl)sin⁡θlsin⁡θv=l⋅v−(n⋅l)(n⋅v)\cos(\phi_v - \phi_l) \sin\theta_l \sin\theta_v = l \cdot v - (n \cdot l)(n \cdot v), so

f=ρπ(A+B max⁡(0, l⋅v−(n⋅l)(n⋅v))max⁡(n⋅l, n⋅v))f = \frac{\rho}{\pi}\Big(A + B\, \frac{\max\big(0,\ l \cdot v - (n \cdot l)(n \cdot v)\big)}{\max(n \cdot l,\ n \cdot v)}\Big)

needs no trigonometric functions.

What it counts

ff is a BRDF in 1/sr: reflected radiance per unit irradiance. The AA term is a Lambertian term scaled down. The BB term counts light that the faces turned toward the light reflect back toward it. When vv is on the same side as ll, the faces that the viewer sees are mostly the lit ones; on the far side, the viewer sees mostly the faces in shadow, and the term is 0.

Example. With ρ=1\rho = 1:

σ\sigma AA BB πf\pi f, both at 60°, same side πf\pi f, both at 60°, opposite sides
0 1 0 1 1
0.25 0.9204 0.1844 1.1970 0.9204
0.5 0.7845 0.3309 1.2808 0.7845
1 0.6241 0.4128 1.2433 0.6241

The flat look. For a sphere lit from the viewer, l=vl = v and the radiance at the angle θ\theta from the center is proportional to cos⁡θ (A+Bsin⁡θtan⁡θ)\cos\theta\, (A + B \sin\theta \tan\theta):

σ\sigma 0° 30° 60° 80°
0 (Lambert) 1 0.866 0.5 0.1736
0.5 0.7845 0.7621 0.6404 0.4571
1 0.6241 0.6437 0.6217 0.5088

At σ=1\sigma = 1 the brightness changes by about 20 percent between the center and 80°, while the Lambertian sphere loses 83 percent. The paper reports the same flattening for its rendered spheres (Section 6).

The albedo. With ρ=1\rho = 1 and the light at the angle θl\theta_l, the directional albedo ∫fcos⁡θv dωv\int f \cos\theta_v\, d\omega_v is:

σ\sigma 0° 30° 60° 80° 89°
0.25 0.9204 0.9428 0.9754 1.0012 1.0116
0.5 0.7845 0.8247 0.8831 0.9295 0.9481
1 0.6241 0.6743 0.7472 0.8049 0.8282

At normal incidence the albedo is exactly AA, because tan⁡β=0\tan\beta = 0 for every vv. The qualitative model loses light at high roughness, partly because it drops the interreflections, and it gives slightly more than 1 for small σ\sigma at grazing light. These values come from the code of this page, which checks the 2D quadrature against a 1D integral.

Relation to other models

  • Lambertian reflectance. σ=0\sigma = 0 gives A=1A = 1, B=0B = 0 and f=ρ/πf = \rho / \pi for all directions.
  • Microfacet BRDFs. The same idea, a statistical surface of flat faces with masking and shadowing, but with diffuse faces instead of mirrors. The masking and shadowing come from V-cavities, as in the GG of Torrance and Sparrow, not from the Smith model.
  • Burley diffuse. The Disney principled BRDF uses an empirical diffuse term instead, which also changes with roughness and gives rough surfaces a brighter grazing response. Burley chose it because it gave a reasonable match to measured materials. Many real-time engines use Lambert or Burley diffuse instead of Oren-Nayar.
  • Moon reflectance. The paper lists older models of lunar reflectance and Smith's shadowing of rough surfaces as earlier work on backscatter.

Known results in the model

  • Lambert limit (proved). At σ=0\sigma = 0 the model is Lambert's.
  • Reciprocity (proved). α\alpha, β\beta and cos⁡(ϕv−ϕl)\cos(\phi_v - \phi_l) are symmetric in ll and vv, so f(l,v)=f(v,l)f(l, v) = f(v, l).
  • Backscatter (proved for the formula). For fixed θl\theta_l and θv\theta_v, ff is largest when the azimuths are equal and is ρA/π\rho A / \pi whenever they differ by 90° or more.
  • Albedo at normal incidence (proved). Equal to ρA\rho A, which is below ρ\rho for σ>0\sigma > 0.
  • Accuracy of the qualitative model (measurement). Oren and Nayar compare the model with measured samples such as wall plaster and report a close match, with larger errors where interreflection matters (Section 5). How well it fits another material is a measurement for that material.
  • The constants (tuning). 0.33, 0.09 and 0.45 are fitted to numerical evaluations of the full model.
Proof: Properties of the qualitative Oren-Nayar modelfull

Setting. For σ≥0\sigma \ge 0, ρ≥0\rho \ge 0 and directions with θl,θv∈[0,π/2)\theta_l, \theta_v \in [0, \pi / 2), the code computes f=ρπ(A+Bmax⁡(0,cos⁡Δϕ)sin⁡αtan⁡β)f = \frac{\rho}{\pi}(A + B \max(0, \cos\Delta\phi) \sin\alpha \tan\beta) with A=1−0.5σ2/(σ2+0.33)A = 1 - 0.5 \sigma^2 / (\sigma^2 + 0.33), B=0.45σ2/(σ2+0.09)B = 0.45 \sigma^2 / (\sigma^2 + 0.09), α=max⁡(θl,θv)\alpha = \max(\theta_l, \theta_v), β=min⁡(θl,θv)\beta = \min(\theta_l, \theta_v) and Δϕ=ϕv−ϕl\Delta\phi = \phi_v - \phi_l. A second function computes the same value from unit vectors. The claims are about these formulas. That they match the full V-cavity model or a real surface is a measurement reported by Oren and Nayar (1994), not a claim here.

Claim 1 (Lambert limit). At σ=0\sigma = 0, f=ρ/πf = \rho / \pi.

Proof. A=1−0=1A = 1 - 0 = 1 and B=0B = 0. □\square

Claim 2 (the vector form). With cl=n⋅lc_l = n \cdot l, cv=n⋅vc_v = n \cdot v, sin⁡αtan⁡β=sin⁡θlsin⁡θv/max⁡(cl,cv)\sin\alpha \tan\beta = \sin\theta_l \sin\theta_v / \max(c_l, c_v) and cos⁡Δϕsin⁡θlsin⁡θv=l⋅v−clcv\cos\Delta\phi \sin\theta_l \sin\theta_v = l \cdot v - c_l c_v.

Proof. Cosine is decreasing on [0,π/2)[0, \pi / 2), so cos⁡β=max⁡(cl,cv)\cos\beta = \max(c_l, c_v). Then sin⁡αtan⁡β=sin⁡αsin⁡β/cos⁡β=sin⁡θlsin⁡θv/max⁡(cl,cv)\sin\alpha \tan\beta = \sin\alpha \sin\beta / \cos\beta = \sin\theta_l \sin\theta_v / \max(c_l, c_v). In a frame with n=zn = z, l=(sin⁡θlcos⁡ϕl,sin⁡θlsin⁡ϕl,cl)l = (\sin\theta_l \cos\phi_l, \sin\theta_l \sin\phi_l, c_l) and the same for vv, so l⋅v=sin⁡θlsin⁡θv(cos⁡ϕlcos⁡ϕv+sin⁡ϕlsin⁡ϕv)+clcv=sin⁡θlsin⁡θvcos⁡Δϕ+clcvl \cdot v = \sin\theta_l \sin\theta_v (\cos\phi_l \cos\phi_v + \sin\phi_l \sin\phi_v) + c_l c_v = \sin\theta_l \sin\theta_v \cos\Delta\phi + c_l c_v. Since sin⁡θlsin⁡θv≥0\sin\theta_l \sin\theta_v \ge 0, max⁡(0,cos⁡Δϕ)sin⁡θlsin⁡θv=max⁡(0,l⋅v−clcv)\max(0, \cos\Delta\phi) \sin\theta_l \sin\theta_v = \max(0, l \cdot v - c_l c_v). □\square

Claim 3 (reciprocity). f(l,v)=f(v,l)f(l, v) = f(v, l).

Proof. max⁡\max, min⁡\min and cos⁡Δϕ\cos\Delta\phi do not change when ll and vv are swapped. □\square

Claim 4 (backscatter). For fixed θl,θv\theta_l, \theta_v, ff is largest at Δϕ=0\Delta\phi = 0 and equals ρA/π\rho A / \pi whenever cos⁡Δϕ≤0\cos\Delta\phi \le 0.

Proof. B≥0B \ge 0 and sin⁡αtan⁡β≥0\sin\alpha \tan\beta \ge 0, so ff increases with max⁡(0,cos⁡Δϕ)\max(0, \cos\Delta\phi), which is largest at Δϕ=0\Delta\phi = 0 and 0 when cos⁡Δϕ≤0\cos\Delta\phi \le 0. □\square

Claim 5 (the albedo). The directional albedo is E(θl)=ρ(A+2Bπ∫0π/2sin⁡αtan⁡βcos⁡θsin⁡θ dθ)E(\theta_l) = \rho \big(A + \frac{2B}{\pi} \int_0^{\pi / 2} \sin\alpha \tan\beta \cos\theta \sin\theta\, d\theta\big) with α,β\alpha, \beta formed from θl\theta_l and θ\theta. In particular E(0)=ρAE(0) = \rho A.

Proof. E=∫02π∫0π/2fcos⁡θsin⁡θ dθ dϕE = \int_0^{2\pi} \int_0^{\pi / 2} f \cos\theta \sin\theta\, d\theta\, d\phi. The AA term gives ρAπ⋅2π⋅12=ρA\frac{\rho A}{\pi} \cdot 2\pi \cdot \frac12 = \rho A. In the BB term only max⁡(0,cos⁡Δϕ)\max(0, \cos\Delta\phi) depends on ϕ\phi, and its integral over a full turn is 2. At θl=0\theta_l = 0, β=0\beta = 0 for every θ\theta, so the BB term is 0. □\square

Claim 6 (the sphere lit from the viewer). With l=vl = v at the angle θ\theta from the normal, the radiance for unit irradiance at normal incidence is ρπcos⁡θ(A+Bsin⁡θtan⁡θ)\frac{\rho}{\pi} \cos\theta (A + B \sin\theta \tan\theta).

Proof. Δϕ=0\Delta\phi = 0 and α=β=θ\alpha = \beta = \theta, and the irradiance is cos⁡θ\cos\theta. □\square

What the tests check. Claim 1 at random directions, Claims 2 and 3 at 2000 random inputs, Claim 4 and Claim 6 at the page values, and Claim 5 by comparing the 2D midpoint quadrature with the 1D integral of the claim and both with the page values.

Code

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

oren_nayar_reflectance_model.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/oren-nayar-reflectance-model/. The authors are listed in prov/TGP977.jsonl.

"""The qualitative Oren-Nayar model of rough diffuse reflection.

sigma is the standard deviation of the facet slope angle, in radians. rho is
the albedo of each Lambertian facet. Angles are measured from the normal;
vectors point away from the surface.
"""

import math

Vec = tuple[float, float, float]


def coefficients(sigma: float) -> tuple[float, float]:
    """A = 1 - 0.5 s2 / (s2 + 0.33) and B = 0.45 s2 / (s2 + 0.09), s2 = sigma^2."""
    s2 = sigma * sigma
    return 1.0 - 0.5 * s2 / (s2 + 0.33), 0.45 * s2 / (s2 + 0.09)


def oren_nayar(theta_i: float, theta_r: float, cos_dphi: float, sigma: float, rho: float = 1.0) -> float:
    """The BRDF rho / pi (A + B max(0, cos dphi) sin(alpha) tan(beta)), in 1/sr.

    alpha = max(theta_i, theta_r), beta = min(theta_i, theta_r), and dphi is
    the difference of the azimuths of the two directions.
    """
    if theta_i >= math.pi / 2.0 or theta_r >= math.pi / 2.0:
        return 0.0
    a, b = coefficients(sigma)
    alpha = max(theta_i, theta_r)
    beta = min(theta_i, theta_r)
    return rho / math.pi * (a + b * max(0.0, cos_dphi) * math.sin(alpha) * math.tan(beta))


def dot(p: Vec, q: Vec) -> float:
    return p[0] * q[0] + p[1] * q[1] + p[2] * q[2]


def oren_nayar_vectors(n: Vec, l: Vec, v: Vec, sigma: float, rho: float = 1.0) -> float:
    """The same BRDF from unit vectors, with no trigonometric calls but one sqrt.

    sin(alpha) tan(beta) = s_i s_r / max(c_i, c_r) for the sines s and cosines c,
    and cos dphi s_i s_r = l.v - c_i c_r.
    """
    ci, cr = dot(n, l), dot(n, v)
    if ci <= 0.0 or cr <= 0.0:
        return 0.0
    a, b = coefficients(sigma)
    g = dot(l, v) - ci * cr  # cos(dphi) sin(theta_i) sin(theta_r)
    return rho / math.pi * (a + b * max(0.0, g) / max(ci, cr))


def albedo(theta_i: float, sigma: float, rho: float = 1.0, nt: int = 600, npf: int = 64) -> float:
    """The directional albedo, the integral of f cos(theta_r) over the hemisphere."""
    total = 0.0
    dt = (math.pi / 2.0) / nt
    dp = math.pi / npf  # symmetric in dphi, so integrate over [0, pi] and double
    for i in range(nt):
        t = (i + 0.5) * dt
        w = math.cos(t) * math.sin(t)
        ring = 0.0
        for j in range(npf):
            p = (j + 0.5) * dp
            ring += oren_nayar(theta_i, t, math.cos(p), sigma, rho)
        total += ring * w
    return 2.0 * total * dt * dp


def sphere_lit_from_viewer(theta: float, sigma: float) -> float:
    """Radiance times pi / rho of a sphere point at angle theta, light at the eye.

    With l = v, theta_i = theta_r = theta and dphi = 0, so the value is
    cos(theta) (A + B sin(theta) tan(theta)) for unit irradiance at normal incidence.
    """
    a, b = coefficients(sigma)
    return math.cos(theta) * (a + b * math.sin(theta) * math.tan(theta))
test_oren_nayar_reflectance_model.py 97 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/oren-nayar-reflectance-model/. The authors are listed in prov/TGP977.jsonl.

"""Tests of the qualitative Oren-Nayar model against Lambert and against a 1D reference."""

import math
import random

from oren_nayar_reflectance_model import (
    albedo,
    coefficients,
    oren_nayar,
    oren_nayar_vectors,
    sphere_lit_from_viewer,
)

N = (0.0, 0.0, 1.0)


def sph(t: float, p: float) -> tuple[float, float, float]:
    return (math.sin(t) * math.cos(p), math.sin(t) * math.sin(p), math.cos(t))


def albedo_1d(theta_i: float, sigma: float, steps: int = 20000) -> float:
    """A + (2 B / pi) times the integral of sin(alpha) tan(beta) cos(t) sin(t) dt.

    The integral of max(0, cos dphi) over a full turn is 2, which removes the azimuth.
    """
    a, b = coefficients(sigma)
    dt = (math.pi / 2.0) / steps
    total = 0.0
    for i in range(steps):
        t = (i + 0.5) * dt
        al, be = max(theta_i, t), min(theta_i, t)
        total += math.sin(al) * math.tan(be) * math.cos(t) * math.sin(t)
    return a + 2.0 * b / math.pi * total * dt


def test_coefficients() -> None:
    table = {0.25: (0.9204, 0.1844), 0.5: (0.7845, 0.3309), 1.0: (0.6241, 0.4128), 2.0: (0.5381, 0.4401)}
    for s, (a, b) in table.items():
        ca, cb = coefficients(s)
        assert abs(ca - a) < 5e-5 and abs(cb - b) < 5e-5
    assert coefficients(0.0) == (1.0, 0.0)


def test_smooth_is_lambert() -> None:
    rng = random.Random(1)
    for _ in range(500):
        l = sph(rng.uniform(0, 1.55), rng.uniform(0, 2 * math.pi))
        v = sph(rng.uniform(0, 1.55), rng.uniform(0, 2 * math.pi))
        rho = rng.uniform(0, 1)
        assert abs(oren_nayar_vectors(N, l, v, 0.0, rho) - rho / math.pi) < 1e-15


def test_forms_agree_and_reciprocity() -> None:
    rng = random.Random(2)
    for _ in range(2000):
        ti, pi_ = rng.uniform(0, 1.55), rng.uniform(0, 2 * math.pi)
        tr, pr = rng.uniform(0, 1.55), rng.uniform(0, 2 * math.pi)
        s = rng.uniform(0.0, 1.5)
        f_ang = oren_nayar(ti, tr, math.cos(pr - pi_), s)
        f_vec = oren_nayar_vectors(N, sph(ti, pi_), sph(tr, pr), s)
        assert abs(f_ang - f_vec) < 1e-9 * max(1.0, f_ang)
        assert abs(oren_nayar(tr, ti, math.cos(pi_ - pr), s) - f_ang) < 1e-15
        assert f_ang >= 0.0


def test_backscatter() -> None:
    t = math.radians(60.0)
    assert abs(math.pi * oren_nayar(t, t, 1.0, 0.5) - 1.2808) < 5e-5
    assert abs(math.pi * oren_nayar(t, t, -1.0, 0.5) - 0.7845) < 5e-5
    assert abs(math.pi * oren_nayar(t, t, 1.0, 1.0) - 1.2433) < 5e-5
    assert abs(math.pi * oren_nayar(t, t, -1.0, 1.0) - 0.6241) < 5e-5


def test_albedo() -> None:
    table = {
        0.25: (0.9204, 0.9428, 0.9754, 1.0012, 1.0116),
        0.5: (0.7845, 0.8247, 0.8831, 0.9295, 0.9481),
        1.0: (0.6241, 0.6743, 0.7472, 0.8049, 0.8282),
    }
    for s, vals in table.items():
        for deg, val in zip((0.0, 30.0, 60.0, 80.0, 89.0), vals):
            ref = albedo_1d(math.radians(deg), s)
            assert abs(ref - val) < 5e-4
            assert abs(albedo(math.radians(deg), s, nt=300, npf=32) - ref) < 2e-3
        # At normal incidence tan(beta) = 0, so only A is left (the midpoint rule adds about 4e-5).
        assert abs(albedo(0.0, s, nt=100, npf=8) - coefficients(s)[0]) < 1e-4
        assert abs(albedo_1d(0.0, s, steps=10) - coefficients(s)[0]) < 1e-15


def test_sphere_lit_from_viewer() -> None:
    table = {0.0: (1.0, 0.866, 0.5, 0.1736), 0.5: (0.7845, 0.7621, 0.6404, 0.4571), 1.0: (0.6241, 0.6437, 0.6217, 0.5088)}
    for s, vals in table.items():
        for deg, val in zip((0.0, 30.0, 60.0, 80.0), vals):
            assert abs(sphere_lit_from_viewer(math.radians(deg), s) - val) < 5e-5

References

  1. Michael Oren and Shree K. Nayar, Generalization of Lambert's reflectance model, SIGGRAPH 94, 1994, 239 to 246, Section 3 (the V-cavity roughness model), Section 4.3 (the model for a Gaussian slope-area distribution and its functional approximation, Equation 27), Section 4.4 (the qualitative model, Equation 30), Section 5 (experiments) and Section 6 (implications for graphics)
  2. Matt Pharr, Wenzel Jakob and Greg Humphreys, Physically Based Rendering, From Theory to Implementation, third edition, Morgan Kaufmann, 2016, Section 8.4.1, Oren-Nayar Diffuse Reflection
  3. Brent Burley, Physically-based shading at Disney, course notes, SIGGRAPH 2012 course Practical Physically Based Shading in Film and Game Production, revised 2014, Section 5.3, Diffuse model details (an empirical rough diffuse term used in place of Oren-Nayar)

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH2 full proof
  • correctness: no review record reviews/TGP977/proof-correctness.yaml
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/TGP977/text.yaml