瀏覽代碼

Adding ignoreCameraViewport

In case the render target is rendered at the camera level (and not scene
level per default), in some cases like the water material, the viewport
of the camera itself should be ignored.
Raanan Weber 8 年之前
父節點
當前提交
238e9faf9e
共有 1 個文件被更改,包括 20 次插入24 次删除
  1. 20 24
      src/Materials/Textures/babylon.renderTargetTexture.ts

+ 20 - 24
src/Materials/Textures/babylon.renderTargetTexture.ts

@@ -40,7 +40,8 @@
         public activeCamera: Camera;
         public customRenderFunction: (opaqueSubMeshes: SmartArray<SubMesh>, transparentSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>, beforeTransparents?: () => void) => void;
         public useCameraPostProcesses: boolean;
-        
+        public ignoreCameraViewport: boolean = false;
+
         private _postProcessManager: PostProcessManager;
         private _postProcesses: PostProcess[];
 
@@ -50,7 +51,7 @@
         * An event triggered when the texture is unbind.
         * @type {BABYLON.Observable}
         */
-        public onBeforeBindObservable = new Observable<RenderTargetTexture>();        
+        public onBeforeBindObservable = new Observable<RenderTargetTexture>();
 
         /**
         * An event triggered when the texture is unbind.
@@ -170,7 +171,7 @@
             if (this._samples === value) {
                 return;
             }
-            
+
             this._samples = this.getScene().getEngine().updateRenderTargetTextureSampleCount(this._texture, value);
         }
 
@@ -320,7 +321,7 @@
                 return;
             }
 
-            this.onBeforeBindObservable.notifyObservers(this);            
+            this.onBeforeBindObservable.notifyObservers(this);
 
             // Set custom projection.
             // Needs to be before binding to prevent changing the aspect ratio.
@@ -329,8 +330,7 @@
                 camera = this.activeCamera;
                 engine.setViewport(this.activeCamera.viewport, this._size, this._size);
 
-                if (this.activeCamera !== scene.activeCamera)
-                {
+                if (this.activeCamera !== scene.activeCamera) {
                     scene.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix(true));
                 }
             }
@@ -356,7 +356,7 @@
                     }
 
                     mesh._preActivateForIntermediateRendering(sceneRenderId);
-                    
+
                     let isMasked;
                     if (!this.renderList) {
                         isMasked = ((mesh.layerMask & camera.layerMask) === 0);
@@ -377,17 +377,17 @@
             }
 
             for (var particleIndex = 0; particleIndex < scene.particleSystems.length; particleIndex++) {
-                    var particleSystem = scene.particleSystems[particleIndex];
+                var particleSystem = scene.particleSystems[particleIndex];
 
-                    let emitter: any = particleSystem.emitter;
-                    if (!particleSystem.isStarted() || !emitter || !emitter.position || !emitter.isEnabled()) {
-                        continue;
-                    }
+                let emitter: any = particleSystem.emitter;
+                if (!particleSystem.isStarted() || !emitter || !emitter.position || !emitter.isEnabled()) {
+                    continue;
+                }
 
-                    if (currentRenderList.indexOf(emitter) >= 0) {
-                        this._renderingManager.dispatchParticles(particleSystem);
-                    }
+                if (currentRenderList.indexOf(emitter) >= 0) {
+                    this._renderingManager.dispatchParticles(particleSystem);
                 }
+            }
 
             if (this.isCube) {
                 for (var face = 0; face < 6; face++) {
@@ -409,7 +409,7 @@
             scene.resetCachedMaterial();
         }
 
-        private renderToTarget(faceIndex: number, currentRenderList: AbstractMesh[], currentRenderListLength:number, useCameraPostProcess: boolean, dumpForDebug: boolean): void {
+        private renderToTarget(faceIndex: number, currentRenderList: AbstractMesh[], currentRenderListLength: number, useCameraPostProcess: boolean, dumpForDebug: boolean): void {
             var scene = this.getScene();
             var engine = scene.getEngine();
 
@@ -418,11 +418,7 @@
                 this._postProcessManager._prepareFrame(this._texture, this._postProcesses);
             }
             else if (!useCameraPostProcess || !scene.postProcessManager._prepareFrame(this._texture)) {
-                if (this.isCube) {
-                    engine.bindFramebuffer(this._texture, faceIndex);
-                } else {
-                    engine.bindFramebuffer(this._texture);
-                }
+                engine.bindFramebuffer(this._texture, this.isCube ? faceIndex : undefined, undefined, undefined, this.ignoreCameraViewport);
             }
 
             this.onBeforeRenderObservable.notifyObservers(faceIndex);
@@ -467,7 +463,7 @@
                 }
 
                 engine.unBindFramebuffer(this._texture, this.isCube, () => {
-                    this.onAfterRenderObservable.notifyObservers(faceIndex);    
+                    this.onAfterRenderObservable.notifyObservers(faceIndex);
                 });
             } else {
                 this.onAfterRenderObservable.notifyObservers(faceIndex);
@@ -487,7 +483,7 @@
             opaqueSortCompareFn: (a: SubMesh, b: SubMesh) => number = null,
             alphaTestSortCompareFn: (a: SubMesh, b: SubMesh) => number = null,
             transparentSortCompareFn: (a: SubMesh, b: SubMesh) => number = null): void {
-            
+
             this._renderingManager.setRenderingOrder(renderingGroupId,
                 opaqueSortCompareFn,
                 alphaTestSortCompareFn,
@@ -500,7 +496,7 @@
          * @param renderingGroupId The rendering group id corresponding to its index
          * @param autoClearDepthStencil Automatically clears depth and stencil between groups if true.
          */
-        public setRenderingAutoClearDepthStencil(renderingGroupId: number, autoClearDepthStencil: boolean): void {            
+        public setRenderingAutoClearDepthStencil(renderingGroupId: number, autoClearDepthStencil: boolean): void {
             this._renderingManager.setRenderingAutoClearDepthStencil(renderingGroupId, autoClearDepthStencil);
         }