gpu-curtains
Version:
gpu-curtains is a 3D WebGPU rendering engine. It can be used as a standalone 3D engine, but also includes extra classes focused on mapping 3d objects to DOM elements; It allows users to synchronize values such as position, sizing, or scale between them.
43 lines (34 loc) • 963 B
JavaScript
const BRDF_GGX = (
/* wgsl */
`
fn DistributionGGX(NdotH: f32, roughness: f32) -> f32 {
let a: f32 = pow2( roughness );
let a2: f32 = pow2( a );
let denom: f32 = (pow2( NdotH ) * (a2 - 1.0) + 1.0);
return RECIPROCAL_PI * a2 / ( pow2( denom ) );
}
fn GeometrySmith(NdotL: f32, NdotV: f32, roughness: f32) -> f32 {
let a: f32 = pow2( roughness );
let a2: f32 = pow2( a );
let gv: f32 = NdotL * sqrt( a2 + ( 1.0 - a2 ) * pow2( NdotV ) );
let gl: f32 = NdotV * sqrt( a2 + ( 1.0 - a2 ) * pow2( NdotL ) );
return 0.5 / max( gv + gl, EPSILON );
}
fn BRDF_GGX(
NdotV: f32,
NdotL: f32,
NdotH: f32,
VdotH: f32,
roughness: f32,
specularFactor: f32,
specularColor: vec3f
) -> vec3f {
// cook-torrance brdf
let G: f32 = GeometrySmith(NdotL, NdotV, roughness);
let D: f32 = DistributionGGX(NdotH, roughness);
let F: vec3f = F_Schlick(specularColor, specularFactor, VdotH);
return G * D * F;
}
`
);
export { BRDF_GGX };