Advanced search tips: use spaces to require multiple terms (AND), | for alternatives (OR), wrap phrases in quotes (="a b"), =term for exact match, 'term to include, !term to exclude, ^term to match prefix, !^term to exclude prefix, .ext$ to match suffix, and !.ext$ to exclude suffix.

pbr_lighting.wgsl

Import path

Functions

getDistanceAttenuation

#

light radius is a non-physical construct for efficiency purposes, because otherwise every light affects every fragment in the scene

fn getDistanceAttenuation (
distanceSquare: f32
inverseRangeSquared: f32
) -> f32

D_GGX

#

Simple implementation, has precision problems when using fp16 instead of fp32 see https://google.github.io/filament/Filament.html#listing_speculardfp16

fn D_GGX (
roughness: f32
NoH: f32
) -> f32

V_SmithGGXCorrelated

#

Visibility function (Specular G) V(v,l,a) = G(v,l,α) / { 4 (n⋅v) (n⋅l) } such that f_r becomes f_r(v,l) = D(h,α) V(v,l,α) F(v,h,f0) where V(v,l,α) = 0.5 / { n⋅l sqrt((n⋅v)^2 (1−α2) + α2) + n⋅v sqrt((n⋅l)^2 (1−α2) + α2) } Note the two sqrt’s, that may be slow on mobile, see https://google.github.io/filament/Filament.html#listing_approximatedspecularv

fn V_SmithGGXCorrelated (
roughness: f32
NoV: f32
NoL: f32
) -> f32

F_Schlick_vec

#

Fresnel function see https://google.github.io/filament/Filament.html#citation-schlick94 F_Schlick(v,h,f_0,f_90) = f_0 + (f_90 − f_0) (1 − v⋅h)^5

fn F_Schlick_vec (
f90: f32
VoH: f32
) -> vec3<f32>

F_Schlick

#
fn F_Schlick (
f90: f32
VoH: f32
) -> f32

fresnel

#
fn fresnel (
LoH: f32
) -> vec3<f32>

specular

#

Cook-Torrance approximation of the microfacet model integration using Fresnel law F to model f_m f_r(v,l) = { D(h,α) G(v,l,α) F(v,h,f0) } / { 4 (n⋅v) (n⋅l) }

fn specular (
roughness: f32
NoV: f32
NoL: f32
NoH: f32
LoH: f32
specularIntensity: f32
) -> vec3<f32>

Fd_Burley

#

Disney approximation See https://google.github.io/filament/Filament.html#citation-burley12 minimal quality difference

fn Fd_Burley (
roughness: f32
NoV: f32
NoL: f32
LoH: f32
) -> f32

EnvBRDFApprox

#
fn EnvBRDFApprox (
perceptual_roughness: f32
NoV: f32
) -> vec3<f32>

perceptualRoughnessToRoughness

#
fn perceptualRoughnessToRoughness (
perceptualRoughness: f32
) -> f32

reinhard

#

from https://64.github.io/tonemapping/ reinhard on RGB oversaturates colors

fn reinhard ( ) -> vec3<f32>

reinhard_extended

#
fn reinhard_extended (
max_white: f32
) -> vec3<f32>

luminance

#

luminance coefficients from Rec. 709. https://en.wikipedia.org/wiki/Rec._709

fn luminance ( ) -> f32

change_luminance

#
fn change_luminance (
l_out: f32
) -> vec3<f32>

reinhard_luminance

#
fn reinhard_luminance ( ) -> vec3<f32>

reinhard_extended_luminance

#
fn reinhard_extended_luminance (
max_white_l: f32
) -> vec3<f32>

point_light

#
fn point_light (
world_position: vec3<f32>
roughness: f32
NdotV: f32
diffuseColor: vec3<f32>
) -> vec3<f32>

spot_light

#
fn spot_light (
world_position: vec3<f32>
roughness: f32
NdotV: f32
diffuseColor: vec3<f32>
) -> vec3<f32>

directional_light

#
fn directional_light (
roughness: f32
NdotV: f32
diffuseColor: vec3<f32>
) -> vec3<f32>