Browse Source

Allow the probe to be generated in linear space

Popov72 4 years ago
parent
commit
607ad0c2e0
1 changed files with 10 additions and 1 deletions
  1. 10 1
      src/Probes/reflectionProbe.ts

+ 10 - 1
src/Probes/reflectionProbe.ts

@@ -78,11 +78,12 @@ export class ReflectionProbe {
      * @param scene defines the hosting scene
      * @param scene defines the hosting scene
      * @param generateMipMaps defines if mip maps should be generated automatically (true by default)
      * @param generateMipMaps defines if mip maps should be generated automatically (true by default)
      * @param useFloat defines if HDR data (float data) should be used to store colors (false by default)
      * @param useFloat defines if HDR data (float data) should be used to store colors (false by default)
+     * @param linearSpace defines if the probe should be generated in linear space or not (false by default)
      */
      */
     constructor(
     constructor(
         /** defines the name of the probe */
         /** defines the name of the probe */
         public name: string,
         public name: string,
-        size: number, scene: Scene, generateMipMaps = true, useFloat = false) {
+        size: number, scene: Scene, generateMipMaps = true, useFloat = false, linearSpace = false) {
         this._scene = scene;
         this._scene = scene;
 
 
         // Create the scene field if not exist.
         // Create the scene field if not exist.
@@ -102,6 +103,7 @@ export class ReflectionProbe {
             }
             }
         }
         }
         this._renderTargetTexture = new RenderTargetTexture(name, size, scene, generateMipMaps, true, textureType, true);
         this._renderTargetTexture = new RenderTargetTexture(name, size, scene, generateMipMaps, true, textureType, true);
+        this._renderTargetTexture.gammaSpace = !linearSpace;
 
 
         this._renderTargetTexture.onBeforeRenderObservable.add((faceIndex: number) => {
         this._renderTargetTexture.onBeforeRenderObservable.add((faceIndex: number) => {
             switch (faceIndex) {
             switch (faceIndex) {
@@ -152,11 +154,18 @@ export class ReflectionProbe {
             scene._forcedViewPosition = this.position;
             scene._forcedViewPosition = this.position;
         });
         });
 
 
+        let currentApplyByPostProcess: boolean;
+
         this._renderTargetTexture.onBeforeBindObservable.add(() => {
         this._renderTargetTexture.onBeforeBindObservable.add(() => {
             scene.getEngine()._debugPushGroup(`reflection probe generation for ${name}`, 1);
             scene.getEngine()._debugPushGroup(`reflection probe generation for ${name}`, 1);
+            currentApplyByPostProcess = this._scene.imageProcessingConfiguration.applyByPostProcess;
+            if (linearSpace) {
+                scene.imageProcessingConfiguration.applyByPostProcess = true;
+            }
         });
         });
 
 
         this._renderTargetTexture.onAfterUnbindObservable.add(() => {
         this._renderTargetTexture.onAfterUnbindObservable.add(() => {
+            scene.imageProcessingConfiguration.applyByPostProcess = currentApplyByPostProcess;
             scene._forcedViewPosition = null;
             scene._forcedViewPosition = null;
             scene.updateTransformMatrix(true);
             scene.updateTransformMatrix(true);
             scene.getEngine()._debugPopGroup(1);
             scene.getEngine()._debugPopGroup(1);