Skip to content

Commit

Permalink
Merge pull request #543 from KhronosGroup/fix/albedoSheenScaling
Browse files Browse the repository at this point in the history
Fix/albedo sheen scaling
  • Loading branch information
UX3D-kanzler authored Apr 26, 2024
2 parents 6bc1df9 + 7e60926 commit 73ca73b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion source/Renderer/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ class gltfRenderer
textureCount = this.applyEnvironmentMap(state, textureCount);
}

if (state.renderingParameters.usePunctual && state.environment !== undefined)
if (state.environment !== undefined)
{
this.webGl.setTexture(this.shader.getUniformLocation("u_SheenELUT"), state.environment, state.environment.sheenELUT, textureCount++);
}
Expand Down
31 changes: 19 additions & 12 deletions source/Renderer/shaders/pbr.frag
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ void main()

#ifdef MATERIAL_SHEEN
f_sheen += getIBLRadianceCharlie(n, v, materialInfo.sheenRoughnessFactor, materialInfo.sheenColorFactor);
albedoSheenScaling = 1.0 - max3(materialInfo.sheenColorFactor) * albedoSheenScalingLUT(NdotV, materialInfo.sheenRoughnessFactor);
#endif
#endif

Expand Down Expand Up @@ -204,22 +205,28 @@ void main()
// Calculation of analytical light
// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#acknowledgments AppendixB
vec3 intensity = getLighIntensity(light, pointToLight);
vec3 l_diffuse = vec3(0.0);
vec3 l_specular = vec3(0.0);
#ifdef MATERIAL_IRIDESCENCE
f_diffuse += intensity * NdotL * BRDF_lambertianIridescence(materialInfo.f0, materialInfo.f90, iridescenceFresnel, materialInfo.iridescenceFactor, materialInfo.c_diff, materialInfo.specularWeight, VdotH);
f_specular += intensity * NdotL * BRDF_specularGGXIridescence(materialInfo.f0, materialInfo.f90, iridescenceFresnel, materialInfo.alphaRoughness, materialInfo.iridescenceFactor, materialInfo.specularWeight, VdotH, NdotL, NdotV, NdotH);
l_diffuse += intensity * NdotL * BRDF_lambertianIridescence(materialInfo.f0, materialInfo.f90, iridescenceFresnel, materialInfo.iridescenceFactor, materialInfo.c_diff, materialInfo.specularWeight, VdotH);
l_specular += intensity * NdotL * BRDF_specularGGXIridescence(materialInfo.f0, materialInfo.f90, iridescenceFresnel, materialInfo.alphaRoughness, materialInfo.iridescenceFactor, materialInfo.specularWeight, VdotH, NdotL, NdotV, NdotH);
#elif defined(MATERIAL_ANISOTROPY)
f_diffuse += intensity * NdotL * BRDF_lambertian(materialInfo.f0, materialInfo.f90, materialInfo.c_diff, materialInfo.specularWeight, VdotH);
f_specular += intensity * NdotL * BRDF_specularGGXAnisotropy(materialInfo.f0, materialInfo.f90, materialInfo.alphaRoughness, materialInfo.anisotropyStrength, n, v, l, h, materialInfo.anisotropicT, materialInfo.anisotropicB);
l_diffuse += intensity * NdotL * BRDF_lambertian(materialInfo.f0, materialInfo.f90, materialInfo.c_diff, materialInfo.specularWeight, VdotH);
l_specular += intensity * NdotL * BRDF_specularGGXAnisotropy(materialInfo.f0, materialInfo.f90, materialInfo.alphaRoughness, materialInfo.anisotropyStrength, n, v, l, h, materialInfo.anisotropicT, materialInfo.anisotropicB);
#else
f_diffuse += intensity * NdotL * BRDF_lambertian(materialInfo.f0, materialInfo.f90, materialInfo.c_diff, materialInfo.specularWeight, VdotH);
f_specular += intensity * NdotL * BRDF_specularGGX(materialInfo.f0, materialInfo.f90, materialInfo.alphaRoughness, materialInfo.specularWeight, VdotH, NdotL, NdotV, NdotH);
l_diffuse += intensity * NdotL * BRDF_lambertian(materialInfo.f0, materialInfo.f90, materialInfo.c_diff, materialInfo.specularWeight, VdotH);
l_specular += intensity * NdotL * BRDF_specularGGX(materialInfo.f0, materialInfo.f90, materialInfo.alphaRoughness, materialInfo.specularWeight, VdotH, NdotL, NdotV, NdotH);
#endif

#ifdef MATERIAL_SHEEN
f_sheen += intensity * getPunctualRadianceSheen(materialInfo.sheenColorFactor, materialInfo.sheenRoughnessFactor, NdotL, NdotV, NdotH);
albedoSheenScaling = min(1.0 - max3(materialInfo.sheenColorFactor) * albedoSheenScalingLUT(NdotV, materialInfo.sheenRoughnessFactor),
float l_albedoSheenScaling = min(1.0 - max3(materialInfo.sheenColorFactor) * albedoSheenScalingLUT(NdotV, materialInfo.sheenRoughnessFactor),
1.0 - max3(materialInfo.sheenColorFactor) * albedoSheenScalingLUT(NdotL, materialInfo.sheenRoughnessFactor));
l_diffuse *= l_albedoSheenScaling;
l_specular *= l_albedoSheenScaling;
#endif
f_diffuse += l_diffuse;
f_specular += l_specular;

#ifdef MATERIAL_CLEARCOAT
f_clearcoat += intensity * getPunctualRadianceClearCoat(materialInfo.clearcoatNormal, v, l, h, VdotH,
Expand Down Expand Up @@ -268,14 +275,14 @@ void main()
// Apply optional PBR terms for additional (optional) shading
#ifdef HAS_OCCLUSION_MAP
ao = texture(u_OcclusionSampler, getOcclusionUV()).r;
diffuse = f_diffuse + mix(f_diffuse_ibl, f_diffuse_ibl * ao, u_OcclusionStrength);
diffuse = f_diffuse + mix(f_diffuse_ibl, f_diffuse_ibl * ao, u_OcclusionStrength) * albedoSheenScaling;
// apply ambient occlusion to all lighting that is not punctual
specular = f_specular + mix(f_specular_ibl, f_specular_ibl * ao, u_OcclusionStrength);
specular = f_specular + mix(f_specular_ibl, f_specular_ibl * ao, u_OcclusionStrength) * albedoSheenScaling;
sheen = f_sheen + mix(f_sheen_ibl, f_sheen_ibl * ao, u_OcclusionStrength);
clearcoat = f_clearcoat + mix(f_clearcoat_ibl, f_clearcoat_ibl * ao, u_OcclusionStrength);
#else
diffuse = f_diffuse_ibl + f_diffuse;
specular = f_specular_ibl + f_specular;
diffuse = f_diffuse_ibl * albedoSheenScaling + f_diffuse;
specular = f_specular_ibl * albedoSheenScaling + f_specular;
sheen = f_sheen_ibl + f_sheen;
clearcoat = f_clearcoat_ibl + f_clearcoat;
#endif
Expand All @@ -295,7 +302,7 @@ void main()
color = baseColor.rgb;
#else
color = f_emissive + diffuse + specular;
color = sheen + color * albedoSheenScaling;
color = sheen + color;
color = color * (1.0 - clearcoatFactor * clearcoatFresnel) + clearcoat;
#endif

Expand Down

0 comments on commit 73ca73b

Please sign in to comment.