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

Constants

LAYER_BASE

#
const LAYER_BASE: u32 = 0

LAYER_CLEARCOAT

#
const LAYER_CLEARCOAT: u32 = 1

Structures

LayerLightingInput

#

Input to a lighting function for a single layer (either the base layer or the clearcoat layer).

struct LayerLightingInput {
NdotV: f32 ,
perceptual_roughness: f32 ,
roughness: f32 ,
}

LightingInput

#

Input to a lighting function (point_light, spot_light, directional_light).

struct LightingInput {
layers: array<LayerLightingInput,2> , 🟢 STANDARD_MATERIAL_CLEARCOAT
layers: array<LayerLightingInput,1> , 🟢 STANDARD_MATERIAL_CLEARCOAT
diffuse_color: vec3<f32> ,
F_ab: vec2<f32> ,
clearcoat_strength: f32 , 🟢 STANDARD_MATERIAL_CLEARCOAT
anisotropy: f32 , 🟢 STANDARD_MATERIAL_ANISOTROPY
Ta: vec3<f32> , 🟢 STANDARD_MATERIAL_ANISOTROPY
Ba: vec3<f32> , 🟢 STANDARD_MATERIAL_ANISOTROPY
}

DerivedLightingInput

#

Values derived from the LightingInput for both diffuse and specular lights.

struct DerivedLightingInput {
NdotL: f32 ,
NdotH: f32 ,
LdotH: f32 ,
}

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
NdotH: f32
) -> f32

D_GGX_anisotropic

#
fn D_GGX_anisotropic (
NdotH: f32
TdotH: f32
BdotH: 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
NdotV: f32
NdotL: f32
) -> f32

V_GGX_anisotropic

#

The visibility function, anisotropic variant.

fn V_GGX_anisotropic (
NdotL: f32
NdotV: f32
BdotV: f32
TdotV: f32
TdotL: f32
BdotL: f32
) -> f32

V_Kelemen

#
fn V_Kelemen (
LdotH: 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
VdotH: f32
) -> vec3<f32>

F_Schlick

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

fresnel

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

specular_multiscatter

#
fn specular_multiscatter (
specular_intensity: f32
) -> vec3<f32>

derive_lighting_input

#

N, V, and L must all be normalized.

fn derive_lighting_input ( ) -> DerivedLightingInput

compute_specular_layer_values_for_point_light

#

Returns L in the xyz components and the specular intensity in the w component.

fn compute_specular_layer_values_for_point_light (
layer: u32
light_to_frag: vec3<f32>
light_position_radius: f32
) -> vec4<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 (
specular_intensity: f32
) -> vec3<f32>

specular_clearcoat

#
fn specular_clearcoat (
clearcoat_strength: f32
specular_intensity: f32
) -> vec2<f32>

specular_anisotropy

#

Shader defs requirments:

🟢 STANDARD_MATERIAL_ANISOTROPY

fn specular_anisotropy (
specular_intensity: f32
) -> vec3<f32>

Fd_Burley

#

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

F_AB

#
fn F_AB (
perceptual_roughness: f32
NdotV: f32
) -> vec2<f32>

EnvBRDFApprox

#
fn EnvBRDFApprox ( ) -> vec3<f32>

perceptualRoughnessToRoughness

#
fn perceptualRoughnessToRoughness (
perceptualRoughness: f32
) -> f32

point_light

#
fn point_light (
light_id: u32
enable_diffuse: bool
) -> vec3<f32>

spot_light

#
fn spot_light (
light_id: u32
enable_diffuse: bool
) -> vec3<f32>

directional_light

#
fn directional_light (
light_id: u32
enable_diffuse: bool
) -> vec3<f32>