UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

3 lines (2 loc) 1.15 kB
declare const _default: "\n// Isotropic GGX (glTF 2.0 compliant)\nfloat calcLightSpecular(float gloss, vec3 worldNormal, vec3 viewDir, vec3 h, vec3 lightDirNorm) {\n const float PI = 3.141592653589793;\n float roughness = max((1.0 - gloss) * (1.0 - gloss), 0.001);\n float alpha = roughness * roughness;\n\n float NoH = max(dot(worldNormal, h), 0.0);\n float NoV = max(dot(worldNormal, viewDir), 0.0);\n float NoL = max(dot(worldNormal, -lightDirNorm), 0.0);\n\n // GGX Distribution\n float NoH2 = NoH * NoH;\n float denom = NoH2 * (alpha - 1.0) + 1.0;\n float D = alpha / (PI * denom * denom);\n\n // Smith G (height-correlated)\n float alpha2 = alpha * alpha;\n float lambdaV = NoL * sqrt(NoV * NoV * (1.0 - alpha2) + alpha2);\n float lambdaL = NoV * sqrt(NoL * NoL * (1.0 - alpha2) + alpha2);\n float G = 0.5 / max(lambdaV + lambdaL, 0.00001);\n\n return D * G;\n}\n\nfloat getLightSpecular(vec3 h, vec3 reflDir, vec3 worldNormal, vec3 viewDir, vec3 lightDirNorm, float gloss, mat3 tbn) {\n return calcLightSpecular(gloss, worldNormal, viewDir, h, lightDirNorm);\n}\n"; export default _default;