Przeglądaj źródła

More MaterialHelper :)

David Catuhe 9 lat temu
rodzic
commit
becad30970

+ 11 - 0
src/Materials/babylon.materialHelper.js

@@ -187,6 +187,17 @@ var BABYLON;
                 effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
             }
         };
+        MaterialHelper.BindLogDepth = function (defines, effect, scene) {
+            if (defines["LOGARITHMICDEPTH"]) {
+                effect.setFloat("logarithmicDepthConstant", 2.0 / (Math.log(scene.activeCamera.maxZ + 1.0) / Math.LN2));
+            }
+        };
+        MaterialHelper.BindClipPlane = function (effect, scene) {
+            if (scene.clipPlane) {
+                var clipPlane = scene.clipPlane;
+                effect.setFloat4("vClipPlane", clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);
+            }
+        };
         return MaterialHelper;
     })();
     BABYLON.MaterialHelper = MaterialHelper;

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

@@ -210,11 +210,24 @@
                 effect.setColor3("vFogColor", scene.fogColor);
             }
         }
+
         public static BindBonesParameters(mesh: AbstractMesh, effect: Effect): void {
             if (mesh && mesh.useBones && mesh.computeBonesUsingShaders) {
                 effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
             }
         }
 
+        public static BindLogDepth(defines: MaterialDefines, effect: Effect, scene: Scene): void {
+            if (defines["LOGARITHMICDEPTH"]) {
+                effect.setFloat("logarithmicDepthConstant", 2.0 / (Math.log(scene.activeCamera.maxZ + 1.0) / Math.LN2));
+            }
+        }
+
+        public static BindClipPlane(effect: Effect, scene: Scene): void {
+            if (scene.clipPlane) {
+                var clipPlane = scene.clipPlane;
+                effect.setFloat4("vClipPlane", clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);
+            }
+        }
     }
 }

+ 2 - 7
src/Materials/babylon.standardMaterial.js

@@ -636,10 +636,7 @@ var BABYLON;
                     }
                 }
                 // Clip plane
-                if (scene.clipPlane) {
-                    var clipPlane = scene.clipPlane;
-                    this._effect.setFloat4("vClipPlane", clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);
-                }
+                BABYLON.MaterialHelper.BindClipPlane(this._effect, scene);
                 // Point size
                 if (this.pointsCloud) {
                     this._effect.setFloat("pointSize", this.pointSize);
@@ -667,9 +664,7 @@ var BABYLON;
                 // Fog
                 BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._effect);
                 // Log. depth
-                if (this._defines.LOGARITHMICDEPTH) {
-                    this._effect.setFloat("logarithmicDepthConstant", 2.0 / (Math.log(scene.activeCamera.maxZ + 1.0) / Math.LN2));
-                }
+                BABYLON.MaterialHelper.BindLogDepth(this._defines, this._effect, scene);
             }
             _super.prototype.bind.call(this, world, mesh);
         };

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

@@ -765,10 +765,7 @@
                 }
 
                 // Clip plane
-                if (scene.clipPlane) {
-                    var clipPlane = scene.clipPlane;
-                    this._effect.setFloat4("vClipPlane", clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);
-                }
+                MaterialHelper.BindClipPlane(this._effect, scene);
 
                 // Point size
                 if (this.pointsCloud) {
@@ -805,9 +802,7 @@
                 MaterialHelper.BindFogParameters(scene, mesh, this._effect);
 
                 // Log. depth
-                if (this._defines.LOGARITHMICDEPTH) {
-                    this._effect.setFloat("logarithmicDepthConstant", 2.0 / (Math.log(scene.activeCamera.maxZ + 1.0) / Math.LN2));
-                }
+                MaterialHelper.BindLogDepth(this._defines, this._effect, scene);
             }
 
             super.bind(world, mesh);