playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
3 lines (2 loc) • 1.21 kB
TypeScript
declare const _default: "\n// Isotropic GGX (glTF 2.0 compliant)\nfn calcLightSpecular(gloss: f32, worldNormal: vec3f, viewDir: vec3f, h: vec3f, lightDirNorm: vec3f) -> f32 {\n const PI: f32 = 3.141592653589793;\n let roughness: f32 = max((1.0 - gloss) * (1.0 - gloss), 0.001);\n let alpha: f32 = roughness * roughness;\n\n let NoH: f32 = max(dot(worldNormal, h), 0.0);\n let NoV: f32 = max(dot(worldNormal, viewDir), 0.0);\n let NoL: f32 = max(dot(worldNormal, -lightDirNorm), 0.0);\n\n // GGX Distribution\n let NoH2: f32 = NoH * NoH;\n let denom: f32 = NoH2 * (alpha - 1.0) + 1.0;\n let D: f32 = alpha / (PI * denom * denom);\n\n // Smith G (height-correlated)\n let alpha2: f32 = alpha * alpha;\n let lambdaV: f32 = NoL * sqrt(NoV * NoV * (1.0 - alpha2) + alpha2);\n let lambdaL: f32 = NoV * sqrt(NoL * NoL * (1.0 - alpha2) + alpha2);\n let G: f32 = 0.5 / max(lambdaV + lambdaL, 0.00001);\n\n return D * G;\n}\n\nfn getLightSpecular(h: vec3f, reflDir: vec3f, worldNormal: vec3f, viewDir: vec3f, lightDirNorm: vec3f, gloss: f32, tbn: mat3x3f) -> f32 {\n return calcLightSpecular(gloss, worldNormal, viewDir, h, lightDirNorm);\n}\n";
export default _default;