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 ; at it is Lambert's model. Their qualitative model, the form used in most renderers, is
with , , and . 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 . The slopes of the faces have a Gaussian distribution with mean 0 and standard deviation (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. and have the polar angles and from the normal and the azimuths and . 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 , , and a separate interreflection term.
The qualitative model. Section 4.4 drops 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, and , so
needs no trigonometric functions.
What it counts
is a BRDF in 1/sr: reflected radiance per unit irradiance. The term is a Lambertian term scaled down. The term counts light that the faces turned toward the light reflect back toward it. When is on the same side as , 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 :
| , both at 60°, same side | , 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, and the radiance at the angle from the center is proportional to :
| 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 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 and the light at the angle , the directional albedo is:
| 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 , because for every . The qualitative model loses light at high roughness, partly because it drops the interreflections, and it gives slightly more than 1 for small 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. gives , and 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 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 the model is Lambert's.
- Reciprocity (proved). , and are symmetric in and , so .
- Backscatter (proved for the formula). For fixed and , is largest when the azimuths are equal and is whenever they differ by 90° or more.
- Albedo at normal incidence (proved). Equal to , which is below for .
- 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 , and directions with , the code computes with , , , and . 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 , .
Proof. and .
Claim 2 (the vector form). With , , and .
Proof. Cosine is decreasing on , so . Then . In a frame with , and the same for , so . Since , .
Claim 3 (reciprocity). .
Proof. , and do not change when and are swapped.
Claim 4 (backscatter). For fixed , is largest at and equals whenever .
Proof. and , so increases with , which is largest at and 0 when .
Claim 5 (the albedo). The directional albedo is with formed from and . In particular .
Proof. . The term gives . In the term only depends on , and its integral over a full turn is 2. At , for every , so the term is 0.
Claim 6 (the sphere lit from the viewer). With at the angle from the normal, the radiance for unit irradiance at normal incidence is .
Proof. and , and the irradiance is .
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.
# 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
- 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)
- 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
- 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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H2 full proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag TGP977 Edit this page History Report an error Markdown