浏览代码

resize OK

Benjamin Guignabert 5 年之前
父节点
当前提交
5c9834fe20
共有 2 个文件被更改,包括 28 次插入12 次删除
  1. 5 2
      src/Materials/Textures/multiRenderTarget.ts
  2. 23 10
      src/scene.ts

+ 5 - 2
src/Materials/Textures/multiRenderTarget.ts

@@ -187,6 +187,10 @@ export class MultiRenderTarget extends RenderTargetTexture {
 
         // Keeps references to frame buffer and stencil/depth buffer
         this._texture = this._internalTextures[0];
+
+        if (this.samples !== 1) {
+            this._getEngine()!.updateMultipleRenderTargetTextureSampleCount(this.count, this._internalTextures, this.samples);
+        }
     }
 
     private _createInternalTextures(): void {
@@ -226,9 +230,8 @@ export class MultiRenderTarget extends RenderTargetTexture {
      * @param size Define the new size
      */
     public resize(size: any) {
-        this.releaseInternalTextures();
         this._size = size;
-        this._createInternalTextures();
+        this._rebuild();
     }
 
     protected unbindFrameBuffer(engine: Engine, faceIndex: number): void {

+ 23 - 10
src/scene.ts

@@ -289,6 +289,12 @@ export class Scene extends AbstractScene implements IAnimatable {
 
     public mrtCount: number = 4;
     public highDefinitionMRT: MultiRenderTarget;
+    private mrtTypes = [
+        Constants.TEXTURETYPE_UNSIGNED_INT, // Original color
+        Constants.TEXTURETYPE_UNSIGNED_INT, // Irradiance
+        Constants.TEXTURETYPE_FLOAT, // Depth (world units)
+        Constants.TEXTURETYPE_UNSIGNED_INT
+    ];
     private multiRenderAttachments: any[];
     private defaultAttachments: any[];
     public sceneCompositorPostProcess: SceneCompositorPostProcess;
@@ -1476,17 +1482,10 @@ export class Scene extends AbstractScene implements IAnimatable {
             this._engine.onNewSceneAddedObservable.notifyObservers(this);
         }
 
-        // TODO : TEMPORARY
-        const types = [
-            Constants.TEXTURETYPE_UNSIGNED_INT, // Original color
-            Constants.TEXTURETYPE_UNSIGNED_INT, // Irradiance
-            Constants.TEXTURETYPE_FLOAT, // Depth (world units)
-            Constants.TEXTURETYPE_UNSIGNED_INT
-        ];
-
         this.highDefinitionMRT = new MultiRenderTarget("sceneHighDefinitionMRT", { width: engine.getRenderWidth(), height: engine.getRenderHeight() }, this.mrtCount, this,
-            { generateMipMaps: false, generateDepthTexture: true, defaultType: Constants.TEXTURETYPE_UNSIGNED_INT, types: types });
-        this.highDefinitionMRT.samples = 1;
+            { generateMipMaps: false, generateDepthTexture: true, defaultType: Constants.TEXTURETYPE_UNSIGNED_INT, types: this.mrtTypes });
+        this.highDefinitionMRT.samples = 8;
+
         let gl = this._engine._gl;
         this.multiRenderAttachments = [gl.COLOR_ATTACHMENT0, gl.COLOR_ATTACHMENT1, gl.COLOR_ATTACHMENT2, gl.COLOR_ATTACHMENT3];
         this.defaultAttachments = [gl.COLOR_ATTACHMENT0, gl.NONE, gl.NONE, gl.NONE];
@@ -3704,8 +3703,21 @@ export class Scene extends AbstractScene implements IAnimatable {
         }
     }
 
+    private _checkRTSize() {
+        var requiredWidth = this._engine.getRenderWidth(true);
+        var requiredHeight = this._engine.getRenderHeight(true);
+        var width = this.highDefinitionMRT.getRenderWidth();
+        var height = this.highDefinitionMRT.getRenderHeight();
+
+        if (width !== requiredWidth || height !== requiredHeight) {
+            this.highDefinitionMRT.resize({ width: requiredWidth, height: requiredHeight });
+            this.sceneCompositorPostProcess.inputTexture = this.highDefinitionMRT.getInternalTexture()!;
+        }
+    }
+
     private _bindFrameBuffer() {
         if (this.highDefinitionPipeline) {
+            this._checkRTSize();
             var internalTexture = this.highDefinitionMRT.getInternalTexture();
             if (internalTexture) {
                 this.getEngine().bindFramebuffer(internalTexture);
@@ -3714,6 +3726,7 @@ export class Scene extends AbstractScene implements IAnimatable {
             }
             return;
         }
+
         if (this.activeCamera && this.activeCamera._multiviewTexture) {
             this.activeCamera._multiviewTexture._bindFrameBuffer();
         } else if (this.activeCamera && this.activeCamera.outputRenderTarget) {