Techniquecore
Schlick's Fresnel approximation
Also called Schlick approximation.
Approximate the Fresnel reflectance by F0 + (1 - F0)(1 - cos theta)^5, where F0 is the reflectance at normal incidence. It is exact at 0 and 90 degrees and off by a few hundredths between.
Schlick's approximation replaces the Fresnel equations by one short formula. With for the angle of incidence and the reflectance at normal incidence,
For a dielectric with relative index , , which is 0.04 for glass with . Christophe Schlick proposed the form in 1994 as part of a cheap BRDF model. It is now the of nearly every real-time microfacet BRDF, where , the cosine between the view direction and the half vector. It is exact at normal and at grazing incidence, it rises monotonically between them, and it costs four multiplications. In between it is a fit, with errors up to about 0.04 for glass and larger for water, diamond and metals.
In plain words
A shiny surface reflects more light when you look at it at a low angle. A lake is clear at your feet and a mirror near the horizon. The exact physics of this effect needs square roots and depends on polarization. Schlick noticed that a simple curve does almost as well. You need one number, the reflectance when you look straight at the surface. The curve starts at that number and rises to full reflection at a grazing angle, and it rises fast only near the end. For glass and water the curve is close to the exact one. For metals and inside glass it can be noticeably wrong, and the sections below show how and how much.
When it applies
- A dielectric seen from the less dense side. Glass, water, plastic and paint seen from air. comes from the index of refraction, and the error is a few hundredths at most (measured below).
- A metal, per color channel. The Fresnel reflectance of a conductor has a complex index . Real-time code stores as an RGB color and uses the same formula. This keeps exact and the grazing value 1, but it misses the dip of the exact curve below near 80°.
- Inside the dense medium only with a change. From inside glass toward air, total internal reflection starts at the critical angle, for . The plain formula does not see it. The fix in the template below uses the cosine of the transmitted angle.
- A microfacet BRDF. Each facet is a mirror with normal , so the angle is between (or ) and . Using instead is a different model, a common mistake.
The template
The inputs are the cosine of the angle of incidence, the reflectance at normal incidence, an optional grazing value (1 for the Fresnel case), and for a dielectric the index ratio of the far side over the near side.
SCHLICK(c, F0, F90)- 1
c ← clamp(c, 0, 1) ▷ c = v·h in a microfacet BRDF - 2
m ← 1 - c - 3
return F0 + (F90 - F0) · m^5 ▷ m^5 as (m²)² · m: three products SCHLICK-DIELECTRIC(c, η)- 4
F0 ← ((η - 1) / (η + 1))² - 5
if η < 1 then ▷ light leaves the denser medium - 6
s ← (1 - c²) / η² ▷ sin² of the transmitted angle - 7
if s ≥ 1 then return 1 ▷ total internal reflection - 8
c ← sqrt(1 - s) ▷ use the transmitted cosine - 9
return SCHLICK(c, F0, 1)
Line L3 is the formula. At it gives and at it gives , and in between it is a monotone blend, because decreases with . Lines L5 to L8 use a proved symmetry of the exact equations: the reflectance from inside at the angle equals the reflectance from outside at the transmitted angle , so the inside error equals the outside error. The cost is per evaluation, with one square root only for light inside the dense medium.
Classic examples
Glass from air. , . The table gives the exact reflectance and the error of Schlick's formula.
| Angle | 0° | 30° | 45° | 60° | 70° | 80° | 85° | 89° |
|---|---|---|---|---|---|---|---|---|
| Exact | 0.0400 | 0.0415 | 0.0502 | 0.0892 | 0.1710 | 0.3877 | 0.6128 | 0.9042 |
| Schlick | 0.0400 | 0.0400 | 0.0421 | 0.0700 | 0.1584 | 0.4099 | 0.6485 | 0.9191 |
| Error | 0 | -0.0015 | -0.0082 | -0.0192 | -0.0126 | +0.0222 | +0.0357 | +0.0149 |
The formula is too low at medium angles and too high near grazing angles. The largest error is near 85°.
Other indices. The largest error over all angles depends on and is not monotone in it.
| Material | Largest error | At | ||
|---|---|---|---|---|
| Water | 1.33 | 0.020 | 0.0599 | 83.8° |
| Glass | 1.5 | 0.040 | 0.0357 | 85.0° |
| Dense flint glass | 2.0 | 0.111 | 0.0444 | 85.2° |
| Diamond | 2.4 | 0.170 | 0.0740 | 84.5° |
Inside glass. With the critical angle is . At 40° the exact reflectance is , while the plain formula with gives . With the transmitted cosine of lines L5 to L8 it gives , and past both give 1.
A metal. For the complex index , chosen as an example near aluminum in green light, . The exact reflectance falls to at before it rises to 1, while Schlick's curve only rises. The largest error is near 83°.
The hemispherical average. Weighted by the cosine, the average of the formula is , because . For glass this is ; the exact average is . Split sum and energy compensation tables use such averages.
All numbers on this page come from the code of this page, which tests the formula against the exact Fresnel equations for dielectrics and conductors.
Variations
- A grazing value other than 1. . Burley's diffuse term uses the same fifth power with for the roughness , which is a tuned shape, not a Fresnel factor.
- A spherical Gaussian power. Karis (2013) replaces by , a fit that is cheaper on some hardware. The two weights differ by at most , near .
- Tinted metals. as an RGB color in linear space, with the base color of a metal used as in metal-rough workflows.
- Per-lobe use. The Disney principled BRDF uses the fifth power for the specular , for the sheen and for the clear coat with .
- Corrections for metals. An extra term that is zero at and , such as a multiple of , can make the curve dip like the exact one (Exercise 6). Its weight is a fit per material, so it is tuning.
Pitfalls
- The wrong cosine. In a microfacet BRDF, is (equal to ), not . For a rough surface, is often larger than at grazing view, so with the reflection there is usually too bright.
- Inside the medium. Without lines L5 to L8, a refractive object shows no total internal reflection. At 40° inside glass the error is .
- Gamma. is a reflectance in linear RGB. A value of 0.04 stored in an sRGB texture without decoding is a different number.
- Metals near 80°. The formula has no dip, so a metal looks slightly too bright near grazing angles. The error is about 0.09 for the example above.
- Rounding near . is small and the fifth power makes it tiny; this is fine, since the term then does not matter. Clamping to matters more, because a negative from interpolated normals gives a value above .
- Claims of accuracy. The error figures above are measurements against the exact Fresnel equations of a smooth interface. Real materials have coatings, oxides and dispersion, and the exact formula is itself a model.
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/schlick-fresnel-approximation/. The authors are listed in prov/W0ZH9M.jsonl.
"""Schlick's approximation of the Fresnel reflectance, and the exact Fresnel
equations that serve as its reference.
cos_i is the cosine of the angle between the incident direction and the
normal (for a microfacet BRDF, v.h). eta is the ratio n_t / n_i of the
refractive indices of the far side and the near side.
"""
import cmath
import math
def f0_from_ior(eta: float) -> float:
"""Reflectance at normal incidence, ((eta - 1) / (eta + 1))^2."""
return ((eta - 1.0) / (eta + 1.0)) ** 2
def schlick(cos_i: float, f0: float, f90: float = 1.0) -> float:
"""F = f0 + (f90 - f0) (1 - cos_i)^5."""
c = min(1.0, max(0.0, cos_i)) # @line L1
m = 1.0 - c # @line L2
return f0 + (f90 - f0) * (m * m) * (m * m) * m # @line L3
def schlick_dielectric(cos_i: float, eta: float) -> float:
"""Schlick for a dielectric on either side of the interface.
When light leaves the denser medium (eta < 1), the cosine of the
transmitted angle replaces cos_i, and past the critical angle the
reflectance is 1 (total internal reflection).
"""
f0 = f0_from_ior(eta) # @line L4
c = min(1.0, max(0.0, cos_i))
if eta < 1.0: # @line L5
sin2_t = (1.0 - c * c) / (eta * eta) # @line L6
if sin2_t >= 1.0: # @line L7
return 1.0
c = math.sqrt(1.0 - sin2_t) # @line L8
return schlick(c, f0) # @line L9
def fresnel_dielectric(cos_i: float, eta: float) -> float:
"""Exact unpolarized Fresnel reflectance of a dielectric interface."""
c = min(1.0, max(0.0, cos_i))
sin2_t = (1.0 - c * c) / (eta * eta)
if sin2_t >= 1.0:
return 1.0
ct = math.sqrt(1.0 - sin2_t)
rs = (c - eta * ct) / (c + eta * ct)
rp = (eta * c - ct) / (eta * c + ct)
return 0.5 * (rs * rs + rp * rp)
def fresnel_conductor(cos_i: float, n: float, k: float) -> float:
"""Exact unpolarized Fresnel reflectance for the complex index n + i k,
seen from a medium of index 1."""
c = min(1.0, max(0.0, cos_i))
eta = complex(n, k)
s2 = 1.0 - c * c
ct = cmath.sqrt(1.0 - s2 / (eta * eta))
rs = (c - eta * ct) / (c + eta * ct)
rp = (eta * c - ct) / (eta * c + ct)
return 0.5 * (abs(rs) ** 2 + abs(rp) ** 2)
def f0_conductor(n: float, k: float) -> float:
"""((n - 1)^2 + k^2) / ((n + 1)^2 + k^2)."""
return ((n - 1.0) ** 2 + k * k) / ((n + 1.0) ** 2 + k * k)
test_schlick_fresnel_approximation.py 114 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/schlick-fresnel-approximation/. The authors are listed in prov/W0ZH9M.jsonl.
"""Tests of Schlick's approximation against the exact Fresnel equations."""
import math
import random
from schlick_fresnel_approximation import (
f0_conductor,
f0_from_ior,
fresnel_conductor,
fresnel_dielectric,
schlick,
schlick_dielectric,
)
def cosd(deg: float) -> float:
return math.cos(math.radians(deg))
def worst(f, g, steps: int = 20000) -> tuple[float, float]:
"""The largest |f - g| over theta in [0, 90] degrees, and where it is."""
best = (0.0, 0.0)
for i in range(steps + 1):
t = i * (math.pi / 2.0) / steps
e = abs(f(math.cos(t)) - g(math.cos(t)))
if e > best[0]:
best = (e, math.degrees(t))
return best
def test_end_points() -> None:
rng = random.Random(1)
for _ in range(200):
eta = rng.uniform(1.01, 3.0)
f0 = f0_from_ior(eta)
assert abs(schlick(1.0, f0) - f0) < 1e-15
assert abs(fresnel_dielectric(1.0, eta) - f0) < 1e-12
assert schlick(0.0, f0) == 1.0
assert abs(fresnel_dielectric(0.0, eta) - 1.0) < 1e-12
f90 = rng.uniform(0.0, 1.0)
assert abs(schlick(0.0, f0, f90) - f90) < 1e-15
def test_monotone_and_range() -> None:
rng = random.Random(2)
for _ in range(100):
f0 = rng.uniform(0.0, 1.0)
prev = schlick(1.0, f0)
for i in range(999, -1, -1):
cur = schlick(i / 1000.0, f0)
assert f0 - 1e-15 <= cur <= 1.0
assert cur >= prev - 1e-15
prev = cur
def test_page_values_glass() -> None:
f0 = f0_from_ior(1.5)
assert abs(f0 - 0.04) < 1e-15
table = {30.0: -0.00148, 45.0: -0.00817, 60.0: -0.01919, 80.0: 0.02221, 85.0: 0.03569}
for deg, err in table.items():
assert abs((schlick(cosd(deg), f0) - fresnel_dielectric(cosd(deg), 1.5)) - err) < 1e-5
assert abs(fresnel_dielectric(cosd(85.0), 1.5) - 0.6128) < 5e-5
def test_worst_error_by_ior() -> None:
expected = {1.33: (0.0599, 83.8), 1.5: (0.0357, 85.0), 2.0: (0.0444, 85.2), 2.4: (0.0740, 84.5)}
for eta, (err, deg) in expected.items():
f0 = f0_from_ior(eta)
e, at = worst(lambda c: schlick(c, f0), lambda c: fresnel_dielectric(c, eta))
assert abs(e - err) < 5e-4
assert abs(at - deg) < 0.2
def test_inside_the_denser_medium() -> None:
eta = 1.0 / 1.5
crit = math.degrees(math.asin(eta))
assert abs(crit - 41.81) < 0.01
# Plain Schlick with cos_i misses total internal reflection.
assert abs(fresnel_dielectric(cosd(40.0), eta) - 0.2453) < 5e-5
assert abs(schlick(cosd(40.0), 0.04) - 0.0407) < 5e-5
assert fresnel_dielectric(cosd(42.0), eta) == 1.0
assert schlick_dielectric(cosd(42.0), eta) == 1.0
# With cos_t the error is the same as outside, because R(theta_i, eta) = R(theta_t, 1 / eta).
e_in, _ = worst(lambda c: schlick_dielectric(c, eta), lambda c: fresnel_dielectric(c, eta))
e_out, _ = worst(lambda c: schlick(c, 0.04), lambda c: fresnel_dielectric(c, 1.5))
assert abs(e_in - e_out) < 1e-4
def test_reciprocity_of_exact_fresnel() -> None:
rng = random.Random(3)
for _ in range(500):
eta = rng.uniform(1.05, 2.5)
ti = rng.uniform(0.0, math.pi / 2.0)
st = math.sin(ti) / eta
tt = math.asin(st)
assert abs(fresnel_dielectric(math.cos(ti), eta) - fresnel_dielectric(math.cos(tt), 1.0 / eta)) < 1e-12
def test_conductor() -> None:
n, k = 1.0, 6.7
f0 = f0_conductor(n, k)
assert abs(f0 - 0.9182) < 5e-5
assert abs(fresnel_conductor(1.0, n, k) - f0) < 1e-12
# The exact curve dips below f0 near 81 degrees; Schlick only rises.
low, at = min((fresnel_conductor(math.cos(math.radians(d / 100.0)), n, k), d / 100.0) for d in range(9001))
assert abs(low - 0.8627) < 5e-5 and abs(at - 80.92) < 0.05
e, at = worst(lambda c: schlick(c, f0), lambda c: fresnel_conductor(c, n, k))
assert abs(e - 0.0947) < 5e-4 and abs(at - 83.1) < 0.2
# A dielectric index with k = 0 gives the dielectric formula.
for deg in (0.0, 30.0, 60.0, 85.0):
assert abs(fresnel_conductor(cosd(deg), 1.5, 0.0) - fresnel_dielectric(cosd(deg), 1.5)) < 1e-12
Exercises
- Show that is monotone in and that for .
- Prove that , and compute the cosine-weighted average of the formula for water.
- Invert to get from . What gives , the upper end of the Disney specular parameter?
- Prove that the exact unpolarized reflectance satisfies , and explain why this makes lines L5 to L8 have the same error as the outside case.
- Find the angle where the exact reflectance of glass equals Schlick's value, between 70° and 80°.
- For the index , plot the exact reflectance and the formula, and find a constant such that reduces the largest error.
Proof: Properties of Schlick's Fresnel approximationfull
Setting. Lines L1 to L3 compute for clamped to . Lines L4 to L9 compute and, for , replace by the transmitted cosine or return 1. The reference is the exact unpolarized reflectance of a smooth dielectric interface, with and , where . The claims are about these formulas in exact arithmetic. The size of the error between the two in the middle of the range is a measurement, made on a grid by the tests.
Claim 1 (end points). and . For and , these equal the exact values and .
Proof. At , ; at it is 1. For the exact formula at , , so and , and . At , and , so .
Claim 2 (monotone and bounded). If , is decreasing in on and .
Proof. decreases from 1 to 0 on , and . So is a convex combination of and with a weight that decreases in .
Claim 3 (the symmetry used by lines L5 to L8). Let , let and let be given by . Then .
Proof. From inside, the incident cosine is and the index ratio is ; the transmitted cosine is then , by Snell's law. So the inside amplitudes are , after multiplying the numerator and the denominator by , and in the same way . Squares do not see the sign.
Claim 4 (lines L5 to L8 are correct). For and the incident cosine inside, line L7 returns 1 exactly when the exact reflectance is 1 (total internal reflection), and otherwise line L9 returns with , which is the outside approximation at the outside angle. So the inside error equals the outside error at the matching angle.
Proof. , by dividing by . The value is of the transmitted angle, and it is at least 1 exactly when there is no transmitted ray, where the exact is 1. Otherwise is the cosine of the outside angle, and Claim 3 says that the exact inside value is the exact outside value at that angle.
Claim 5 (the cosine-weighted average). .
Proof. , and .
Conductors. The test also compares with the exact reflectance for a complex index . Claim 1 holds there for , but Claim 2 does not hold for the exact curve, which falls below before it rises. The size of that dip and of the error is a measurement on a grid.
What the tests check. Claims 1 and 2 at random inputs, Claim 3 at 500 random angles and indices, Claim 4 by comparing the largest inside and outside errors, and the page values against the exact formulas.
References
- Christophe Schlick, An inexpensive BRDF model for physically-based rendering, Computer Graphics Forum 13(3), 1994, 233 to 246, the approximation of the Fresnel factor by a fifth power of (1 - cos theta) (general locator)
- Brian Karis, Real shading in Unreal Engine 4, course notes, SIGGRAPH 2013 course Physically Based Shading in Theory and Practice, the section Specular F, Equation 5 (Schlick's form with a spherical Gaussian in place of the fifth power)
- 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.5, Specular F details (Schlick with the angle theta_d between l and h), and Section 5.3 for the diffuse term with the same fifth power
- Matt Pharr, Wenzel Jakob and Greg Humphreys, Physically Based Rendering, From Theory to Implementation, third edition, Morgan Kaufmann, 2016, Section 8.2.1, Fresnel Reflectance (the exact formulas for dielectrics and conductors that serve as the reference here)
- Tomas Akenine-Möller, Eric Haines, Naty Hoffman, Angelo Pesce, Michał Iwanicki and Sébastien Hillaire, Real-Time Rendering, fourth edition, CRC Press, 2018, Chapter 9, Physically Based Shading (the section on Fresnel reflectance and the Schlick approximation)
Where this leads
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 | W2 basic |
|
Tag W0ZH9M Edit this page History Report an error Markdown