lygia
/lighting
/common
/smithGGXCorrelated
)Dependencies:
lygia
/math
/saturateMediump
.glsl
#ifndef FNC_SMITH_GGX_CORRELATED
#define FNC_SMITH_GGX_CORRELATED
float smithGGXCorrelated(const in float NoV, const in float NoL, const in float roughness) {
// Heitz 2014, "Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs"
float a2 = roughness * roughness;
// TODO: lambdaV can be pre-computed for all the lights, it should be moved out of this function
float lambdaV = NoL * sqrt((NoV - a2 * NoV) * NoV + a2);
float lambdaL = NoV * sqrt((NoL - a2 * NoL) * NoL + a2);
float v = 0.5 / (lambdaV + lambdaL);
// a2=0 => v = 1 / 4*NoL*NoV => min=1/4, max=+inf
// a2=1 => v = 1 / 2*(NoL+NoV) => min=1/4, max=+inf
// clamp to the maximum value representable in mediump
return saturateMediump(v);
}
float smithGGXCorrelated_Fast(const in float NoV, const in float NoL, const in float roughness) {
// Hammon 2017, "PBR Diffuse Lighting for GGX+Smith Microsurfaces"
float v = 0.5 / mix(2.0 * NoL * NoV, NoL + NoV, roughness);
return saturateMediump(v);
}
#endif
Dependencies:
lygia
/math
/saturateMediump
.glsl
#ifndef FNC_SMITH_GGX_CORRELATED
#define FNC_SMITH_GGX_CORRELATED
float smithGGXCorrelated(float NoV, float NoL, float roughness) {
// Heitz 2014, "Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs"
float a2 = roughness * roughness;
// TODO: lambdaV can be pre-computed for all the lights, it should be moved out of this function
float lambdaV = NoL * sqrt((NoV - a2 * NoV) * NoV + a2);
float lambdaL = NoV * sqrt((NoL - a2 * NoL) * NoL + a2);
float v = 0.5 / (lambdaV + lambdaL);
// a2=0 => v = 1 / 4*NoL*NoV => min=1/4, max=+inf
// a2=1 => v = 1 / 2*(NoL+NoV) => min=1/4, max=+inf
// clamp to the maximum value representable in mediump
return saturateMediump(v);
}
float smithGGXCorrelated_Fast(float NoV, float NoL, float roughness) {
// Hammon 2017, "PBR Diffuse Lighting for GGX+Smith Microsurfaces"
float v = 0.5 / lerp(2.0 * NoL * NoV, NoL + NoV, roughness);
return saturateMediump(v);
}
#endif
LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.
Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).
It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository