Преглед изворни кода

Added support for invertNormalMapX and invertNormalMapY

David Catuhe пре 9 година
родитељ
комит
034111691b

Разлика између датотеке није приказан због своје велике величине
+ 11 - 11
dist/preview release/babylon.core.js


Разлика између датотеке није приказан због своје велике величине
+ 1198 - 1190
dist/preview release/babylon.d.ts


Разлика између датотеке није приказан због своје велике величине
+ 17 - 17
dist/preview release/babylon.js


Разлика између датотеке није приказан због своје велике величине
+ 35 - 12
dist/preview release/babylon.max.js


Разлика између датотеке није приказан због своје велике величине
+ 11 - 11
dist/preview release/babylon.noworker.js


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

@@ -20,7 +20,7 @@
 	  - Added a dynamic [2D Bin Packing Algorithm](http://stackoverflow.com/questions/8762569/how-is-2d-bin-packing-achieved-programmatically), ([more info here](http://www.html5gamedevs.com/topic/22565-two-new-texture-types-fonttexture-and-maptexture/)) ([nockawa](https://github.com/nockawa))
 	  - Introduced Canvas2D feature: a 2D engine to render primitives, sprites in 2D, text. Canvas2D can be displayed in Screen Space (above the 3D scene) or in World Space to be a part of the Scene. [overview](http://doc.babylonjs.com/overviews/Using_The_Canvas2D), [tutorial](http://doc.babylonjs.com/tutorials/Using_the_Canvas2D) ([nockawa](https://github.com/nockawa))	
   - **Updates**
-    - Added support for OpenGL normal maps ([deltakosh](https://github.com/deltakosh))
+    - Added support for various normal maps conventions ([deltakosh](https://github.com/deltakosh))
     - Added postprocess.enablePixelPerfectMode to avoid texture scaling/stretching when dealing with non-power of 2 resolutions. cannot be used on post-processes chain ([deltakosh](https://github.com/deltakosh))
     - Enabled other post processes to be used when also using a 3D Rig ([jcpalmer](https://github.com/Palmer-JC))
     - Added skeleton.getBoneIndexByName(boneName: string) ([dad72](https://github.com/dad72))

+ 17 - 5
src/Materials/babylon.pbrMaterial.js

@@ -75,6 +75,8 @@ var BABYLON;
             this.USEPMREMREFLECTION = false;
             this.USEPMREMREFRACTION = false;
             this.OPENGLNORMALMAP = false;
+            this.INVERTNORMALMAPX = false;
+            this.INVERTNORMALMAPY = false;
             this.rebuild();
         }
         return PBRMaterialDefines;
@@ -303,9 +305,13 @@ var BABYLON;
              */
             this.maxSimultaneousLights = 4;
             /**
-             * If sets to true, normal map will be considered following OpenGL convention.
+             * If sets to true, x component of normal map value will invert (x = 1.0 - x).
              */
-            this.useOpenGLNormalMap = false;
+            this.invertNormalMapX = false;
+            /**
+             * If sets to true, y component of normal map value will invert (y = 1.0 - y).
+             */
+            this.invertNormalMapY = false;
             this._renderTargets = new BABYLON.SmartArray(16);
             this._worldViewProjectionMatrix = BABYLON.Matrix.Zero();
             this._globalAmbientColor = new BABYLON.Color3(0, 0, 0);
@@ -551,8 +557,11 @@ var BABYLON;
                                 this._defines.PARALLAXOCCLUSION = true;
                             }
                         }
-                        if (this.useOpenGLNormalMap) {
-                            this._defines.OPENGLNORMALMAP = true;
+                        if (this.invertNormalMapX) {
+                            this._defines.INVERTNORMALMAPX = true;
+                        }
+                        if (this.invertNormalMapY) {
+                            this._defines.INVERTNORMALMAPY = true;
                         }
                     }
                 }
@@ -1242,7 +1251,10 @@ var BABYLON;
         ], PBRMaterial.prototype, "maxSimultaneousLights", void 0);
         __decorate([
             BABYLON.serialize()
-        ], PBRMaterial.prototype, "useOpenGLNormalMap", void 0);
+        ], PBRMaterial.prototype, "invertNormalMapX", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], PBRMaterial.prototype, "invertNormalMapY", void 0);
         __decorate([
             BABYLON.serialize()
         ], PBRMaterial.prototype, "useLogarithmicDepth", null);

Разлика између датотеке није приказан због своје велике величине
+ 1425 - 1413
src/Materials/babylon.pbrMaterial.ts


+ 17 - 6
src/Materials/babylon.standardMaterial.js

@@ -67,7 +67,8 @@ var BABYLON;
             this.REFRACTION = false;
             this.REFRACTIONMAP_3D = false;
             this.REFLECTIONOVERALPHA = false;
-            this.OPENGLNORMALMAP = false;
+            this.INVERTNORMALMAPX = false;
+            this.INVERTNORMALMAPY = false;
             this.rebuild();
         }
         return StandardMaterialDefines;
@@ -99,9 +100,13 @@ var BABYLON;
             this.useGlossinessFromSpecularMapAlpha = false;
             this.maxSimultaneousLights = 4;
             /**
-             * If sets to true, normal map will be considered following OpenGL convention.
+             * If sets to true, x component of normal map value will invert (x = 1.0 - x).
              */
-            this.useOpenGLNormalMap = false;
+            this.invertNormalMapX = false;
+            /**
+             * If sets to true, y component of normal map value will invert (y = 1.0 - y).
+             */
+            this.invertNormalMapY = false;
             this._renderTargets = new BABYLON.SmartArray(16);
             this._worldViewProjectionMatrix = BABYLON.Matrix.Zero();
             this._globalAmbientColor = new BABYLON.Color3(0, 0, 0);
@@ -292,8 +297,11 @@ var BABYLON;
                                 this._defines.PARALLAXOCCLUSION = true;
                             }
                         }
-                        if (this.useOpenGLNormalMap) {
-                            this._defines.OPENGLNORMALMAP = true;
+                        if (this.invertNormalMapX) {
+                            this._defines.INVERTNORMALMAPX = true;
+                        }
+                        if (this.invertNormalMapY) {
+                            this._defines.INVERTNORMALMAPY = true;
                         }
                     }
                 }
@@ -827,7 +835,10 @@ var BABYLON;
         ], StandardMaterial.prototype, "maxSimultaneousLights", void 0);
         __decorate([
             BABYLON.serialize()
-        ], StandardMaterial.prototype, "useOpenGLNormalMap", void 0);
+        ], StandardMaterial.prototype, "invertNormalMapX", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], StandardMaterial.prototype, "invertNormalMapY", void 0);
         __decorate([
             BABYLON.serialize()
         ], StandardMaterial.prototype, "useLogarithmicDepth", null);

+ 18 - 7
src/Materials/babylon.standardMaterial.ts

@@ -52,7 +52,8 @@
         public REFRACTION = false;
         public REFRACTIONMAP_3D = false;
         public REFLECTIONOVERALPHA = false;
-        public OPENGLNORMALMAP = false;
+        public INVERTNORMALMAPX = false;
+        public INVERTNORMALMAPY = false;
 
         constructor() {
             super();
@@ -166,11 +167,17 @@
         @serialize()
         public maxSimultaneousLights = 4;
 
-        /**
-         * If sets to true, normal map will be considered following OpenGL convention.
-         */
+        /**
+         * If sets to true, x component of normal map value will invert (x = 1.0 - x).
+         */
         @serialize()
-        public useOpenGLNormalMap = false;
+        public invertNormalMapX = false;
+
+        /**
+         * If sets to true, y component of normal map value will invert (y = 1.0 - y).
+         */
+        @serialize()
+        public invertNormalMapY = false;
 
         private _renderTargets = new SmartArray<RenderTargetTexture>(16);
         private _worldViewProjectionMatrix = Matrix.Zero();
@@ -394,8 +401,12 @@
                             }
                         }
 
-                        if (this.useOpenGLNormalMap) {
-                            this._defines.OPENGLNORMALMAP = true;
+                        if (this.invertNormalMapX) {
+                            this._defines.INVERTNORMALMAPX = true;
+                        }
+
+                        if (this.invertNormalMapY) {
+                            this._defines.INVERTNORMALMAPY = true;
                         }
                     }
                 }

+ 4 - 1
src/Shaders/ShadersInclude/bumpFragmentFunctions.fx

@@ -27,7 +27,10 @@
 	{
 		vec3 map = texture2D(bumpSampler, uv).xyz;
 
-	#ifdef OPENGLNORMALMAP
+	#ifdef INVERTNORMALMAPX
+		map.x = 1.0 - map.x;
+	#endif
+	#ifdef INVERTNORMALMAPY
 		map.y = 1.0 - map.y;
 	#endif