Ver código fonte

Merge pull request #1589 from sebavan/Development

Fix Highlight and Rendering Manager
Raanan Weber 8 anos atrás
pai
commit
fdc3431d72

+ 15 - 12
src/Materials/Textures/babylon.renderTargetTexture.ts

@@ -213,12 +213,6 @@
                 useCameraPostProcess = this.useCameraPostProcesses;
             }
 
-            if (this.activeCamera && this.activeCamera !== scene.activeCamera) {
-                scene.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix(true));
-            } else {
-                scene.setTransformMatrix(scene.activeCamera.getViewMatrix(), scene.activeCamera.getProjectionMatrix(true));               
-            }
-
             if (this._waitingRenderList) {
                 this.renderList = [];
                 for (var index = 0; index < this._waitingRenderList.length; index++) {
@@ -309,12 +303,21 @@
                     engine.bindFramebuffer(this._texture);
                 }
             }
-            
-            if (this.activeCamera) {
-                engine.setViewport(this.activeCamera.viewport);
-            }
-            else {
-                engine.setViewport(scene.activeCamera.viewport);
+
+            // Set states for projection (this does not change accross faces)
+            if (!this.isCube || faceIndex === 0) {            
+                if (this.activeCamera && this.activeCamera !== scene.activeCamera) {
+                    scene.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix(true));
+                } else {
+                    scene.setTransformMatrix(scene.activeCamera.getViewMatrix(), scene.activeCamera.getProjectionMatrix(true));               
+                }
+
+                if (this.activeCamera) {
+                    engine.setViewport(this.activeCamera.viewport);
+                }
+                else {
+                    engine.setViewport(scene.activeCamera.viewport);
+                }
             }
 
             this.onBeforeRenderObservable.notifyObservers(faceIndex);

+ 28 - 8
src/Rendering/babylon.renderingManager.ts

@@ -1,4 +1,15 @@
 module BABYLON {
+
+    /**
+     * Interface describing the different options available in the rendering manager
+     * regarding Auto Clear between groups.
+     */
+    interface RenderingManageAutoClearOptions {
+        autoClear: boolean;
+        depth: boolean;
+        stencil: boolean;
+    }
+
     export class RenderingManager {
         /**
          * The max id used for rendering groups (not included)
@@ -19,7 +30,7 @@
         private _currentRenderParticles: boolean;
         private _currentRenderSprites: boolean;
 
-        private _autoClearDepthStencil: { [id:number]: boolean } = {};
+        private _autoClearDepthStencil: { [id:number]: RenderingManageAutoClearOptions } = {};
         private _customOpaqueSortCompareFn: { [id:number]: (a: SubMesh, b: SubMesh) => number } = {};
         private _customAlphaTestSortCompareFn: { [id:number]: (a: SubMesh, b: SubMesh) => number } = {};
         private _customTransparentSortCompareFn: { [id:number]: (a: SubMesh, b: SubMesh) => number } = {};
@@ -29,7 +40,7 @@
             this._scene = scene;
 
             for (let i = RenderingManager.MIN_RENDERINGGROUPS; i < RenderingManager.MAX_RENDERINGGROUPS; i++) {
-                this._autoClearDepthStencil[i] = true;
+                this._autoClearDepthStencil[i] = { autoClear: true, depth:true, stencil: true };
             }
         }
 
@@ -80,12 +91,12 @@
             this._scene._spritesDuration.endMonitoring(false);
         }
 
-        private _clearDepthStencilBuffer(): void {
+        private _clearDepthStencilBuffer(depth = true, stencil = true): void {
             if (this._depthStencilBufferAlreadyCleaned) {
                 return;
             }
 
-            this._scene.getEngine().clear(0, false, true, true);
+            this._scene.getEngine().clear(0, false, depth, stencil);
             this._depthStencilBufferAlreadyCleaned = true;
         }
 
@@ -136,8 +147,9 @@
                     }
 
                     // Clear depth/stencil if needed
-                    if (this._autoClearDepthStencil[index]) {
-                        this._clearDepthStencilBuffer();
+                    let autoClear = this._autoClearDepthStencil[index];
+                    if (autoClear && autoClear.autoClear) {
+                        this._clearDepthStencilBuffer(autoClear.depth, autoClear.stencil);
                     }
 
                     // Fire PREOPAQUE stage
@@ -234,9 +246,17 @@
          * 
          * @param renderingGroupId The rendering group id corresponding to its index
          * @param autoClearDepthStencil Automatically clears depth and stencil between groups if true.
+         * @param depth Automatically clears depth between groups if true and autoClear is true.
+         * @param stencil Automatically clears stencil between groups if true and autoClear is true.
          */
-        public setRenderingAutoClearDepthStencil(renderingGroupId: number, autoClearDepthStencil: boolean): void {            
-            this._autoClearDepthStencil[renderingGroupId] = autoClearDepthStencil;
+        public setRenderingAutoClearDepthStencil(renderingGroupId: number, autoClearDepthStencil: boolean,
+            depth = true,
+            stencil = true): void {            
+            this._autoClearDepthStencil[renderingGroupId] = { 
+                autoClear: autoClearDepthStencil,
+                depth: depth,
+                stencil: stencil
+            };
         }
     }
 } 

+ 6 - 2
src/babylon.scene.ts

@@ -3205,9 +3205,13 @@
          * 
          * @param renderingGroupId The rendering group id corresponding to its index
          * @param autoClearDepthStencil Automatically clears depth and stencil between groups if true.
+         * @param depth Automatically clears depth between groups if true and autoClear is true.
+         * @param stencil Automatically clears stencil between groups if true and autoClear is true.
          */
-        public setRenderingAutoClearDepthStencil(renderingGroupId: number, autoClearDepthStencil: boolean): void {
-            this._renderingManager.setRenderingAutoClearDepthStencil(renderingGroupId, autoClearDepthStencil);
+        public setRenderingAutoClearDepthStencil(renderingGroupId: number, autoClearDepthStencil: boolean,
+            depth = true,
+            stencil = true): void {
+            this._renderingManager.setRenderingAutoClearDepthStencil(renderingGroupId, autoClearDepthStencil, depth, stencil);
         }
     }
 }