Explorar o código

convert back to gamma to avoid multiple toLinear conversions

Trevor Baron %!s(int64=7) %!d(string=hai) anos
pai
achega
030d8cb362

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

@@ -132,6 +132,7 @@
 - Add onLoadObservable on VideoTexture - [#3845](https://github.com/BabylonJS/Babylon.js/issues/3845) ([sebavan](https://github.com/sebavan))
 - beforeRender is now triggered after the camera updated its state - [#3873](https://github.com/BabylonJS/Babylon.js/issues/3873) ([RaananW](https://github.com/RaananW))
 - Tools.DeepCopy no longer copying getter-only elements - [#3929](https://github.com/BabylonJS/Babylon.js/issues/3929) ([RaananW](https://github.com/RaananW))
+- Reflection and refraction no longer apply a toLinear conversion twice when applying image processing as a post process - [#4060](https://github.com/BabylonJS/Babylon.js/issues/4060) ([trevordev](https://github.com/trevordev))
 
 ## Breaking changes
 

+ 1 - 0
src/Materials/Textures/babylon.mirrorTexture.ts

@@ -90,6 +90,7 @@
             this.ignoreCameraViewport = true;
 
             this.onBeforeRenderObservable.add(() => {
+                this.gammaSpace = !scene.imageProcessingConfiguration.isEnabled || !scene.imageProcessingConfiguration.applyByPostProcess;
                 Matrix.ReflectionToRef(this.mirrorPlane, this._mirrorMatrix);
                 this._savedViewMatrix = scene.getViewMatrix();
 

+ 13 - 0
src/Materials/babylon.standardMaterial.ts

@@ -87,6 +87,16 @@ module BABYLON {
         public SAMPLER3DGREENDEPTH = false;
         public SAMPLER3DBGRMAP = false;
         public IMAGEPROCESSINGPOSTPROCESS = false;
+        /**
+         * If the reflection texture on this material is in linear color space
+         * @ignore
+         */
+        public IS_REFLECTION_LINEAR = false;
+        /**
+         * If the refraction texture on this material is in linear color space
+         * @ignore
+         */
+        public IS_REFRACTION_LINEAR = false;
         public EXPOSURE = false;
 
         constructor() {
@@ -724,6 +734,9 @@ module BABYLON {
                 }
 
                 this._imageProcessingConfiguration.prepareDefines(defines);
+
+                defines.IS_REFLECTION_LINEAR = (this.reflectionTexture != null && !this.reflectionTexture.gammaSpace);
+                defines.IS_REFRACTION_LINEAR = (this.refractionTexture != null && !this.refractionTexture.gammaSpace);
             }
 
             if (defines._areFresnelDirty) {

+ 15 - 6
src/Shaders/default.fragment.fx

@@ -274,7 +274,12 @@ void main(void) {
 
 	refractionCoords.y = 1.0 - refractionCoords.y;
 
-	refractionColor = texture2D(refraction2DSampler, refractionCoords).rgb * vRefractionInfos.x;
+	#ifdef IS_REFRACTION_LINEAR
+		refractionColor = toGammaSpace(texture2D(refraction2DSampler, refractionCoords).rgb);
+	#else
+		refractionColor = texture2D(refraction2DSampler, refractionCoords).rgb;
+	#endif
+	refractionColor *= vRefractionInfos.x;
 #endif
 #endif
 
@@ -304,13 +309,17 @@ void main(void) {
 #else
 	vec2 coords = vReflectionUVW.xy;
 
-#ifdef REFLECTIONMAP_PROJECTION
-	coords /= vReflectionUVW.z;
-#endif
+	#ifdef REFLECTIONMAP_PROJECTION
+		coords /= vReflectionUVW.z;
+	#endif
 
 	coords.y = 1.0 - coords.y;
-
-	reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.x;
+	#ifdef IS_REFLECTION_LINEAR
+		reflectionColor = toGammaSpace(texture2D(reflection2DSampler, coords).rgb);
+	#else
+		reflectionColor = texture2D(reflection2DSampler, coords).rgb;
+	#endif
+	reflectionColor *= vReflectionInfos.x;
 #endif
 
 #ifdef REFLECTIONFRESNEL