Skip to content

Commit ed001a6

Browse files
authored
Fix NME PBR default setup (#16806)
https://playground.babylonjs.com/#T7FXR8#78 should render both sides in a similar way.
1 parent 36b4293 commit ed001a6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

packages/dev/core/src/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {
786786

787787
// Advanced
788788
defines.setValue("BRDF_V_HEIGHT_CORRELATED", true);
789+
defines.setValue("LEGACY_SPECULAR_ENERGY_CONSERVATION", true);
789790
defines.setValue("MS_BRDF_ENERGY_CONSERVATION", this.useEnergyConservation, true);
790791
defines.setValue("RADIANCEOCCLUSION", this.useRadianceOcclusion, true);
791792
defines.setValue("HORIZONOCCLUSION", this.useHorizonOcclusion, true);

packages/dev/core/src/Materials/Node/Blocks/PBR/subSurfaceBlock.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,19 @@ export class SubSurfaceBlock extends NodeMaterialBlock {
180180
${state._declareLocalVar("vTintColor", NodeMaterialBlockConnectionPointTypes.Vector4)} = vec4${state.fSuffix}(${tintColor}, ${refractionTintAtDistance});
181181
${state._declareLocalVar("vSubSurfaceIntensity", NodeMaterialBlockConnectionPointTypes.Vector3)} = vec3(${refractionIntensity}, ${translucencyIntensity}, 0.);
182182
${state._declareLocalVar("dispersion", NodeMaterialBlockConnectionPointTypes.Float)} = ${dispersion};
183-
#ifdef LEGACY_SPECULAR_ENERGY_CONSERVATION
184-
vec3 vSpecularEnvironmentReflectance = vec3(max(colorSpecularEnvironmentReflectance.r, max(colorSpecularEnvironmentReflectance.g, colorSpecularEnvironmentReflectance.b)));
185-
#endif
186183
subSurfaceOut = subSurfaceBlock(
187184
vSubSurfaceIntensity
188185
, vThicknessParam
189186
, vTintColor
190187
, normalW
191188
#ifdef LEGACY_SPECULAR_ENERGY_CONSERVATION
192-
, vSpecularEnvironmentReflectance
193-
#else
189+
`;
190+
191+
code += isWebGPU
192+
? `, vec3f(max(colorSpecularEnvironmentReflectance.r, max(colorSpecularEnvironmentReflectance.g, colorSpecularEnvironmentReflectance.b)))/n`
193+
: `, vec3(max(colorSpecularEnvironmentReflectance.r, max(colorSpecularEnvironmentReflectance.g, colorSpecularEnvironmentReflectance.b)))/n`;
194+
195+
code += `#else
194196
, baseSpecularEnvironmentReflectance
195197
#endif
196198
#ifdef SS_THICKNESSANDMASK_TEXTURE

0 commit comments

Comments
 (0)