ソースを参照

BindClipPlane + BindLogDepth

David Catuhe 9 年 前
コミット
d13132cceb

ファイルの差分が大きいため隠しています
+ 22 - 32
dist/preview release/babylon.core.js


ファイルの差分が大きいため隠しています
+ 3338 - 3335
dist/preview release/babylon.d.ts


ファイルの差分が大きいため隠しています
+ 26 - 36
dist/preview release/babylon.js


ファイルの差分が大きいため隠しています
+ 4842 - 4833
dist/preview release/babylon.max.js


ファイルの差分が大きいため隠しています
+ 25 - 35
dist/preview release/babylon.noworker.js


+ 3 - 22
materialsLibrary/dist/babylon.pbrMaterial.js

@@ -226,22 +226,7 @@ var BABYLON;
                     continue;
                 }
                 this._lightRadiuses[lightIndex] = light.radius;
-                if (light instanceof BABYLON.PointLight) {
-                    // Point Light
-                    light.transferToEffect(effect, "vLightData" + lightIndex);
-                }
-                else if (light instanceof BABYLON.DirectionalLight) {
-                    // Directional Light
-                    light.transferToEffect(effect, "vLightData" + lightIndex);
-                }
-                else if (light instanceof BABYLON.SpotLight) {
-                    // Spot Light
-                    light.transferToEffect(effect, "vLightData" + lightIndex, "vLightDirection" + lightIndex);
-                }
-                else if (light instanceof BABYLON.HemisphericLight) {
-                    // Hemispheric Light
-                    light.transferToEffect(effect, "vLightData" + lightIndex, "vLightGround" + lightIndex);
-                }
+                BABYLON.MaterialHelper.BindLightProperties(light, effect, lightIndex);
                 // GAMMA CORRECTION.
                 this.convertColorToLinearSpaceToRef(light.diffuse, PBRMaterial._scaledAlbedo, useScalarInLinearSpace);
                 PBRMaterial._scaledAlbedo.scaleToRef(light.intensity, PBRMaterial._scaledAlbedo);
@@ -713,9 +698,7 @@ var BABYLON;
                     }
                 }
                 // Clip plane
-                if (this._myScene.clipPlane) {
-                    this._effect.setFloat4("vClipPlane", this._myScene.clipPlane.normal.x, this._myScene.clipPlane.normal.y, this._myScene.clipPlane.normal.z, this._myScene.clipPlane.d);
-                }
+                BABYLON.MaterialHelper.BindClipPlane(this._effect, this._myScene);
                 // Point size
                 if (this.pointsCloud) {
                     this._effect.setFloat("pointSize", this.pointSize);
@@ -779,9 +762,7 @@ var BABYLON;
                 this._overloadedMicroSurface.z = this.overloadedReflectionIntensity;
                 this._effect.setVector3("vOverloadedMicroSurface", this._overloadedMicroSurface);
                 // Log. depth
-                if (this._defines.LOGARITHMICDEPTH) {
-                    this._effect.setFloat("logarithmicDepthConstant", 2.0 / (Math.log(this._myScene.activeCamera.maxZ + 1.0) / Math.LN2));
-                }
+                BABYLON.MaterialHelper.BindLogDepth(this._defines, this._effect, this._myScene);
             }
             _super.prototype.bind.call(this, world, mesh);
             this._myScene = null;

ファイルの差分が大きいため隠しています
+ 2 - 2
materialsLibrary/dist/babylon.pbrMaterial.min.js


ファイルの差分が大きいため隠しています
+ 1 - 2
materialsLibrary/dist/babylon.simpleMaterial.js


ファイルの差分が大きいため隠しています
+ 1 - 1
materialsLibrary/dist/babylon.simpleMaterial.min.js


+ 3 - 22
materialsLibrary/materials/pbr/babylon.pbrMaterial.ts

@@ -278,19 +278,7 @@ module BABYLON {
                 
                 this._lightRadiuses[lightIndex] = light.radius;
 
-                if (light instanceof PointLight) {
-                    // Point Light
-                    light.transferToEffect(effect, "vLightData" + lightIndex);
-                } else if (light instanceof DirectionalLight) {
-                    // Directional Light
-                    light.transferToEffect(effect, "vLightData" + lightIndex);
-                } else if (light instanceof SpotLight) {
-                    // Spot Light
-                    light.transferToEffect(effect, "vLightData" + lightIndex, "vLightDirection" + lightIndex);
-                } else if (light instanceof HemisphericLight) {
-                    // Hemispheric Light
-                    light.transferToEffect(effect, "vLightData" + lightIndex, "vLightGround" + lightIndex);
-                }
+                MaterialHelper.BindLightProperties(light, effect, lightIndex);
 
                 // GAMMA CORRECTION.
                 this.convertColorToLinearSpaceToRef(light.diffuse, PBRMaterial._scaledAlbedo, useScalarInLinearSpace);
@@ -890,12 +878,7 @@ module BABYLON {
                 }
 
                 // Clip plane
-                if (this._myScene.clipPlane) {
-                    this._effect.setFloat4("vClipPlane", this._myScene.clipPlane.normal.x,
-                        this._myScene.clipPlane.normal.y,
-                        this._myScene.clipPlane.normal.z,
-                        this._myScene.clipPlane.d);
-                }
+                MaterialHelper.BindClipPlane(this._effect, this._myScene);
 
                 // Point size
                 if (this.pointsCloud) {
@@ -977,9 +960,7 @@ module BABYLON {
                 this._effect.setVector3("vOverloadedMicroSurface", this._overloadedMicroSurface);
 
                 // Log. depth
-                if (this._defines.LOGARITHMICDEPTH) {
-                    this._effect.setFloat("logarithmicDepthConstant", 2.0 / (Math.log(this._myScene.activeCamera.maxZ + 1.0) / Math.LN2));
-                }
+                MaterialHelper.BindLogDepth(this._defines, this._effect, this._myScene);
             }
             super.bind(world, mesh);
 

ファイルの差分が大きいため隠しています
+ 4842 - 4833
materialsLibrary/test/refs/babylon.max.js


+ 174 - 174
src/Materials/Textures/babylon.hdrcubetexture.ts

@@ -1,174 +1,174 @@
-module BABYLON {
-    export class HDRCubeTexture extends BaseTexture {
-        public url: string;
-        public coordinatesMode = Texture.CUBIC_MODE;
-        
-        private _useInGammaSpace = false;
-        private _generateHarmonics = true;
-        private _noMipmap: boolean;
-        private _extensions: string[];
-        private _textureMatrix: Matrix;
-        private _size: number;
-        
-        private static _facesMapping = [
-            "left",
-            "down",
-            "front",
-            "right",
-            "up",
-            "back"
-        ]; 
-
-        public sphericalPolynomial: SphericalPolynomial = null;
-        
-        constructor(url: string, scene: Scene, size:number, noMipmap = false, generateHarmonics = true, useInGammaSpace = false) {
-            super(scene);
-
-            this.name = url;
-            this.url = url;
-            this._noMipmap = noMipmap;
-            this.hasAlpha = false;
-            this._size = size;
-            this._useInGammaSpace = useInGammaSpace;
-
-            if (!url) {
-                return;
-            }
-
-            this._texture = this._getFromCache(url, noMipmap);
-
-            if (!this._texture) {
-                if (!scene.useDelayedTextureLoading) {
-                    this.loadTexture();
-                } else {
-                    this.delayLoadState = Engine.DELAYLOADSTATE_NOTLOADED;
-                }
-            }
-
-            this.isCube = true;
-
-            this._textureMatrix = Matrix.Identity();
-        }
-        
-        private loadTexture() {
-            var callback = (buffer: ArrayBuffer) => {
-                // Extract the raw linear data.
-                var data = BABYLON.Internals.HDRTools.GetCubeMapTextureData(buffer, this._size);
-                
-                // Generate harmonics if needed.
-                if (this._generateHarmonics) {
-                    this.sphericalPolynomial = BABYLON.Internals.CubeMapToSphericalPolynomialTools.ConvertCubeMapToSphericalPolynomial(data);
-                }
-                
-                var results = [];
-                var byteArray: Uint8Array = null;
-                
-                // Create uintarray fallback.
-                if (!this.getScene().getEngine().getCaps().textureFloat) {
-                    // 3 channels of 1 bytes per pixel in bytes.
-                    var byteBuffer = new ArrayBuffer(this._size * this._size * 3);
-                    byteArray = new Uint8Array(byteBuffer);
-                }
-                
-                // Push each faces.
-                for (var j = 0; j < 6; j++) {
-                    var dataFace = <Float32Array>data[HDRCubeTexture._facesMapping[j]];
-                    
-                    // If special cases.
-                    if (this._useInGammaSpace || byteArray) {
-                        for(var i = 0; i < this._size * this._size; i++) {
-                             
-                             // Put in gamma space if requested.
-                             if (this._useInGammaSpace) {
-                                dataFace[(i * 3) + 0] = Math.pow(dataFace[(i * 3) + 0], BABYLON.ToGammaSpace);
-                                dataFace[(i * 3) + 1] = Math.pow(dataFace[(i * 3) + 1], BABYLON.ToGammaSpace);
-                                dataFace[(i * 3) + 2] = Math.pow(dataFace[(i * 3) + 2], BABYLON.ToGammaSpace);
-                             }
-                             
-                             // Convert to int texture for fallback.
-                             if (byteArray) {
-                                 // R
-                                 byteArray[(i * 3) + 0] = dataFace[(i * 3) + 0] * 255;
-                                 byteArray[(i * 3) + 0] = Math.min(255, byteArray[(i * 3) + 0]);
-                                 // G
-                                 byteArray[(i * 3) + 1] = dataFace[(i * 3) + 1] * 255;
-                                 byteArray[(i * 3) + 1] = Math.min(255, byteArray[(i * 3) + 1]);
-                                 // B
-                                 byteArray[(i * 3) + 2] = dataFace[(i * 3) + 2] * 255;
-                                 byteArray[(i * 3) + 2] = Math.min(255, byteArray[(i * 3) + 2]);
-                             }
-                         }
-                    }
-
-                    results.push(dataFace);
-                }
-                return results;
-            }
-
-            this._texture = (<any>this.getScene().getEngine()).createRawCubeTexture(this.url, this.getScene(), this._size, Engine.TEXTUREFORMAT_RGB, Engine.TEXTURETYPE_FLOAT, this._noMipmap, callback);
-        }
-
-        public clone(): HDRCubeTexture {
-            var newTexture = new HDRCubeTexture(this.url, this.getScene(), this._size, this._noMipmap,
-                this._generateHarmonics, this._useInGammaSpace);
-
-            // Base texture
-            newTexture.level = this.level;
-            newTexture.wrapU = this.wrapU;
-            newTexture.wrapV = this.wrapV;
-            newTexture.coordinatesIndex = this.coordinatesIndex;
-            newTexture.coordinatesMode = this.coordinatesMode;
-            
-            return newTexture;
-        }
-
-        // Methods
-        public delayLoad(): void {
-            if (this.delayLoadState !== Engine.DELAYLOADSTATE_NOTLOADED) {
-                return;
-            }
-
-            this.delayLoadState = Engine.DELAYLOADSTATE_LOADED;
-            this._texture = this._getFromCache(this.url, this._noMipmap);
-
-            if (!this._texture) {
-                this.loadTexture();
-            }
-        }
-
-        public getReflectionTextureMatrix(): Matrix {
-            return this._textureMatrix;
-        }
-        
-        public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): HDRCubeTexture {
-            var texture = null;
-            if (parsedTexture.name && !parsedTexture.isRenderTarget) {
-                texture = new BABYLON.HDRCubeTexture(rootUrl + parsedTexture.name, scene, parsedTexture.size,
-                    texture.generateHarmonics, texture.useInGammaSpace);
-                texture.name = parsedTexture.name;
-                texture.hasAlpha = parsedTexture.hasAlpha;
-                texture.level = parsedTexture.level;
-                texture.coordinatesMode = parsedTexture.coordinatesMode;
-            }
-            return texture;
-        }
-
-        public serialize(): any {
-            if (!this.name) {
-                return null;
-            }
-
-            var serializationObject: any = {};
-            serializationObject.name = this.name;
-            serializationObject.hasAlpha = this.hasAlpha;
-            serializationObject.isCube = true;
-            serializationObject.level = this.level;
-            serializationObject.size = this._size;
-            serializationObject.coordinatesMode = this.coordinatesMode;
-            serializationObject.useInGammaSpace = this._useInGammaSpace;
-            serializationObject.generateHarmonics = this._generateHarmonics;
-
-            return serializationObject;
-        }
-    }
-} 
+module BABYLON {
+    export class HDRCubeTexture extends BaseTexture {
+        public url: string;
+        public coordinatesMode = Texture.CUBIC_MODE;
+
+        private _useInGammaSpace = false;
+        private _generateHarmonics = true;
+        private _noMipmap: boolean;
+        private _extensions: string[];
+        private _textureMatrix: Matrix;
+        private _size: number;
+
+        private static _facesMapping = [
+            "left",
+            "down",
+            "front",
+            "right",
+            "up",
+            "back"
+        ];
+
+        public sphericalPolynomial: SphericalPolynomial = null;
+
+        constructor(url: string, scene: Scene, size: number, noMipmap = false, generateHarmonics = true, useInGammaSpace = false) {
+            super(scene);
+
+            this.name = url;
+            this.url = url;
+            this._noMipmap = noMipmap;
+            this.hasAlpha = false;
+            this._size = size;
+            this._useInGammaSpace = useInGammaSpace;
+
+            if (!url) {
+                return;
+            }
+
+            this._texture = this._getFromCache(url, noMipmap);
+
+            if (!this._texture) {
+                if (!scene.useDelayedTextureLoading) {
+                    this.loadTexture();
+                } else {
+                    this.delayLoadState = Engine.DELAYLOADSTATE_NOTLOADED;
+                }
+            }
+
+            this.isCube = true;
+
+            this._textureMatrix = Matrix.Identity();
+        }
+
+        private loadTexture() {
+            var callback = (buffer: ArrayBuffer) => {
+                // Extract the raw linear data.
+                var data = BABYLON.Internals.HDRTools.GetCubeMapTextureData(buffer, this._size);
+                
+                // Generate harmonics if needed.
+                if (this._generateHarmonics) {
+                    this.sphericalPolynomial = BABYLON.Internals.CubeMapToSphericalPolynomialTools.ConvertCubeMapToSphericalPolynomial(data);
+                }
+
+                var results = [];
+                var byteArray: Uint8Array = null;
+                
+                // Create uintarray fallback.
+                if (!this.getScene().getEngine().getCaps().textureFloat) {
+                    // 3 channels of 1 bytes per pixel in bytes.
+                    var byteBuffer = new ArrayBuffer(this._size * this._size * 3);
+                    byteArray = new Uint8Array(byteBuffer);
+                }
+                
+                // Push each faces.
+                for (var j = 0; j < 6; j++) {
+                    var dataFace = <Float32Array>data[HDRCubeTexture._facesMapping[j]];
+                    
+                    // If special cases.
+                    if (this._useInGammaSpace || byteArray) {
+                        for (var i = 0; i < this._size * this._size; i++) {
+                             
+                            // Put in gamma space if requested.
+                            if (this._useInGammaSpace) {
+                                dataFace[(i * 3) + 0] = Math.pow(dataFace[(i * 3) + 0], BABYLON.ToGammaSpace);
+                                dataFace[(i * 3) + 1] = Math.pow(dataFace[(i * 3) + 1], BABYLON.ToGammaSpace);
+                                dataFace[(i * 3) + 2] = Math.pow(dataFace[(i * 3) + 2], BABYLON.ToGammaSpace);
+                            }
+                             
+                            // Convert to int texture for fallback.
+                            if (byteArray) {
+                                // R
+                                byteArray[(i * 3) + 0] = dataFace[(i * 3) + 0] * 255;
+                                byteArray[(i * 3) + 0] = Math.min(255, byteArray[(i * 3) + 0]);
+                                // G
+                                byteArray[(i * 3) + 1] = dataFace[(i * 3) + 1] * 255;
+                                byteArray[(i * 3) + 1] = Math.min(255, byteArray[(i * 3) + 1]);
+                                // B
+                                byteArray[(i * 3) + 2] = dataFace[(i * 3) + 2] * 255;
+                                byteArray[(i * 3) + 2] = Math.min(255, byteArray[(i * 3) + 2]);
+                            }
+                        }
+                    }
+
+                    results.push(dataFace);
+                }
+                return results;
+            }
+
+            this._texture = (<any>this.getScene().getEngine()).createRawCubeTexture(this.url, this.getScene(), this._size, Engine.TEXTUREFORMAT_RGB, Engine.TEXTURETYPE_FLOAT, this._noMipmap, callback);
+        }
+
+        public clone(): HDRCubeTexture {
+            var newTexture = new HDRCubeTexture(this.url, this.getScene(), this._size, this._noMipmap,
+                this._generateHarmonics, this._useInGammaSpace);
+
+            // Base texture
+            newTexture.level = this.level;
+            newTexture.wrapU = this.wrapU;
+            newTexture.wrapV = this.wrapV;
+            newTexture.coordinatesIndex = this.coordinatesIndex;
+            newTexture.coordinatesMode = this.coordinatesMode;
+
+            return newTexture;
+        }
+
+        // Methods
+        public delayLoad(): void {
+            if (this.delayLoadState !== Engine.DELAYLOADSTATE_NOTLOADED) {
+                return;
+            }
+
+            this.delayLoadState = Engine.DELAYLOADSTATE_LOADED;
+            this._texture = this._getFromCache(this.url, this._noMipmap);
+
+            if (!this._texture) {
+                this.loadTexture();
+            }
+        }
+
+        public getReflectionTextureMatrix(): Matrix {
+            return this._textureMatrix;
+        }
+
+        public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): HDRCubeTexture {
+            var texture = null;
+            if (parsedTexture.name && !parsedTexture.isRenderTarget) {
+                texture = new BABYLON.HDRCubeTexture(rootUrl + parsedTexture.name, scene, parsedTexture.size,
+                    texture.generateHarmonics, texture.useInGammaSpace);
+                texture.name = parsedTexture.name;
+                texture.hasAlpha = parsedTexture.hasAlpha;
+                texture.level = parsedTexture.level;
+                texture.coordinatesMode = parsedTexture.coordinatesMode;
+            }
+            return texture;
+        }
+
+        public serialize(): any {
+            if (!this.name) {
+                return null;
+            }
+
+            var serializationObject: any = {};
+            serializationObject.name = this.name;
+            serializationObject.hasAlpha = this.hasAlpha;
+            serializationObject.isCube = true;
+            serializationObject.level = this.level;
+            serializationObject.size = this._size;
+            serializationObject.coordinatesMode = this.coordinatesMode;
+            serializationObject.useInGammaSpace = this._useInGammaSpace;
+            serializationObject.generateHarmonics = this._generateHarmonics;
+
+            return serializationObject;
+        }
+    }
+} 

+ 19 - 16
src/Materials/babylon.materialHelper.js

@@ -131,6 +131,24 @@ var BABYLON;
             }
             return depthValuesAlreadySet;
         };
+        MaterialHelper.BindLightProperties = function (light, effect, lightIndex) {
+            if (light instanceof BABYLON.PointLight) {
+                // Point Light
+                light.transferToEffect(effect, "vLightData" + lightIndex);
+            }
+            else if (light instanceof BABYLON.DirectionalLight) {
+                // Directional Light
+                light.transferToEffect(effect, "vLightData" + lightIndex);
+            }
+            else if (light instanceof BABYLON.SpotLight) {
+                // Spot Light
+                light.transferToEffect(effect, "vLightData" + lightIndex, "vLightDirection" + lightIndex);
+            }
+            else if (light instanceof BABYLON.HemisphericLight) {
+                // Hemispheric Light
+                light.transferToEffect(effect, "vLightData" + lightIndex, "vLightGround" + lightIndex);
+            }
+        };
         MaterialHelper.BindLights = function (scene, mesh, effect, defines) {
             var lightIndex = 0;
             var depthValuesAlreadySet = false;
@@ -142,22 +160,7 @@ var BABYLON;
                 if (!light.canAffectMesh(mesh)) {
                     continue;
                 }
-                if (light instanceof BABYLON.PointLight) {
-                    // Point Light
-                    light.transferToEffect(effect, "vLightData" + lightIndex);
-                }
-                else if (light instanceof BABYLON.DirectionalLight) {
-                    // Directional Light
-                    light.transferToEffect(effect, "vLightData" + lightIndex);
-                }
-                else if (light instanceof BABYLON.SpotLight) {
-                    // Spot Light
-                    light.transferToEffect(effect, "vLightData" + lightIndex, "vLightDirection" + lightIndex);
-                }
-                else if (light instanceof BABYLON.HemisphericLight) {
-                    // Hemispheric Light
-                    light.transferToEffect(effect, "vLightData" + lightIndex, "vLightGround" + lightIndex);
-                }
+                MaterialHelper.BindLightProperties(light, effect, lightIndex);
                 light.diffuse.scaleToRef(light.intensity, BABYLON.Tmp.Color3[0]);
                 effect.setColor4("vLightDiffuse" + lightIndex, BABYLON.Tmp.Color3[0], light.range);
                 if (defines["SPECULARTERM"]) {

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

@@ -153,6 +153,22 @@
             return depthValuesAlreadySet;
         }
 
+        public static BindLightProperties(light: Light, effect: Effect, lightIndex: number): void {
+            if (light instanceof PointLight) {
+                // Point Light
+                light.transferToEffect(effect, "vLightData" + lightIndex);
+            } else if (light instanceof DirectionalLight) {
+                // Directional Light
+                light.transferToEffect(effect, "vLightData" + lightIndex);
+            } else if (light instanceof SpotLight) {
+                // Spot Light
+                light.transferToEffect(effect, "vLightData" + lightIndex, "vLightDirection" + lightIndex);
+            } else if (light instanceof HemisphericLight) {
+                // Hemispheric Light
+                light.transferToEffect(effect, "vLightData" + lightIndex, "vLightGround" + lightIndex);
+            }
+        }
+
         public static BindLights(scene: Scene, mesh: AbstractMesh, effect: Effect, defines: MaterialDefines) {
             var lightIndex = 0;
             var depthValuesAlreadySet = false;
@@ -167,19 +183,7 @@
                     continue;
                 }
 
-                if (light instanceof PointLight) {
-                    // Point Light
-                    light.transferToEffect(effect, "vLightData" + lightIndex);
-                } else if (light instanceof DirectionalLight) {
-                    // Directional Light
-                    light.transferToEffect(effect, "vLightData" + lightIndex);
-                } else if (light instanceof SpotLight) {
-                    // Spot Light
-                    light.transferToEffect(effect, "vLightData" + lightIndex, "vLightDirection" + lightIndex);
-                } else if (light instanceof HemisphericLight) {
-                    // Hemispheric Light
-                    light.transferToEffect(effect, "vLightData" + lightIndex, "vLightGround" + lightIndex);
-                }
+                MaterialHelper.BindLightProperties(light, effect, lightIndex);
 
                 light.diffuse.scaleToRef(light.intensity, Tmp.Color3[0]);
                 effect.setColor4("vLightDiffuse" + lightIndex, Tmp.Color3[0], light.range);

+ 2 - 1
src/Math/babylon.math.ts

@@ -1651,7 +1651,7 @@
 
             return this;
         };
-        
+
         public toRotationMatrix(result: Matrix): Quaternion {
             var xx = this.x * this.x;
             var yy = this.y * this.y;
@@ -3716,3 +3716,4 @@
     }
 }
 
+