Browse Source

Fix gammaSpace updates

David Catuhe 6 years ago
parent
commit
8fcb819076

+ 1 - 1
src/Engines/thinEngine.ts

@@ -2924,7 +2924,7 @@ export class ThinEngine {
             else if (typeof buffer === "string" || buffer instanceof ArrayBuffer || ArrayBuffer.isView(buffer) || buffer instanceof Blob) {
                 FileTools.LoadImage(buffer, onload, onInternalError, scene ? scene.offlineProvider : null);
             }
-            else {
+            else if (buffer){
                 onload(<HTMLImageElement>buffer);
             }
         }

+ 3 - 3
src/Materials/Node/Blocks/Dual/textureBlock.ts

@@ -170,15 +170,15 @@ export class TextureBlock extends NodeMaterialBlock {
     }
 
     public prepareDefines(mesh: AbstractMesh, nodeMaterial: NodeMaterial, defines: NodeMaterialDefines) {
-        if (!this.texture || !this.texture.getTextureMatrix) {
+        if (!defines._areTexturesDirty) {
             return;
         }
 
-        defines.setValue(this._linearDefineName, !this.texture.gammaSpace);
-        if (!defines._areTexturesDirty) {
+        if (!this.texture || !this.texture.getTextureMatrix) {
             return;
         }
 
+        defines.setValue(this._linearDefineName, !this.texture.gammaSpace);
         if (this._isMixed) {
             if (!this.texture.getTextureMatrix().isIdentityAs3x2()) {
                 defines.setValue(this._defineName, true);

+ 15 - 1
src/Materials/Textures/baseTexture.ts

@@ -1,4 +1,4 @@
-import { serialize, SerializationHelper, serializeAsTexture } from "../../Misc/decorators";
+import { serialize, SerializationHelper, serializeAsTexture, expandToProperty } from "../../Misc/decorators";
 import { Observer, Observable } from "../../Misc/observable";
 import { CubeMapToSphericalPolynomialTools } from "../../Misc/HighDynamicRange/cubemapToSphericalPolynomial";
 import { Nullable } from "../../types";
@@ -205,6 +205,7 @@ export class BaseTexture implements IAnimatable {
      * This only impacts the PBR and Background materials
      */
     @serialize()
+    @expandToProperty("_markAllSubMeshesAsTexturesDirty")
     public gammaSpace = true;
 
     /**
@@ -595,6 +596,19 @@ export class BaseTexture implements IAnimatable {
     }
 
     /**
+     * Indicates that textures need to be re-calculated for all materials
+     */
+    protected _markAllSubMeshesAsTexturesDirty() {
+        let scene = this.getScene();
+
+        if (!scene) {
+            return;
+        }
+
+        scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);
+    }
+
+    /**
      * Reads the pixels stored in the webgl texture and returns them as an ArrayBuffer.
      * This will returns an RGBA array buffer containing either in values (0-255) or
      * float values (0-1) depending of the underlying buffer type.

+ 5 - 0
src/Shaders/ShadersInclude/helperFunctions.fx

@@ -53,6 +53,11 @@ vec3 toGammaSpace(vec3 color)
     return pow(color, vec3(GammaEncodePowerApprox));
 }
 
+float toGammaSpace(float color)
+{
+    return pow(color, GammaEncodePowerApprox);
+}
+
 float square(float value)
 {
     return value * value;