瀏覽代碼

Merge pull request #6834 from ColorDigital-PS/master

Deactivation of energy conservation for the specular glossiness workflow
David Catuhe 6 年之前
父節點
當前提交
05c912cc8a

+ 1 - 0
dist/preview release/what's new.md

@@ -87,6 +87,7 @@
 - Added `ShaderMaterial.setArray4` ([JonathanTron](https://github.com/JonathanTron/))
 - Added `scene.environmentIntensity` to control the IBL strength overall in a scene ([Sebavan](https://github.com/sebavan/))
 - Added support of image processing for `WaterMaterial` ([julien-moreau](https://github.com/julien-moreau))
+- Added `pbrBRDFConfiguration.useSpecularGlossinessInputEnergyConservation` to allow Specular-Workflow energy conservation to be turned off ([ColorDigital-PS](https://github.com/ColorDigital-PS)).
 
 ### ScreenshotTools
 - Added interface for argument `size` of screenshot methods ([Dok11](https://github.com/Dok11/))

+ 20 - 0
src/Materials/PBR/pbrBRDFConfiguration.ts

@@ -8,6 +8,7 @@ export interface IMaterialBRDFDefines {
     BRDF_V_HEIGHT_CORRELATED: boolean;
     MS_BRDF_ENERGY_CONSERVATION: boolean;
     SPHERICAL_HARMONICS: boolean;
+    SPECULAR_GLOSSINESS_ENERGY_CONSERVATION: boolean;
 
     /** @hidden */
     _areMiscDirty: boolean;
@@ -37,6 +38,13 @@ export class PBRBRDFConfiguration {
      */
     public static DEFAULT_USE_SPHERICAL_HARMONICS = true;
 
+    /**
+     * Default value used for activating energy conservation for the specular workflow.
+     * If activated, the albedo color is multiplied with (1. - maxChannel(specular color)).
+     * If deactivated, a material is only physically plausible, when (albedo color + specular color) < 1.
+     */
+    public static DEFAULT_USE_SPECULAR_GLOSSINESS_INPUT_ENERGY_CONSERVATION = true;
+
     private _useEnergyConservation = PBRBRDFConfiguration.DEFAULT_USE_ENERGY_CONSERVATION;
     /**
      * Defines if the material uses energy conservation.
@@ -70,6 +78,17 @@ export class PBRBRDFConfiguration {
     @expandToProperty("_markAllSubMeshesAsMiscDirty")
     public useSphericalHarmonics = PBRBRDFConfiguration.DEFAULT_USE_SPHERICAL_HARMONICS;
 
+    private _useSpecularGlossinessInputEnergyConservation = PBRBRDFConfiguration.DEFAULT_USE_SPECULAR_GLOSSINESS_INPUT_ENERGY_CONSERVATION;
+    /**
+     * Defines if the material uses energy conservation, when the specular workflow is active.
+     * If activated, the albedo color is multiplied with (1. - maxChannel(specular color)).
+     * If deactivated, a material is only physically plausible, when (albedo color + specular color) < 1.
+     * In the deactivated case, the material author has to ensure energy conservation, for a physically plausible rendering.
+     */
+    @serialize()
+    @expandToProperty("_markAllSubMeshesAsMiscDirty")
+    public useSpecularGlossinessInputEnergyConservation = PBRBRDFConfiguration.DEFAULT_USE_SPECULAR_GLOSSINESS_INPUT_ENERGY_CONSERVATION;
+
     /** @hidden */
     private _internalMarkAllSubMeshesAsMiscDirty: () => void;
 
@@ -94,6 +113,7 @@ export class PBRBRDFConfiguration {
         defines.BRDF_V_HEIGHT_CORRELATED = this._useSmithVisibilityHeightCorrelated;
         defines.MS_BRDF_ENERGY_CONSERVATION = this._useEnergyConservation && this._useSmithVisibilityHeightCorrelated;
         defines.SPHERICAL_HARMONICS = this._useSphericalHarmonics;
+        defines.SPECULAR_GLOSSINESS_ENERGY_CONSERVATION = this._useSpecularGlossinessInputEnergyConservation;
     }
 
     /**

+ 1 - 0
src/Materials/PBR/pbrBaseMaterial.ts

@@ -204,6 +204,7 @@ export class PBRMaterialDefines extends MaterialDefines
 
     public BRDF_V_HEIGHT_CORRELATED = false;
     public MS_BRDF_ENERGY_CONSERVATION = false;
+    public SPECULAR_GLOSSINESS_ENERGY_CONSERVATION = false;
 
     public SHEEN = false;
     public SHEEN_TEXTURE = false;

+ 3 - 1
src/Shaders/pbr.fragment.fx

@@ -1029,7 +1029,9 @@ void main(void) {
     // _____________________________ Energy Conservation  ___________________________
     // Apply Energy Conservation.
     #ifndef METALLICWORKFLOW
-        surfaceAlbedo.rgb = (1. - reflectance) * surfaceAlbedo.rgb;
+        #ifdef SPECULAR_GLOSSINESS_ENERGY_CONSERVATION
+            surfaceAlbedo.rgb = (1. - reflectance) * surfaceAlbedo.rgb;
+        #endif
     #endif
 
     // _____________________________ Irradiance ______________________________________