Jelajahi Sumber

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