Skip to content

Commit b0cd8c8

Browse files
authored
WebGLRenderer/WebGPURenderer: Improve Physical Accuracy (#32330)
1 parent 2c50dc2 commit b0cd8c8

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const V_GGX_SmithCorrelated_Anisotropic = /*@__PURE__*/ Fn( ( { alphaT, alphaB,
99
const gl = dotNV.mul( vec3( alphaT.mul( dotTL ), alphaB.mul( dotBL ), dotNL ).length() );
1010
const v = div( 0.5, gv.add( gl ) );
1111

12-
return v.saturate();
12+
return v;
1313

1414
} ).setLayout( {
1515
name: 'V_GGX_SmithCorrelated_Anisotropic',

src/nodes/functions/PhysicalLightingModel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ class PhysicalLightingModel extends LightingModel {
751751
// Diffuse energy conservation uses dielectric path
752752
const totalScatteringDielectric = singleScatteringDielectric.add( multiScatteringDielectric );
753753

754-
const diffuse = diffuseContribution.mul( totalScatteringDielectric.r.max( totalScatteringDielectric.g ).max( totalScatteringDielectric.b ).oneMinus() );
754+
const diffuse = diffuseContribution.mul( totalScatteringDielectric.oneMinus() );
755755

756756
const cosineWeightedIrradiance = iblIrradiance.mul( 1 / Math.PI );
757757

src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,10 @@ vec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH )
7171
return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );
7272
}
7373
74-
// Moving Frostbite to Physically Based Rendering 3.0 - page 12, listing 2
75-
// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
74+
// Heitz 2014, "Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs"
7675
float V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {
7776
7877
float a2 = pow2( alpha );
79-
8078
float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
8179
float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
8280
@@ -106,7 +104,7 @@ float D_GGX( const in float alpha, const in float dotNH ) {
106104
float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );
107105
float v = 0.5 / ( gv + gl );
108106
109-
return saturate(v);
107+
return v;
110108
111109
}
112110
@@ -463,7 +461,7 @@ vec3 BRDF_GGX_Multiscatter( const in vec3 lightDir, const in vec3 viewDir, const
463461
vec3 Favg = material.specularColorBlended + ( 1.0 - material.specularColorBlended ) * 0.047619; // 1/21
464462
465463
// Multiple scattering contribution
466-
vec3 Fms = FssEss_V * FssEss_L * Favg / ( 1.0 - Ems_V * Ems_L * Favg * Favg + EPSILON );
464+
vec3 Fms = FssEss_V * FssEss_L * Favg / ( 1.0 - Ems_V * Ems_L * Favg + EPSILON );
467465
468466
// Energy compensation factor
469467
float compensationFactor = Ems_V * Ems_L;
@@ -590,7 +588,7 @@ void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradia
590588
591589
// Diffuse energy conservation uses dielectric path
592590
vec3 totalScatteringDielectric = singleScatteringDielectric + multiScatteringDielectric;
593-
vec3 diffuse = material.diffuseContribution * ( 1.0 - max( max( totalScatteringDielectric.r, totalScatteringDielectric.g ), totalScatteringDielectric.b ) );
591+
vec3 diffuse = material.diffuseContribution * ( 1.0 - totalScatteringDielectric );
594592
595593
vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;
596594

0 commit comments

Comments
 (0)