Selaa lähdekoodia

Fixed how invertNormal works

David Catuhe 8 vuotta sitten
vanhempi
commit
609c919139
38 muutettua tiedostoa jossa 9262 lisäystä ja 9113 poistoa
  1. 3717 3719
      dist/preview release/babylon.d.ts
  2. 40 40
      dist/preview release/babylon.js
  3. 20 22
      dist/preview release/babylon.max.js
  4. 3717 3719
      dist/preview release/babylon.module.d.ts
  5. 41 41
      dist/preview release/babylon.worker.js
  6. 571 573
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts
  7. 32 32
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js
  8. 20 22
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js
  9. 571 573
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts
  10. 23 0
      dist/preview release/gui/babylon.gui.d.ts
  11. 162 0
      dist/preview release/gui/babylon.gui.js
  12. 3 3
      dist/preview release/gui/babylon.gui.min.js
  13. 263 263
      dist/preview release/inspector/babylon.inspector.bundle.js
  14. 3 3
      dist/preview release/inspector/babylon.inspector.min.js
  15. 2 2
      dist/preview release/loaders/babylon.glTF1FileLoader.min.js
  16. 1 1
      dist/preview release/loaders/babylon.glTF2FileLoader.min.js
  17. 2 2
      dist/preview release/loaders/babylon.glTFFileLoader.min.js
  18. 1 1
      dist/preview release/loaders/babylon.objFileLoader.min.js
  19. 0 2
      dist/preview release/materialsLibrary/babylon.customMaterial.d.ts
  20. 8 10
      dist/preview release/materialsLibrary/babylon.customMaterial.js
  21. 2 2
      dist/preview release/materialsLibrary/babylon.customMaterial.min.js
  22. 10 15
      dist/preview release/materialsLibrary/babylon.legacyPbrMaterial.js
  23. 3 3
      dist/preview release/materialsLibrary/babylon.legacyPbrMaterial.min.js
  24. 1 1
      dist/preview release/materialsLibrary/babylon.waterMaterial.min.js
  25. 1 1
      dist/preview release/postProcessesLibrary/babylon.asciiArtPostProcess.min.js
  26. 1 1
      dist/preview release/postProcessesLibrary/babylon.digitalRainPostProcess.min.js
  27. 8 12
      materialsLibrary/src/custom/babylon.customMaterial.ts
  28. 10 17
      materialsLibrary/src/legacyPBR/babylon.legacyPBRMaterial.ts
  29. 2 2
      materialsLibrary/src/legacyPBR/babylon.legacyPbrMaterial.js.include.fx
  30. 1 0
      materialsLibrary/src/legacyPBR/legacyPbrFragmentDeclaration.fx
  31. 1 0
      materialsLibrary/src/legacyPBR/legacyPbrUboDeclaration.fx
  32. 11 13
      src/Materials/PBR/babylon.pbrBaseMaterial.ts
  33. 8 12
      src/Materials/babylon.standardMaterial.ts
  34. 2 6
      src/Shaders/ShadersInclude/bumpFragmentFunctions.fx
  35. 1 0
      src/Shaders/ShadersInclude/defaultFragmentDeclaration.fx
  36. 1 0
      src/Shaders/ShadersInclude/defaultUboDeclaration.fx
  37. 1 0
      src/Shaders/ShadersInclude/pbrFragmentDeclaration.fx
  38. 1 0
      src/Shaders/ShadersInclude/pbrUboDeclaration.fx

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 3717 - 3719
dist/preview release/babylon.d.ts


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 40 - 40
dist/preview release/babylon.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 20 - 22
dist/preview release/babylon.max.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 3717 - 3719
dist/preview release/babylon.module.d.ts


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 41 - 41
dist/preview release/babylon.worker.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 571 - 573
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 32 - 32
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 20 - 22
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 571 - 573
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts


+ 23 - 0
dist/preview release/gui/babylon.gui.d.ts

@@ -94,6 +94,7 @@ declare module BABYLON.GUI {
         readonly isPercentage: boolean;
         readonly isPixel: boolean;
         readonly internalValue: number;
+        getValueInPixel(host: AdvancedDynamicTexture, refValue: number): number;
         getValue(host: AdvancedDynamicTexture): number;
         toString(host: AdvancedDynamicTexture): string;
         fromString(source: string | number): boolean;
@@ -577,3 +578,25 @@ declare module BABYLON.GUI {
         protected _onPointerUp(coordinates: Vector2): void;
     }
 }
+
+
+declare module BABYLON.GUI {
+    class InputText extends Control {
+        name: string;
+        private _text;
+        private _background;
+        private _thickness;
+        private _margin;
+        private _autoStretchWidth;
+        private _maxWidth;
+        maxWidth: string | number;
+        margin: string;
+        autoStretchWidth: boolean;
+        thickness: number;
+        background: string;
+        text: string;
+        constructor(name?: string, text?: string);
+        protected _getTypeName(): string;
+        _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
+    }
+}

+ 162 - 0
dist/preview release/gui/babylon.gui.js

@@ -551,6 +551,12 @@ var BABYLON;
                 enumerable: true,
                 configurable: true
             });
+            ValueAndUnit.prototype.getValueInPixel = function (host, refValue) {
+                if (this.isPixel) {
+                    return this.getValue(host);
+                }
+                return this.getValue(host) * refValue;
+            };
             ValueAndUnit.prototype.getValue = function (host) {
                 if (host && !this.ignoreAdaptiveScaling && this.unit !== ValueAndUnit.UNITMODE_PERCENTAGE) {
                     if (host.idealWidth) {
@@ -3608,3 +3614,159 @@ var BABYLON;
         GUI.ColorPicker = ColorPicker;
     })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
 })(BABYLON || (BABYLON = {}));
+
+/// <reference path="../../../dist/preview release/babylon.d.ts"/>
+var __extends = (this && this.__extends) || (function () {
+    var extendStatics = Object.setPrototypeOf ||
+        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
+    return function (d, b) {
+        extendStatics(d, b);
+        function __() { this.constructor = d; }
+        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+    };
+})();
+var BABYLON;
+(function (BABYLON) {
+    var GUI;
+    (function (GUI) {
+        var InputText = (function (_super) {
+            __extends(InputText, _super);
+            function InputText(name, text) {
+                if (text === void 0) { text = ""; }
+                var _this = _super.call(this, name) || this;
+                _this.name = name;
+                _this._text = "";
+                _this._background = "black";
+                _this._thickness = 1;
+                _this._margin = new GUI.ValueAndUnit(10, GUI.ValueAndUnit.UNITMODE_PIXEL);
+                _this._autoStretchWidth = true;
+                _this._maxWidth = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
+                _this.text = text;
+                return _this;
+            }
+            Object.defineProperty(InputText.prototype, "maxWidth", {
+                get: function () {
+                    return this._maxWidth.toString(this._host);
+                },
+                set: function (value) {
+                    if (this._maxWidth.toString(this._host) === value) {
+                        return;
+                    }
+                    if (this._maxWidth.fromString(value)) {
+                        this._markAsDirty();
+                    }
+                },
+                enumerable: true,
+                configurable: true
+            });
+            Object.defineProperty(InputText.prototype, "margin", {
+                get: function () {
+                    return this._margin.toString(this._host);
+                },
+                set: function (value) {
+                    if (this._margin.toString(this._host) === value) {
+                        return;
+                    }
+                    if (this._margin.fromString(value)) {
+                        this._markAsDirty();
+                    }
+                },
+                enumerable: true,
+                configurable: true
+            });
+            Object.defineProperty(InputText.prototype, "autoStretchWidth", {
+                get: function () {
+                    return this._autoStretchWidth;
+                },
+                set: function (value) {
+                    if (this._autoStretchWidth === value) {
+                        return;
+                    }
+                    this._autoStretchWidth = value;
+                    this._markAsDirty();
+                },
+                enumerable: true,
+                configurable: true
+            });
+            Object.defineProperty(InputText.prototype, "thickness", {
+                get: function () {
+                    return this._thickness;
+                },
+                set: function (value) {
+                    if (this._thickness === value) {
+                        return;
+                    }
+                    this._thickness = value;
+                    this._markAsDirty();
+                },
+                enumerable: true,
+                configurable: true
+            });
+            Object.defineProperty(InputText.prototype, "background", {
+                get: function () {
+                    return this._background;
+                },
+                set: function (value) {
+                    if (this._background === value) {
+                        return;
+                    }
+                    this._background = value;
+                    this._markAsDirty();
+                },
+                enumerable: true,
+                configurable: true
+            });
+            Object.defineProperty(InputText.prototype, "text", {
+                get: function () {
+                    return this._text;
+                },
+                set: function (value) {
+                    if (this._text === value) {
+                        return;
+                    }
+                    this._text = value;
+                    this._markAsDirty();
+                },
+                enumerable: true,
+                configurable: true
+            });
+            InputText.prototype._getTypeName = function () {
+                return "InputText";
+            };
+            InputText.prototype._draw = function (parentMeasure, context) {
+                context.save();
+                this._applyStates(context);
+                if (this._processMeasures(parentMeasure, context)) {
+                    // Background
+                    if (this._background) {
+                        context.fillStyle = this._background;
+                        context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
+                    }
+                    // Text
+                    if (this._text) {
+                        if (this.color) {
+                            context.fillStyle = this.color;
+                        }
+                        var rootY = this._fontOffset.ascent + (this._currentMeasure.height - this._fontOffset.height) / 2;
+                        context.fillText(this._text, this._currentMeasure.left + this._margin.getValueInPixel(this._host, parentMeasure.width), this._currentMeasure.top + rootY);
+                        if (this._autoStretchWidth) {
+                            this.width = Math.min(this._maxWidth.getValueInPixel(this._host, parentMeasure.width), context.measureText(this._text).width + this._margin.getValueInPixel(this._host, parentMeasure.width) * 2) + "px";
+                        }
+                    }
+                    // Border
+                    if (this._thickness) {
+                        if (this.color) {
+                            context.strokeStyle = this.color;
+                        }
+                        context.lineWidth = this._thickness;
+                        context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
+                    }
+                }
+                context.restore();
+            };
+            return InputText;
+        }(GUI.Control));
+        GUI.InputText = InputText;
+    })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
+})(BABYLON || (BABYLON = {}));

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 3 - 3
dist/preview release/gui/babylon.gui.min.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 263 - 263
dist/preview release/inspector/babylon.inspector.bundle.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 3 - 3
dist/preview release/inspector/babylon.inspector.min.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 2 - 2
dist/preview release/loaders/babylon.glTF1FileLoader.min.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1 - 1
dist/preview release/loaders/babylon.glTF2FileLoader.min.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 2 - 2
dist/preview release/loaders/babylon.glTFFileLoader.min.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1 - 1
dist/preview release/loaders/babylon.objFileLoader.min.js


+ 0 - 2
dist/preview release/materialsLibrary/babylon.customMaterial.d.ts

@@ -54,8 +54,6 @@ declare module BABYLON {
         REFRACTION: boolean;
         REFRACTIONMAP_3D: boolean;
         REFLECTIONOVERALPHA: boolean;
-        INVERTNORMALMAPX: boolean;
-        INVERTNORMALMAPY: boolean;
         TWOSIDEDLIGHTING: boolean;
         SHADOWFLOAT: boolean;
         MORPHTARGETS: boolean;

+ 8 - 10
dist/preview release/materialsLibrary/babylon.customMaterial.js

@@ -75,8 +75,6 @@ var BABYLON;
             _this.REFRACTION = false;
             _this.REFRACTIONMAP_3D = false;
             _this.REFLECTIONOVERALPHA = false;
-            _this.INVERTNORMALMAPX = false;
-            _this.INVERTNORMALMAPY = false;
             _this.TWOSIDEDLIGHTING = false;
             _this.SHADOWFLOAT = false;
             _this.MORPHTARGETS = false;
@@ -498,8 +496,6 @@ var BABYLON;
                         else {
                             defines._needUVs = true;
                             defines.BUMP = true;
-                            defines.INVERTNORMALMAPX = this.invertNormalMapX;
-                            defines.INVERTNORMALMAPY = this.invertNormalMapY;
                             defines.PARALLAX = this._useParallax;
                             defines.PARALLAXOCCLUSION = this._useParallaxOcclusion;
                         }
@@ -569,11 +565,6 @@ var BABYLON;
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             // Values that need to be evaluated on every frame
             BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
-            if (scene._mirroredCameraPosition && defines.BUMP) {
-                defines.INVERTNORMALMAPX = !this.invertNormalMapX;
-                defines.INVERTNORMALMAPY = !this.invertNormalMapY;
-                defines.markAsUnprocessed();
-            }
             // Get correct effect      
             if (defines.isDirty) {
                 defines.markAsProcessed();
@@ -650,7 +641,7 @@ var BABYLON;
                     "mBones",
                     "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
                     "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor", "refractionLeftColor", "refractionRightColor",
-                    "logarithmicDepthConstant"
+                    "logarithmicDepthConstant", "vNormalReoderParams"
                 ];
                 var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"];
                 var uniformBuffers = ["Material", "Scene"];
@@ -714,6 +705,7 @@ var BABYLON;
             this._uniformBuffer.addUniform("lightmapMatrix", 16);
             this._uniformBuffer.addUniform("specularMatrix", 16);
             this._uniformBuffer.addUniform("bumpMatrix", 16);
+            this._uniformBuffer.addUniform("vNormalReoderParams", 4);
             this._uniformBuffer.addUniform("refractionMatrix", 16);
             this._uniformBuffer.addUniform("vRefractionInfos", 4);
             this._uniformBuffer.addUniform("vSpecularColor", 4);
@@ -804,6 +796,12 @@ var BABYLON;
                         if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial_OldVer.BumpTextureEnabled) {
                             this._uniformBuffer.updateFloat3("vBumpInfos", this._bumpTexture.coordinatesIndex, 1.0 / this._bumpTexture.level, this.parallaxScaleBias);
                             this._uniformBuffer.updateMatrix("bumpMatrix", this._bumpTexture.getTextureMatrix());
+                            if (scene._mirroredCameraPosition) {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this.invertNormalMapX ? 0 : 1.0, this.invertNormalMapX ? 1.0 : -1.0, this.invertNormalMapY ? 0 : 1.0, this.invertNormalMapY ? 1.0 : -1.0);
+                            }
+                            else {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this.invertNormalMapX ? 1.0 : 0, this.invertNormalMapX ? -1.0 : 1.0, this.invertNormalMapY ? 1.0 : 0, this.invertNormalMapY ? -1.0 : 1.0);
+                            }
                         }
                         if (this._refractionTexture && StandardMaterial_OldVer.RefractionTextureEnabled) {
                             var depth = 1.0;

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 2 - 2
dist/preview release/materialsLibrary/babylon.customMaterial.min.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 10 - 15
dist/preview release/materialsLibrary/babylon.legacyPbrMaterial.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 3 - 3
dist/preview release/materialsLibrary/babylon.legacyPbrMaterial.min.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1 - 1
dist/preview release/materialsLibrary/babylon.waterMaterial.min.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1 - 1
dist/preview release/postProcessesLibrary/babylon.asciiArtPostProcess.min.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1 - 1
dist/preview release/postProcessesLibrary/babylon.digitalRainPostProcess.min.js


+ 8 - 12
materialsLibrary/src/custom/babylon.customMaterial.ts

@@ -57,8 +57,6 @@ module BABYLON {
         public REFRACTION = false;
         public REFRACTIONMAP_3D = false;
         public REFLECTIONOVERALPHA = false;
-        public INVERTNORMALMAPX = false;
-        public INVERTNORMALMAPY = false;
         public TWOSIDEDLIGHTING = false;
         public SHADOWFLOAT = false;
         public MORPHTARGETS = false;
@@ -640,9 +638,6 @@ module BABYLON {
                             defines._needUVs = true;
                             defines.BUMP = true;
 
-                            defines.INVERTNORMALMAPX = this.invertNormalMapX;
-                            defines.INVERTNORMALMAPY = this.invertNormalMapY;
-
                             defines.PARALLAX = this._useParallax;
                             defines.PARALLAXOCCLUSION = this._useParallaxOcclusion;
                         }
@@ -728,12 +723,6 @@ module BABYLON {
             // Values that need to be evaluated on every frame
             MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
 
-            if (scene._mirroredCameraPosition && defines.BUMP) {
-                defines.INVERTNORMALMAPX = !this.invertNormalMapX;
-                defines.INVERTNORMALMAPY = !this.invertNormalMapY;
-                defines.markAsUnprocessed();
-            }
-
             // Get correct effect      
             if (defines.isDirty) {
                 defines.markAsProcessed();
@@ -834,7 +823,7 @@ module BABYLON {
                     "mBones",
                     "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
                     "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor", "refractionLeftColor", "refractionRightColor",
-                    "logarithmicDepthConstant"
+                    "logarithmicDepthConstant", "vNormalReoderParams"
                 ];
 
                 var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"]
@@ -911,6 +900,7 @@ module BABYLON {
             this._uniformBuffer.addUniform("lightmapMatrix", 16);
             this._uniformBuffer.addUniform("specularMatrix", 16);
             this._uniformBuffer.addUniform("bumpMatrix", 16);
+            this._uniformBuffer.addUniform("vNormalReoderParams", 4);            
             this._uniformBuffer.addUniform("refractionMatrix", 16);
             this._uniformBuffer.addUniform("vRefractionInfos", 4);
             this._uniformBuffer.addUniform("vSpecularColor", 4);
@@ -1024,6 +1014,12 @@ module BABYLON {
                         if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial_OldVer.BumpTextureEnabled) {
                             this._uniformBuffer.updateFloat3("vBumpInfos", this._bumpTexture.coordinatesIndex, 1.0 / this._bumpTexture.level, this.parallaxScaleBias);
                             this._uniformBuffer.updateMatrix("bumpMatrix", this._bumpTexture.getTextureMatrix());
+
+                            if (scene._mirroredCameraPosition) {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this.invertNormalMapX ? 0 : 1.0, this.invertNormalMapX ? 1.0 : -1.0, this.invertNormalMapY ? 0 : 1.0, this.invertNormalMapY ? 1.0 : -1.0);
+                            } else {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this.invertNormalMapX ? 1.0 : 0, this.invertNormalMapX ? -1.0 : 1.0, this.invertNormalMapY ? 1.0 : 0, this.invertNormalMapY ? -1.0 : 1.0);
+                            }                                                          
                         }
 
                         if (this._refractionTexture && StandardMaterial_OldVer.RefractionTextureEnabled) {

+ 10 - 17
materialsLibrary/src/legacyPBR/babylon.legacyPBRMaterial.ts

@@ -66,8 +66,6 @@ module BABYLON {
         public RADIANCEOVERALPHA = false;
         public USEPMREMREFLECTION = false;
         public USEPMREMREFRACTION = false;
-        public INVERTNORMALMAPX = false;
-        public INVERTNORMALMAPY = false;
         public TWOSIDEDLIGHTING = false;
         public SHADOWFLOAT = false;
 
@@ -851,20 +849,7 @@ module BABYLON {
                         if (this.useParallaxOcclusion) {
                             this._defines.PARALLAXOCCLUSION = true;
                         }
-                    }
-
-                    if (this.invertNormalMapX) {
-                        this._defines.INVERTNORMALMAPX = true;
-                    }
-
-                    if (this.invertNormalMapY) {
-                        this._defines.INVERTNORMALMAPY = true;
-                    }
-
-                    if (scene._mirroredCameraPosition) {
-                        this._defines.INVERTNORMALMAPX = !this._defines.INVERTNORMALMAPX;
-                        this._defines.INVERTNORMALMAPY = !this._defines.INVERTNORMALMAPY;
-                    }                        
+                    }                     
                 }
 
                 if (this.refractionTexture && StandardMaterial.RefractionTextureEnabled) {
@@ -1154,7 +1139,7 @@ module BABYLON {
                         "vSphericalXX", "vSphericalYY", "vSphericalZZ",
                         "vSphericalXY", "vSphericalYZ", "vSphericalZX",
                         "vMicrosurfaceTextureLods",
-                        "vCameraInfos"
+                        "vCameraInfos", "vNormalReoderParams"
                 ];
 
                 var samplers = ["albedoSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "reflectivitySampler", "microSurfaceSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"];
@@ -1233,6 +1218,7 @@ module BABYLON {
             this._uniformBuffer.addUniform("reflectivityMatrix", 16);
             this._uniformBuffer.addUniform("microSurfaceSamplerMatrix", 16);
             this._uniformBuffer.addUniform("bumpMatrix", 16);
+            this._uniformBuffer.addUniform("vNormalReoderParams", 4);
             this._uniformBuffer.addUniform("refractionMatrix", 16);
             this._uniformBuffer.addUniform("reflectionMatrix", 16);
 
@@ -1377,6 +1363,13 @@ module BABYLON {
                         if (this.bumpTexture && this._myScene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled && !this.disableBumpMap) {
                             this._uniformBuffer.updateFloat3("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level, this.parallaxScaleBias);
                             this._uniformBuffer.updateMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
+
+
+                            if (this._myScene._mirroredCameraPosition) {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this.invertNormalMapX ? 0 : 1.0, this.invertNormalMapX ? 1.0 : -1.0, this.invertNormalMapY ? 0 : 1.0, this.invertNormalMapY ? 1.0 : -1.0);
+                            } else {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this.invertNormalMapX ? 1.0 : 0, this.invertNormalMapX ? -1.0 : 1.0, this.invertNormalMapY ? 1.0 : 0, this.invertNormalMapY ? -1.0 : 1.0);
+                            }                              
                         }
 
                         if (this.refractionTexture && StandardMaterial.RefractionTextureEnabled) {

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 2 - 2
materialsLibrary/src/legacyPBR/babylon.legacyPbrMaterial.js.include.fx


+ 1 - 0
materialsLibrary/src/legacyPBR/legacyPbrFragmentDeclaration.fx

@@ -36,6 +36,7 @@ uniform vec3 vAmbientInfos;
 
 #ifdef BUMP
 uniform vec3 vBumpInfos;
+uniform vec4 vNormalReoderParams;
 #endif
 
 #ifdef OPACITY	

+ 1 - 0
materialsLibrary/src/legacyPBR/legacyPbrUboDeclaration.fx

@@ -20,6 +20,7 @@ uniform Material
 	uniform mat4 reflectivityMatrix;
 	uniform mat4 microSurfaceSamplerMatrix;
 	uniform mat4 bumpMatrix;
+	uniform vec4 vNormalReoderParams;
 	uniform mat4 refractionMatrix;
 	uniform mat4 reflectionMatrix;
 

+ 11 - 13
src/Materials/PBR/babylon.pbrBaseMaterial.ts

@@ -54,8 +54,6 @@
         public BUMPDIRECTUV = 0;
         public PARALLAX = false;
         public PARALLAXOCCLUSION = false;
-        public INVERTNORMALMAPX = false;
-        public INVERTNORMALMAPY = false;
         public NORMALXYSCALE = true;
 
         public LIGHTMAP = false;
@@ -351,12 +349,12 @@
         protected _maxSimultaneousLights = 4;  
 
         /**
-         * If sets to true, x component of normal map value will invert (x = 1.0 - x).
+         * If sets to true, x component of normal map value will be inverted (x = 1.0 - x).
          */
         protected _invertNormalMapX = false;
 
         /**
-         * If sets to true, y component of normal map value will invert (y = 1.0 - y).
+         * If sets to true, y component of normal map value will be inverted (y = 1.0 - y).
          */
         protected _invertNormalMapY = false;
 
@@ -730,14 +728,6 @@
                             defines.PARALLAX = false;
                         }
 
-                        defines.INVERTNORMALMAPX = !!this._invertNormalMapX;
-                        defines.INVERTNORMALMAPY = !!this._invertNormalMapY;
-
-                        if (scene._mirroredCameraPosition) {
-                            defines.INVERTNORMALMAPX = !defines.INVERTNORMALMAPX;
-                            defines.INVERTNORMALMAPY = !defines.INVERTNORMALMAPY;
-                        }
-
                         defines.USERIGHTHANDEDSYSTEM = scene.useRightHandedSystem;
                     } else {
                         defines.BUMP = false;
@@ -923,7 +913,8 @@
                         "vSphericalX", "vSphericalY", "vSphericalZ",
                         "vSphericalXX", "vSphericalYY", "vSphericalZZ",
                         "vSphericalXY", "vSphericalYZ", "vSphericalZX",
-                        "vReflectionMicrosurfaceInfos", "vRefractionMicrosurfaceInfos"
+                        "vReflectionMicrosurfaceInfos", "vRefractionMicrosurfaceInfos",
+                        "vNormalReoderParams"
                 ];
 
                 var samplers = ["albedoSampler", "reflectivitySampler", "ambientSampler", "emissiveSampler", 
@@ -999,6 +990,7 @@
             this._uniformBuffer.addUniform("reflectivityMatrix", 16);
             this._uniformBuffer.addUniform("microSurfaceSamplerMatrix", 16);
             this._uniformBuffer.addUniform("bumpMatrix", 16);
+            this._uniformBuffer.addUniform("vNormalReoderParams", 4);
             this._uniformBuffer.addUniform("refractionMatrix", 16);
             this._uniformBuffer.addUniform("reflectionMatrix", 16);
 
@@ -1130,6 +1122,12 @@
                         if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled && !this._disableBumpMap) {
                             this._uniformBuffer.updateFloat3("vBumpInfos", this._bumpTexture.coordinatesIndex, this._bumpTexture.level, this._parallaxScaleBias);
                             MaterialHelper.BindTextureMatrix(this._bumpTexture, this._uniformBuffer, "bump");
+
+                            if (scene._mirroredCameraPosition) {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this._invertNormalMapX ? 0 : 1.0, this._invertNormalMapX ? 1.0 : -1.0, this._invertNormalMapY ? 0 : 1.0, this._invertNormalMapY ? 1.0 : -1.0);
+                            } else {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this._invertNormalMapX ? 1.0 : 0, this._invertNormalMapX ? -1.0 : 1.0, this._invertNormalMapY ? 1.0 : 0, this._invertNormalMapY ? -1.0 : 1.0);
+                            }                                                         
                         }
 
                         var refractionTexture = this._getRefractionTexture();

+ 8 - 12
src/Materials/babylon.standardMaterial.ts

@@ -62,8 +62,6 @@ module BABYLON {
         public REFRACTION = false;
         public REFRACTIONMAP_3D = false;
         public REFLECTIONOVERALPHA = false;
-        public INVERTNORMALMAPX = false;
-        public INVERTNORMALMAPY = false;
         public TWOSIDEDLIGHTING = false;
         public SHADOWFLOAT = false;
         public MORPHTARGETS = false;
@@ -640,9 +638,6 @@ module BABYLON {
                         } else {
                             MaterialHelper.PrepareDefinesForMergedUV(this._bumpTexture, defines, "BUMP");
 
-                            defines.INVERTNORMALMAPX = this.invertNormalMapX;
-                            defines.INVERTNORMALMAPY = this.invertNormalMapY;
-
                             defines.PARALLAX = this._useParallax;
                             defines.PARALLAXOCCLUSION = this._useParallaxOcclusion;
                         }
@@ -728,12 +723,6 @@ module BABYLON {
             // Values that need to be evaluated on every frame
             MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
 
-            if (scene._mirroredCameraPosition && defines.BUMP) {
-                defines.INVERTNORMALMAPX = !this.invertNormalMapX;
-                defines.INVERTNORMALMAPY = !this.invertNormalMapY;
-                defines.markAsUnprocessed();
-            }
-
             // Get correct effect      
             if (defines.isDirty) {
                 defines.markAsProcessed();
@@ -834,7 +823,7 @@ module BABYLON {
                     "mBones",
                     "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
                     "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor", "refractionLeftColor", "refractionRightColor",
-                    "logarithmicDepthConstant"
+                    "logarithmicDepthConstant", "vNormalReoderParams"
                 ];
 
                 var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"]
@@ -911,6 +900,7 @@ module BABYLON {
             this._uniformBuffer.addUniform("lightmapMatrix", 16);
             this._uniformBuffer.addUniform("specularMatrix", 16);
             this._uniformBuffer.addUniform("bumpMatrix", 16);
+            this._uniformBuffer.addUniform("vNormalReoderParams", 4);
             this._uniformBuffer.addUniform("refractionMatrix", 16);
             this._uniformBuffer.addUniform("vRefractionInfos", 4);
             this._uniformBuffer.addUniform("vSpecularColor", 4);
@@ -1024,6 +1014,12 @@ module BABYLON {
                         if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled) {
                             this._uniformBuffer.updateFloat3("vBumpInfos", this._bumpTexture.coordinatesIndex, 1.0 / this._bumpTexture.level, this.parallaxScaleBias);
                             MaterialHelper.BindTextureMatrix(this._bumpTexture, this._uniformBuffer, "bump");
+
+                            if (scene._mirroredCameraPosition) {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this.invertNormalMapX ? 0 : 1.0, this.invertNormalMapX ? 1.0 : -1.0, this.invertNormalMapY ? 0 : 1.0, this.invertNormalMapY ? 1.0 : -1.0);
+                            } else {
+                                this._uniformBuffer.updateFloat4("vNormalReoderParams", this.invertNormalMapX ? 1.0 : 0, this.invertNormalMapX ? -1.0 : 1.0, this.invertNormalMapY ? 1.0 : 0, this.invertNormalMapY ? -1.0 : 1.0);
+                            }                           
                         }
 
                         if (this._refractionTexture && StandardMaterial.RefractionTextureEnabled) {

+ 2 - 6
src/Shaders/ShadersInclude/bumpFragmentFunctions.fx

@@ -42,12 +42,8 @@
 	{
 		vec3 map = texture2D(bumpSampler, uv).xyz;
 
-	#ifdef INVERTNORMALMAPX
-		map.x = 1.0 - map.x;
-	#endif
-	#ifdef INVERTNORMALMAPY
-		map.y = 1.0 - map.y;
-	#endif
+		map.x = vNormalReoderParams.x + vNormalReoderParams.y * map.x;
+		map.y = vNormalReoderParams.z + vNormalReoderParams.w * map.y;
 
 		map = map * 255. / 127. - 128. / 127.;
 		return normalize(cotangentFrame * map);

+ 1 - 0
src/Shaders/ShadersInclude/defaultFragmentDeclaration.fx

@@ -27,6 +27,7 @@ uniform vec2 vLightmapInfos;
 
 #ifdef BUMP
 uniform vec3 vBumpInfos;
+uniform vec4 vNormalReoderParams;
 #endif
 
 #if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)

+ 1 - 0
src/Shaders/ShadersInclude/defaultUboDeclaration.fx

@@ -27,6 +27,7 @@ uniform Material
 	mat4 lightmapMatrix;
 	mat4 specularMatrix;
 	mat4 bumpMatrix; 
+	vec4 vNormalReoderParams;
 	mat4 refractionMatrix;
 	vec4 vRefractionInfos;
 	vec4 vSpecularColor;

+ 1 - 0
src/Shaders/ShadersInclude/pbrFragmentDeclaration.fx

@@ -18,6 +18,7 @@ uniform vec3 vAmbientInfos;
 
 #ifdef BUMP
 uniform vec3 vBumpInfos;
+uniform vec4 vNormalReoderParams;
 #endif
 
 #ifdef OPACITY	

+ 1 - 0
src/Shaders/ShadersInclude/pbrUboDeclaration.fx

@@ -20,6 +20,7 @@ uniform Material
 	uniform mat4 reflectivityMatrix;
 	uniform mat4 microSurfaceSamplerMatrix;
 	uniform mat4 bumpMatrix;
+	uniform vec4 vNormalReoderParams;
 	uniform mat4 refractionMatrix;
 	uniform mat4 reflectionMatrix;