Pārlūkot izejas kodu

Merge remote-tracking branch 'refs/remotes/BabylonJS/master' into OcclusionQueries

# Conflicts:
#	dist/preview release/babylon.d.ts
#	dist/preview release/babylon.js
#	dist/preview release/babylon.module.d.ts
#	dist/preview release/babylon.worker.js
#	dist/preview
release/customConfigurations/minimalGLTFViewer/babylon.d.ts
#	dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js
#	dist/preview
release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts
DESKTOP-QJU4N0L\mityh 8 gadi atpakaļ
vecāks
revīzija
76304e230b

+ 15 - 5
dist/preview release/babylon.max.js

@@ -7460,6 +7460,10 @@ var BABYLON;
             this._performanceMonitor = new BABYLON.PerformanceMonitor();
             this._fps = 60;
             this._deltaTime = 0;
+            /**
+             * Turn this value on if you want to pause FPS computation when in background
+             */
+            this.disablePerformanceMonitorInBackground = false;
             // States
             this._depthCullingState = new BABYLON.Internals._DepthCullingState();
             this._stencilState = new BABYLON.Internals._StencilState();
@@ -7552,11 +7556,15 @@ var BABYLON;
                     throw new Error("WebGL not supported");
                 }
                 this._onBlur = function () {
-                    _this._performanceMonitor.disable();
+                    if (_this.disablePerformanceMonitorInBackground) {
+                        _this._performanceMonitor.disable();
+                    }
                     _this._windowIsBackground = true;
                 };
                 this._onFocus = function () {
-                    _this._performanceMonitor.enable();
+                    if (_this.disablePerformanceMonitorInBackground) {
+                        _this._performanceMonitor.enable();
+                    }
                     _this._windowIsBackground = false;
                 };
                 this._onCanvasBlur = function () {
@@ -45320,7 +45328,7 @@ var BABYLON;
                 this.onClearObservable.notifyObservers(engine);
             }
             else {
-                engine.clear(scene.clearColor, true, true, true);
+                engine.clear(this.clearColor || scene.clearColor, true, true, true);
             }
             if (!this._doNotChangeAspectRatio) {
                 scene.updateTransformMatrix(true);
@@ -67732,8 +67740,10 @@ var BABYLON;
                     // Alpha test
                     if (material && material.needAlphaTesting()) {
                         var alphaTexture = material.getAlphaTestTexture();
-                        _this._glowMapGenerationEffect.setTexture("diffuseSampler", alphaTexture);
-                        _this._glowMapGenerationEffect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
+                        if (alphaTexture) {
+                            _this._glowMapGenerationEffect.setTexture("diffuseSampler", alphaTexture);
+                            _this._glowMapGenerationEffect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
+                        }
                     }
                     // Glow emissive only
                     if (emissiveTexture) {

+ 11 - 3
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -7460,6 +7460,10 @@ var BABYLON;
             this._performanceMonitor = new BABYLON.PerformanceMonitor();
             this._fps = 60;
             this._deltaTime = 0;
+            /**
+             * Turn this value on if you want to pause FPS computation when in background
+             */
+            this.disablePerformanceMonitorInBackground = false;
             // States
             this._depthCullingState = new BABYLON.Internals._DepthCullingState();
             this._stencilState = new BABYLON.Internals._StencilState();
@@ -7552,11 +7556,15 @@ var BABYLON;
                     throw new Error("WebGL not supported");
                 }
                 this._onBlur = function () {
-                    _this._performanceMonitor.disable();
+                    if (_this.disablePerformanceMonitorInBackground) {
+                        _this._performanceMonitor.disable();
+                    }
                     _this._windowIsBackground = true;
                 };
                 this._onFocus = function () {
-                    _this._performanceMonitor.enable();
+                    if (_this.disablePerformanceMonitorInBackground) {
+                        _this._performanceMonitor.enable();
+                    }
                     _this._windowIsBackground = false;
                 };
                 this._onCanvasBlur = function () {
@@ -32927,7 +32935,7 @@ var BABYLON;
                 this.onClearObservable.notifyObservers(engine);
             }
             else {
-                engine.clear(scene.clearColor, true, true, true);
+                engine.clear(this.clearColor || scene.clearColor, true, true, true);
             }
             if (!this._doNotChangeAspectRatio) {
                 scene.updateTransformMatrix(true);

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

@@ -4,10 +4,12 @@ declare module BABYLON {
         private _worldViewProjectionMatrix;
         private _scaledDiffuse;
         private _renderId;
+        private _activeLight;
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         getAlphaTestTexture(): BaseTexture;
+        activeLight: IShadowLight;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         clone(name: string): ShadowOnlyMaterial;

+ 27 - 0
dist/preview release/materialsLibrary/babylon.shadowOnlyMaterial.js

@@ -51,6 +51,16 @@ var BABYLON;
         ShadowOnlyMaterial.prototype.getAlphaTestTexture = function () {
             return null;
         };
+        Object.defineProperty(ShadowOnlyMaterial.prototype, "activeLight", {
+            get: function () {
+                return this._activeLight;
+            },
+            set: function (light) {
+                this._activeLight = light;
+            },
+            enumerable: true,
+            configurable: true
+        });
         // Methods   
         ShadowOnlyMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
             if (this.isFrozen) {
@@ -69,6 +79,23 @@ var BABYLON;
                 }
             }
             var engine = scene.getEngine();
+            // Ensure that active light is the first shadow light
+            if (this._activeLight) {
+                for (var _i = 0, _a = mesh._lightSources; _i < _a.length; _i++) {
+                    var light = _a[_i];
+                    if (light.shadowEnabled) {
+                        if (this._activeLight === light) {
+                            break; // We are good
+                        }
+                        var lightPosition = mesh._lightSources.indexOf(this._activeLight);
+                        if (lightPosition !== -1) {
+                            mesh._lightSources.splice(lightPosition, 1);
+                            mesh._lightSources.splice(0, 0, this._activeLight);
+                        }
+                        break;
+                    }
+                }
+            }
             BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
dist/preview release/materialsLibrary/babylon.shadowOnlyMaterial.min.js


+ 28 - 0
materialsLibrary/src/shadowOnly/babylon.shadowOnlyMaterial.ts

@@ -23,6 +23,7 @@ module BABYLON {
         private _worldViewProjectionMatrix = Matrix.Zero();
         private _scaledDiffuse = new Color3();
         private _renderId: number;
+        private _activeLight: IShadowLight;
 
         constructor(name: string, scene: Scene) {
             super(name, scene);
@@ -40,6 +41,14 @@ module BABYLON {
             return null;
         }
 
+        public get activeLight(): IShadowLight {
+            return this._activeLight;
+        }
+
+        public set activeLight(light: IShadowLight) {
+            this._activeLight = light;
+        }        
+
         // Methods   
         public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {   
             if (this.isFrozen) {
@@ -63,6 +72,25 @@ module BABYLON {
 
             var engine = scene.getEngine();
 
+            // Ensure that active light is the first shadow light
+            if (this._activeLight) {
+                for (var light of mesh._lightSources) {
+                    if (light.shadowEnabled) {
+                        if (this._activeLight === light) {
+                            break; // We are good
+                        }
+
+                        var lightPosition = mesh._lightSources.indexOf(this._activeLight);
+
+                        if (lightPosition !== -1) {
+                            mesh._lightSources.splice(lightPosition, 1);
+                            mesh._lightSources.splice(0, 0, this._activeLight);
+                        }
+                        break;
+                    }
+                }
+            }
+
             MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
 
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);

+ 8 - 6
src/Layer/babylon.highlightlayer.ts

@@ -9,7 +9,7 @@ module BABYLON {
     class GlowBlurPostProcess extends PostProcess {
         constructor(name: string, public direction: Vector2, public kernel: number, options: number | PostProcessOptions, camera: Camera, samplingMode: number = Texture.BILINEAR_SAMPLINGMODE, engine?: Engine, reusable?: boolean) {
             super(name, "glowBlurPostProcess", ["screenSize", "direction", "blurWidth"], null, options, camera, samplingMode, engine, reusable);
-           
+
             this.onApplyObservable.add((effect: Effect) => {
                 effect.setFloat2("screenSize", this.width, this.height);
                 effect.setVector2("direction", this.direction);
@@ -371,7 +371,7 @@ module BABYLON {
             }
             else {
                 this._horizontalBlurPostprocess = new BlurPostProcess("HighlightLayerHBP", new BABYLON.Vector2(1.0, 0), this._options.blurHorizontalSize, 1,
-                null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine());
+                    null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine());
                 this._horizontalBlurPostprocess.onApplyObservable.add(effect => {
                     effect.setFloat2("screenSize", blurTextureWidth, blurTextureHeight);
                 });
@@ -445,8 +445,10 @@ module BABYLON {
                     // Alpha test
                     if (material && material.needAlphaTesting()) {
                         var alphaTexture = material.getAlphaTestTexture();
-                        this._glowMapGenerationEffect.setTexture("diffuseSampler", alphaTexture);
-                        this._glowMapGenerationEffect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
+                        if (alphaTexture) {
+                            this._glowMapGenerationEffect.setTexture("diffuseSampler", alphaTexture);
+                            this._glowMapGenerationEffect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
+                        }
                     }
 
                     // Glow emissive only
@@ -613,7 +615,7 @@ module BABYLON {
             var previousStencilMask = engine.getStencilMask();
             var previousStencilOperationPass = engine.getStencilOperationPass();
             var previousStencilOperationFail = engine.getStencilOperationFail();
-            var previousStencilOperationDepthFail = engine.getStencilOperationDepthFail();            
+            var previousStencilOperationDepthFail = engine.getStencilOperationDepthFail();
             var previousAlphaMode = engine.getAlphaMode();
 
             // Texture
@@ -651,7 +653,7 @@ module BABYLON {
             engine.setStencilBuffer(previousStencilBuffer);
             engine.setStencilOperationPass(previousStencilOperationPass);
             engine.setStencilOperationFail(previousStencilOperationFail);
-            engine.setStencilOperationDepthFail(previousStencilOperationDepthFail);            
+            engine.setStencilOperationDepthFail(previousStencilOperationDepthFail);
 
             (<any>engine)._stencilState.reset();
 

+ 2 - 1
src/Materials/Textures/babylon.renderTargetTexture.ts

@@ -109,6 +109,7 @@
             this._onClearObserver = this.onClearObservable.add(callback);
         }
 
+        public clearColor: Color4;
         protected _size: number;
         public _generateMipMaps: boolean;
         protected _renderingManager: RenderingManager;
@@ -427,7 +428,7 @@
             if (this.onClearObservable.hasObservers()) {
                 this.onClearObservable.notifyObservers(engine);
             } else {
-                engine.clear(scene.clearColor, true, true, true);
+                engine.clear(this.clearColor || scene.clearColor, true, true, true);
             }
 
             if (!this._doNotChangeAspectRatio) {

+ 10 - 2
src/babylon.engine.ts

@@ -591,6 +591,10 @@
         private _performanceMonitor = new PerformanceMonitor();
         private _fps = 60;
         private _deltaTime = 0;
+        /**
+         * Turn this value on if you want to pause FPS computation when in background
+         */
+        public disablePerformanceMonitorInBackground = false;
 
         public get performanceMonitor(): PerformanceMonitor {
             return this._performanceMonitor;
@@ -740,12 +744,16 @@
                 }
 
                 this._onBlur = () => {
-                    this._performanceMonitor.disable();
+                    if (this.disablePerformanceMonitorInBackground) {
+                        this._performanceMonitor.disable();
+                    }
                     this._windowIsBackground = true;
                 };
 
                 this._onFocus = () => {
-                    this._performanceMonitor.enable();
+                    if (this.disablePerformanceMonitorInBackground) {
+                        this._performanceMonitor.enable();
+                    }
                     this._windowIsBackground = false;
                 };