Przeglądaj źródła

Merge pull request #2659 from RaananW/waterMaterialVRFix

Watermaterial VR Fix
David Catuhe 8 lat temu
rodzic
commit
b2da9babf4

+ 16 - 6
materialsLibrary/src/water/babylon.waterMaterial.ts

@@ -133,6 +133,8 @@ module BABYLON {
         @serialize()
         public waveSpeed: number = 1.0;
 
+        protected _renderTargets = new SmartArray<RenderTargetTexture>(16);
+
 		/*
 		* Private members
 		*/
@@ -157,8 +159,17 @@ module BABYLON {
         constructor(name: string, scene: Scene, public renderTargetSize: Vector2 = new Vector2(512, 512)) {
             super(name, scene);
 
-            // Create render targets
             this._createRenderTargets(scene, renderTargetSize);
+
+            // Create render targets
+            this.getRenderTargetTextures = (): SmartArray<RenderTargetTexture> => {
+                this._renderTargets.reset();
+                this._renderTargets.push(this._reflectionRTT);
+                this._renderTargets.push(this._refractionRTT);
+
+                return this._renderTargets;
+            }
+
         }
 
         @serialize()
@@ -468,13 +479,12 @@ module BABYLON {
             this._refractionRTT = new RenderTargetTexture(name + "_refraction", { width: renderTargetSize.x, height: renderTargetSize.y }, scene, false, true);
             this._refractionRTT.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
             this._refractionRTT.wrapV = BABYLON.Texture.MIRROR_ADDRESSMODE;
+            this._refractionRTT.ignoreCameraViewport = true;
 
             this._reflectionRTT = new RenderTargetTexture(name + "_reflection", { width: renderTargetSize.x, height: renderTargetSize.y }, scene, false, true);
             this._reflectionRTT.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
             this._reflectionRTT.wrapV = BABYLON.Texture.MIRROR_ADDRESSMODE;
-
-            scene.customRenderTargets.push(this._refractionRTT);
-            scene.customRenderTargets.push(this._reflectionRTT);
+            this._reflectionRTT.ignoreCameraViewport = true;
 
             var isVisible: boolean;
             var clipPlane = null;
@@ -498,7 +508,7 @@ module BABYLON {
                     this._mesh.isVisible = isVisible;
                 }
 
-                // Clip plane
+                // Clip plane 
                 scene.clipPlane = clipPlane;
             };
 
@@ -616,7 +626,7 @@ module BABYLON {
 
         public getClassName(): string {
             return "WaterMaterial";
-        }        
+        }
 
         // Statics
         public static Parse(source: any, scene: Scene, rootUrl: string): WaterMaterial {

+ 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);
         }