lygia
/lighting
/specular
/cookTorrance
)Dependencies:
lygia
/lighting
/common
/ggx
.glsl
lygia
/lighting
/common
/smithGGXCorrelated
.glsl
lygia
/math
/saturate
.glsl
lygia
/math
/saturateMediump
.glsl
lygia
/lighting
/fresnel
.glsl
#ifndef FNC_SPECULAR_COOKTORRANCE
#define FNC_SPECULAR_COOKTORRANCE
vec3 specularCookTorrance(const in vec3 L, const in vec3 N, const in vec3 H, const in float NoV, const in float NoL, const in float NoH, const in float linearRoughness, const in vec3 specularColor) {
float LoH = saturate(dot(L, H));
float D = GGX(N, H, NoH, linearRoughness);
#if defined(PLATFORM_RPI)
float V = smithGGXCorrelated_Fast(NoV, NoL, linearRoughness);
#else
float V = smithGGXCorrelated(NoV, NoL,linearRoughness);
#endif
vec3 F = fresnel(specularColor, LoH);
return (D * V) * F;
}
vec3 specularCookTorrance(ShadingData shadingData){
return specularCookTorrance(shadingData.L, shadingData.N, shadingData.H, shadingData.NoV, shadingData.NoL, shadingData.NoH, shadingData.linearRoughness, shadingData.specularColor);
}
#endif
Dependencies:
lygia
/lighting
/common
/ggx
.glsl
lygia
/lighting
/common
/smithGGXCorrelated
.glsl
lygia
/math
/saturateMediump
.glsl
lygia
/lighting
/fresnel
.glsl
#ifndef FNC_SPECULAR_COOKTORRANCE
#define FNC_SPECULAR_COOKTORRANCE
float3 specularCookTorrance(float3 L, float3 N, const in float3 H, float NoV, float NoL, const in float NoH, float linearRoughness, float3 specularColor) {
float LoH = saturate(dot(L, H));
float D = GGX(N, H, NoH, linearRoughness);
#if defined(PLATFORM_RPI)
float V = smithGGXCorrelated_Fast(NoV, NoL, linearRoughness);
#else
float V = smithGGXCorrelated(NoV, NoL, linearRoughness);
#endif
float3 F = fresnel(specularColor, LoH);
return (D * V) * F;
}
float3 specularCookTorrance(ShadingData shadingData){
return specularCookTorrance(shadingData.L, shadingData.N, shadingData.H, shadingData.NoV, shadingData.NoL, shadingData.NoH, shadingData.linearRoughness, shadingData.specularColor);
}
#endif
Dependencies:
fn specularCookTorrance(L: vec3f, N: vec3f, V: vec3f, NoV: f32, NoL: f32, roughness: f32, fresnel: f32) -> f32 {
// Half angle vector
let H = normalize(L + V);
// Geometric term
let NoH = max(dot(N, H), 0.0);
let VoH = max(dot(V, H), 0.000001);
let x = 2.0 * NoH / VoH;
let G = min(1.0, min(x * NoV, x * NoL));
// Distribution term
let D = GGX(N, H, NoH, roughness);
// Fresnel term
let F = pow(1.0 - NoV, fresnel);
// Multiply terms and done
return max(G * F * D / max(PI * NoV * NoL, 0.00001), 0.0);
}
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