lygia
/lighting
/light
/iblEvaluate
)Calculate indirect light
Dependencies:
lygia
/lighting
/envMap
.glsl
lygia
/lighting
/fresnelReflection
.glsl
lygia
/lighting
/sphericalHarmonics
.glsl
lygia
/lighting
/specular
/importanceSampling
.glsl
lygia
/lighting
/reflection
.glsl
lygia
/lighting
/common
/specularAO
.glsl
lygia
/lighting
/common
/envBRDFApprox
.glsl
lygia
/color
/tonemap
.glsl
Use:
void lightIBLEvaluate(<Material> mat, inout <ShadingData> shadingData)
#ifndef IBL_LUMINANCE
#define IBL_LUMINANCE 1.0
#endif
#ifndef FNC_LIGHT_IBL_EVALUATE
#define FNC_LIGHT_IBL_EVALUATE
void lightIBLEvaluate(Material mat, inout ShadingData shadingData) {
#if !defined(IBL_IMPORTANCE_SAMPLING) || __VERSION__ < 130 || defined(SCENE_SH_ARRAY)
vec2 E = envBRDFApprox(shadingData.NoV, shadingData.roughness);
vec3 specularColorE = shadingData.specularColor * E.x + E.y;
#endif
vec3 energyCompensation = vec3(1.0, 1.0, 1.0);
#if defined(IBL_IMPORTANCE_SAMPLING) && __VERSION__ >= 130
vec3 Fr = specularImportanceSampling(shadingData.linearRoughness, shadingData.specularColor,
mat.position, shadingData.N, shadingData.V, shadingData.R, shadingData.NoV, energyCompensation);
#else
vec3 R = mix(shadingData.R, shadingData.N, shadingData.roughness*shadingData.roughness);
vec3 Fr = envMap(R, shadingData.roughness, mat.metallic);
Fr *= specularColorE;
#endif
Fr *= energyCompensation;
#if !defined(PLATFORM_RPI) && defined(SHADING_MODEL_IRIDESCENCE)
Fr += fresnelReflection(mat, shadingData);
#endif
vec3 Fd = shadingData.diffuseColor;
#if defined(SCENE_SH_ARRAY)
#ifdef GLSLVIEWER
Fd *= tonemap(sphericalHarmonics(shadingData.N));
#else
Fd *= (sphericalHarmonics(shadingData.N));
#endif
#else
Fd *= envMap(shadingData.N, 1.0);
#endif
#if !defined(IBL_IMPORTANCE_SAMPLING)
Fd *= (1.0-specularColorE);
#endif
// AO
float diffuseAO = mat.ambientOcclusion;
Fd *= diffuseAO;
Fr *= specularAO(mat, shadingData, diffuseAO);
shadingData.energyCompensation = energyCompensation;
shadingData.indirectDiffuse = Fd * IBL_LUMINANCE;
shadingData.indirectSpecular = Fr * IBL_LUMINANCE;
}
#endif
Dependencies:
lygia
/lighting
/envMap
.glsl
lygia
/lighting
/fresnelReflection
.glsl
lygia
/lighting
/sphericalHarmonics
.glsl
lygia
/lighting
/specular
/importanceSampling
.glsl
lygia
/lighting
/reflection
.glsl
lygia
/lighting
/common
/specularAO
.glsl
lygia
/lighting
/common
/envBRDFApprox
.glsl
Use:
void lightIBLEvaluate(<Material> mat, inout <ShadingData> shadingData)
#ifndef IBL_LUMINANCE
#define IBL_LUMINANCE 1.0
#endif
#ifndef FNC_LIGHT_IBL_EVALUATE
#define FNC_LIGHT_IBL_EVALUATE
void lightIBLEvaluate(Material mat, inout ShadingData shadingData) {
#if !defined(IBL_IMPORTANCE_SAMPLING) || defined(SCENE_SH_ARRAY)
float2 E = envBRDFApprox(shadingData.NoV, shadingData.roughness);
float3 specularColorE = shadingData.specularColor * E.x + E.y;
#endif
float3 energyCompensation = float3(1.0, 1.0, 1.0);
#if defined(IBL_IMPORTANCE_SAMPLING)
float3 Fr = specularImportanceSampling(shadingData.linearRoughness, shadingData.specularColor,
mat.position, shadingData.N, shadingData.V, shadingData.R, shadingData.NoV, energyCompensation);
#else
float3 R = lerp(shadingData.R, shadingData.N, shadingData.roughness*shadingData.roughness);
float3 Fr = envMap(R, shadingData.roughness, mat.metallic);
Fr *= specularColorE;
#endif
Fr *= energyCompensation;
#if !defined(PLATFORM_RPI) && defined(SHADING_MODEL_IRIDESCENCE)
Fr += fresnelReflection(mat, shadingData);
#endif
#if defined(SCENE_SH_ARRAY)
float3 Fd = shadingData.diffuseColor * (1.0-specularColorE);
Fd *= sphericalHarmonics(shadingData.N);
#elif defined(IBL_IMPORTANCE_SAMPLING)
float3 Fd = shadingData.diffuseColor;
Fd *= envMap(shadingData.N, 1.0);
#else
float3 Fd = shadingData.diffuseColor * (1.0-specularColorE);
Fd *= envMap(shadingData.N, 1.0);
#endif
// AO
float diffuseAO = mat.ambientOcclusion;
Fd *= diffuseAO;
Fr *= specularAO(mat, shadingData, diffuseAO);
shadingData.energyCompensation = energyCompensation;
shadingData.indirectDiffuse = Fd * IBL_LUMINANCE;
shadingData.indirectSpecular = Fr * IBL_LUMINANCE;
}
#endif
MIT License (MIT) Copyright (c) 2024 Shadi El Hajj
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