Browse Source

get post process multitarget working

Trevor Baron 6 năm trước cách đây
mục cha
commit
37564a3e4c

+ 12 - 4
src/Engines/engine.ts

@@ -5572,7 +5572,7 @@ export class Engine {
         internalTexture._depthStencilTextureArray = gl.createTexture();
         gl.bindTexture(gl.TEXTURE_2D_ARRAY, internalTexture._depthStencilTextureArray);
         (gl as any).texStorage3D(gl.TEXTURE_2D_ARRAY, 1, (gl as any).DEPTH32F_STENCIL8, width, height, 2);
-
+        internalTexture.isReady = true;
         return internalTexture;
     }
 
@@ -6446,7 +6446,12 @@ export class Engine {
 
             this._activateCurrentTexture();
 
-            this._gl.bindTexture(target, texture ? texture._webGLTexture : null);
+            if(texture && texture.isMultiview){
+                this._gl.bindTexture(target, texture ? texture._colorTextureArray : null);
+            }else{
+                this._gl.bindTexture(target, texture ? texture._webGLTexture : null);
+            }
+            
             this._boundTexturesCache[this._activeChannel] = texture;
 
             if (texture) {
@@ -6637,8 +6642,11 @@ export class Engine {
         }
 
         this._activeChannel = channel;
-
-        if (internalTexture && internalTexture.is3D) {
+        if (internalTexture && internalTexture.isMultiview) {
+            if (needToBind) {
+                this._bindTextureDirectly(this._gl.TEXTURE_2D_ARRAY, internalTexture, isPartOfTextureArray);
+            }
+        }else if (internalTexture && internalTexture.is3D) {
             if (needToBind) {
                 this._bindTextureDirectly(this._gl.TEXTURE_3D, internalTexture, isPartOfTextureArray);
             }

+ 4 - 0
src/Materials/Textures/internalTexture.ts

@@ -88,6 +88,10 @@ export class InternalTexture implements IInternalTextureTracker {
      */
     public is3D: boolean;
     /**
+     * Defines if the texture contains multiview data
+     */
+    public isMultiview: boolean;
+    /**
      * Gets the URL used to load this texture
      */
     public url: string;

+ 1 - 0
src/Materials/Textures/renderTargetTexture.ts

@@ -1014,6 +1014,7 @@ export class MultiviewRenderTarget extends RenderTargetTexture {
     constructor(public scene: Scene, size: number | { width: number, height: number } | { ratio: number } = 512) {
         super("multiview rtt", size, scene, false, true, InternalTexture.DATASOURCE_UNKNOWN, false, undefined, false, false, true, undefined, true);
         var internalTexture = scene.getEngine().createMultiviewRenderTargetTexture(this.getRenderWidth(), this.getRenderHeight());
+        internalTexture.isMultiview = true;
         this._texture = internalTexture;
     }
 

+ 3 - 8
src/scene.ts

@@ -4031,8 +4031,6 @@ export class Scene extends AbstractScene implements IAnimatable {
         this.resetCachedMaterial();
         this._renderId++;
 
-        // Bind outputRenderTarget before setting transform if needed
-        this._bindFrameBuffer();
         var useMultiview = this.getEngine().getCaps().multiview && camera.outputRenderTarget && camera.outputRenderTarget.getViewCount() > 1;
         if (useMultiview) {
             this.setTransformMatrix(camera._rigCameras[0].getViewMatrix(), camera._rigCameras[0].getProjectionMatrix(), camera._rigCameras[1].getViewMatrix(), camera._rigCameras[1].getProjectionMatrix());
@@ -4354,13 +4352,10 @@ export class Scene extends AbstractScene implements IAnimatable {
         }
 
         // Restore back buffer
-        if (this.customRenderTargets.length > 0) {
-            engine.restoreDefaultFramebuffer();
-        }
-
-        this.onAfterRenderTargetsRenderObservable.notifyObservers(this);
         this.activeCamera = currentActiveCamera;
-
+        this._bindFrameBuffer();
+        this.onAfterRenderTargetsRenderObservable.notifyObservers(this);
+        
         for (let step of this._beforeClearStage) {
             step.action();
         }