Skip to content

Commit

Permalink
fix: sheen
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhhkrx committed Dec 11, 2024
1 parent b9874f2 commit a794dc6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
7 changes: 3 additions & 4 deletions packages/shaderlab/src/shaders/shadingPBR/BRDF.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ struct BRDFData{
#ifdef MATERIAL_ENABLE_SHEEN
float sheenRoughness;
float sheenScaling;
float IBLsheenDFG;
#endif

};
Expand Down Expand Up @@ -372,10 +373,8 @@ void initBRDFData(SurfaceData surfaceData, out BRDFData brdfData){

#ifdef MATERIAL_ENABLE_SHEEN
brdfData.sheenRoughness = max(MIN_PERCEPTUAL_ROUGHNESS, min(surfaceData.sheenRoughness + getAARoughnessFactor(surfaceData.normal), 1.0));
// sheen energy compensation approximation calculation in ‘Sheen DFG LUT integrated over diffuse IBL’
// https://drive.google.com/file/d/1T0D1VSyR4AllqIJTQAraEIzjlb5h4FKH/view?usp=sharing
float IBLSheenDFG = IBLSheenDFG(surfaceData, brdfData.sheenRoughness);
brdfData.sheenScaling = 1.0 - IBLSheenDFG * max(max(surfaceData.sheenColor.r, surfaceData.sheenColor.g), surfaceData.sheenColor.b);
brdfData.IBLsheenDFG = IBLSheenDFG(surfaceData, brdfData.sheenRoughness);
brdfData.sheenScaling = 1.0 - brdfData.IBLsheenDFG * max(max(surfaceData.sheenColor.r, surfaceData.sheenColor.g), surfaceData.sheenColor.b);
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define FUNCTION_CLEAR_COAT_LOBE clearCoatLobe
#endif
#ifndef FUNCTION_SHEEN_LOBE
#define FUNCTION_SHEEN_LOBE SheenLobe
#define FUNCTION_SHEEN_LOBE sheenLobe
#endif

#include "BRDF.glsl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ vec3 getLightProbeRadiance(SurfaceData surfaceData, vec3 normal, float roughness
// This is a curve-fit approxmation to the "Charlie sheen" BRDF integrated over the hemisphere from
// Estevez and Kulla 2017, "Production Friendly Microfacet Sheen BRDF". The analysis can be found
// in the Sheen section of https://drive.google.com/file/d/1T0D1VSyR4AllqIJTQAraEIzjlb5h4FKH/view?usp=sharing
float IBLSheenDFG(SurfaceData surfaceData, float roughness) {
float IBLSheenDFG(SurfaceData surfaceData, float sheenRoughness) {
float dotNV = surfaceData.dotNV;
float r2 = roughness * roughness;
float a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;
float b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;
float DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );
float r2 = sheenRoughness * sheenRoughness;
float a = sheenRoughness < 0.25 ? -339.2 * r2 + 161.4 * sheenRoughness - 25.9 : -8.48 * r2 + 14.3 * sheenRoughness - 9.95;
float b = sheenRoughness < 0.25 ? 44.0 * r2 - 23.7 * sheenRoughness + 3.26 : 1.97 * r2 - 3.27 * sheenRoughness + 0.72;
float DG = exp( a * dotNV + b ) + ( sheenRoughness < 0.25 ? 0.0 : 0.1 * ( sheenRoughness - 0.25 ) );
return saturate( DG * RECIPROCAL_PI );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void evaluateSheenIBL(Varyings varyings, SurfaceData surfaceData, BRDFData brdfD
diffuseColor *= brdfData.sheenScaling;
specularColor *= brdfData.sheenScaling;

vec3 reflectance = radianceAttenuation * IBLSheenDFG(surfaceData, brdfData.sheenRoughness) * surfaceData.sheenColor;
vec3 reflectance = radianceAttenuation * brdfData.IBLsheenDFG * surfaceData.sheenColor;
specularColor += reflectance;
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void specularLobe(Varyings varyings, SurfaceData surfaceData, BRDFData brdfData,
specularColor += attenuationIrradiance * BRDF_Specular_GGX( incidentDirection, surfaceData, brdfData, surfaceData.normal, brdfData.specularColor, brdfData.roughness);
}

void SheenLobe(Varyings varyings, SurfaceData surfaceData, BRDFData brdfData, vec3 incidentDirection, vec3 attenuationIrradiance, inout vec3 diffuseColor, inout vec3 specularColor){
void sheenLobe(Varyings varyings, SurfaceData surfaceData, BRDFData brdfData, vec3 incidentDirection, vec3 attenuationIrradiance, inout vec3 diffuseColor, inout vec3 specularColor){
#ifdef MATERIAL_ENABLE_SHEEN
diffuseColor *= brdfData.sheenScaling;
specularColor *= brdfData.sheenScaling;
Expand Down

0 comments on commit a794dc6

Please sign in to comment.