Anisotropic GGX squares roughness twice, making KHR_materials_anisotropy lobes far too tight
lightSpecularAnisoGGX converts gloss to roughness twice. Anisotropic GGX lobes are therefore much tighter than KHR_materials_anisotropy specifies, and a material with an anisotropy of 0 does not match the isotropic GGX chunk.
Where
- GLSL: https://github.com/playcanvas/engine/blob/de3a8d4f909e3198c9f5dc14ec72f2aabdd334a3/src/scene/shader-lib/glsl/chunks/lit/frag/lightSpecularAnisoGGX.js#L5-L11
- WGSL: https://github.com/playcanvas/engine/blob/de3a8d4f909e3198c9f5dc14ec72f2aabdd334a3/src/scene/shader-lib/wgsl/chunks/lit/frag/lightSpecularAnisoGGX.js#L5-L11
What's wrong
With gloss = 1 - perceptualRoughness (the glTF parser sets glossInvert), roughness = (1 - gloss)^2 is already the spec's alphaRoughness. The chunk then squares it again:
float roughness = max((1.0 - gloss) * (1.0 - gloss), 0.001); // already alphaRoughness
float alphaRoughness = roughness * roughness; // perceptualRoughness^4
...
float at = mix(alphaRoughness, 1.0, anisotropy * anisotropy);
float ab = clamp(alphaRoughness, 0.001, 1.0);The reference BRDF_specularGGXAnisotropy computes at / ab in the same way, but from alphaRoughness = perceptualRoughness^2. Both the D and the V terms use at / ab directly, so both are affected. This was introduced in #7668; before that the chunk used roughness directly.
Impact
With an anisotropy of 0, the anisotropic D should reduce to isotropic GGX. Compared with the glTF reference D, which lightSpecularGGX matches:
| Perceptual roughness | Peak (NoH = 1) | D at NoH = 0.99, engine / reference |
|---|---|---|
| 0.3 | 124x too high | 0.052 / 3.327 |
| 0.5 | 16x too high | 2.208 / 3.021 |
| 0.7 | 4.2x too high | 3.144 / 1.173 |
Punctual highlights on anisotropic materials are far too small and intense. Because any anisotropyIntensity > 0 switches a GGX material to this chunk, a tiny amount of anisotropy visibly changes the highlight. This may also explain the "strange sharp line" from the directional light discussed in #7698.
Fix
float alphaRoughness = max((1.0 - gloss) * (1.0 - gloss), 0.001);Apply the WGSL equivalent too. With that change, a transliteration of the chunk at an anisotropy of 0 matches the isotropic reference exactly.
Related: anisotropic reflections
reflDirAniso bends the reflection normal using roughness = sqrt(1.0 - gloss), which is sqrt(perceptualRoughness). The reference getIBLRadianceAnisotropy is called with perceptualRoughness itself, so glossy anisotropic materials get less bending than they should. This is worth correcting at the same time (GLSL and WGSL).
Both changes can be checked with the Khronos anisotropy test models already in examples/assets/models (AnisotropyStrengthTest, AnisotropyRotationTest, AnisotropyDiscTest, AnisotropyBarnLamp) against the Khronos Sample Viewer.
Found while investigating #4260 (specular anti-aliasing).
Source: playcanvas/engine