فهرست منبع

first batch of review

Benjamin Guignabert 4 سال پیش
والد
کامیت
4b71592447

+ 6 - 6
src/Engines/Extensions/engine.multiRender.ts

@@ -25,7 +25,7 @@ declare module "../../Engines/thinEngine" {
          * @param noDrawBuffers if set to true, the engine won't make an initializing call of drawBuffers
          * @param noDrawBuffers if set to true, the engine won't make an initializing call of drawBuffers
          * @returns the cube texture as an InternalTexture
          * @returns the cube texture as an InternalTexture
          */
          */
-        createMultipleRenderTarget(size: any, options: IMultiRenderTargetOptions, noDrawBuffers?: boolean): InternalTexture[];
+        createMultipleRenderTarget(size: any, options: IMultiRenderTargetOptions, initializeBuffers?: boolean): InternalTexture[];
 
 
         /**
         /**
          * Update the sample count for a given multiple render target texture
          * Update the sample count for a given multiple render target texture
@@ -35,7 +35,7 @@ declare module "../../Engines/thinEngine" {
          * @param noDrawBuffers if set to true, the engine won't make an initializing call of drawBuffers
          * @param noDrawBuffers if set to true, the engine won't make an initializing call of drawBuffers
          * @returns the effective sample count (could be 0 if multisample render targets are not supported)
          * @returns the effective sample count (could be 0 if multisample render targets are not supported)
          */
          */
-        updateMultipleRenderTargetTextureSampleCount(textures: Nullable<InternalTexture[]>, samples: number, noDrawBuffers?: boolean): number;
+        updateMultipleRenderTargetTextureSampleCount(textures: Nullable<InternalTexture[]>, samples: number, initializeBuffers?: boolean): number;
 
 
         /**
         /**
          * Select a subsets of attachments to draw to.
          * Select a subsets of attachments to draw to.
@@ -183,7 +183,7 @@ ThinEngine.prototype.unBindMultiColorAttachmentFramebuffer = function(textures:
     this._bindUnboundFramebuffer(null);
     this._bindUnboundFramebuffer(null);
 };
 };
 
 
-ThinEngine.prototype.createMultipleRenderTarget = function(size: any, options: IMultiRenderTargetOptions, noDrawBuffers?: boolean): InternalTexture[] {
+ThinEngine.prototype.createMultipleRenderTarget = function(size: any, options: IMultiRenderTargetOptions, initializeBuffers: boolean = true): InternalTexture[] {
     var generateMipMaps = false;
     var generateMipMaps = false;
     var generateDepthBuffer = true;
     var generateDepthBuffer = true;
     var generateStencilBuffer = false;
     var generateStencilBuffer = false;
@@ -332,7 +332,7 @@ ThinEngine.prototype.createMultipleRenderTarget = function(size: any, options: I
         textures.push(depthTexture);
         textures.push(depthTexture);
         this._internalTexturesCache.push(depthTexture);
         this._internalTexturesCache.push(depthTexture);
     }
     }
-    if (!noDrawBuffers) {
+    if (initializeBuffers) {
         gl.drawBuffers(attachments);
         gl.drawBuffers(attachments);
     }
     }
 
 
@@ -343,7 +343,7 @@ ThinEngine.prototype.createMultipleRenderTarget = function(size: any, options: I
     return textures;
     return textures;
 };
 };
 
 
-ThinEngine.prototype.updateMultipleRenderTargetTextureSampleCount = function(textures: Nullable<InternalTexture[]>, samples: number, noDrawBuffers?: boolean): number {
+ThinEngine.prototype.updateMultipleRenderTargetTextureSampleCount = function(textures: Nullable<InternalTexture[]>, samples: number, initializeBuffers: boolean = true): number {
     if (this.webGLVersion < 2 || !textures) {
     if (this.webGLVersion < 2 || !textures) {
         return 1;
         return 1;
     }
     }
@@ -415,7 +415,7 @@ ThinEngine.prototype.updateMultipleRenderTargetTextureSampleCount = function(tex
             gl.bindRenderbuffer(gl.RENDERBUFFER, null);
             gl.bindRenderbuffer(gl.RENDERBUFFER, null);
             attachments.push(attachment);
             attachments.push(attachment);
         }
         }
-        if (!noDrawBuffers) {
+        if (initializeBuffers) {
             gl.drawBuffers(attachments);
             gl.drawBuffers(attachments);
         }
         }
     } else {
     } else {

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

@@ -231,10 +231,6 @@ export class InternalTexture {
     public _lodGenerationOffset: number = 0;
     public _lodGenerationOffset: number = 0;
     /** @hidden */
     /** @hidden */
     public _depthStencilTexture: Nullable<InternalTexture>;
     public _depthStencilTexture: Nullable<InternalTexture>;
-    /** @hidden */
-    public _lastUsedRenderId = -1;
-    /** @hidden */
-    public _postProcessChannel = -1;
 
 
     // Multiview
     // Multiview
     /** @hidden */
     /** @hidden */

+ 11 - 0
src/Materials/Textures/prePassRenderTarget.ts

@@ -13,6 +13,7 @@ import { Nullable } from "../../types";
  * Note : This is an internal class, and you should NOT need to instanciate this.
  * Note : This is an internal class, and you should NOT need to instanciate this.
  * Only the `PrePassRenderer` should instanciate this class.
  * Only the `PrePassRenderer` should instanciate this class.
  * It is more likely that you need a regular `MultiRenderTarget`
  * It is more likely that you need a regular `MultiRenderTarget`
+ * @hidden
  */
  */
 export class PrePassRenderTarget extends MultiRenderTarget {
 export class PrePassRenderTarget extends MultiRenderTarget {
     /**
     /**
@@ -24,7 +25,14 @@ export class PrePassRenderTarget extends MultiRenderTarget {
      */
      */
     public imageProcessingPostProcess: ImageProcessingPostProcess;
     public imageProcessingPostProcess: ImageProcessingPostProcess;
 
 
+    /**
+     * @hidden
+     */
     public _engine: Engine;
     public _engine: Engine;
+
+    /**
+     * @hidden
+     */
     public _scene: Scene;
     public _scene: Scene;
 
 
     /**
     /**
@@ -56,6 +64,7 @@ export class PrePassRenderTarget extends MultiRenderTarget {
 
 
     /**
     /**
      * Creates a composition effect for this RT
      * Creates a composition effect for this RT
+     * @hidden
      */
      */
     public _createCompositionEffect() {
     public _createCompositionEffect() {
         this.imageProcessingPostProcess = new ImageProcessingPostProcess("prePassComposition", 1, null, undefined, this._engine);
         this.imageProcessingPostProcess = new ImageProcessingPostProcess("prePassComposition", 1, null, undefined, this._engine);
@@ -64,6 +73,7 @@ export class PrePassRenderTarget extends MultiRenderTarget {
 
 
     /**
     /**
      * Checks that the size of this RT is still adapted to the desired render size.
      * Checks that the size of this RT is still adapted to the desired render size.
+     * @hidden
      */
      */
     public _checkSize() {
     public _checkSize() {
         var	requiredWidth = this._engine.getRenderWidth(true);
         var	requiredWidth = this._engine.getRenderWidth(true);
@@ -92,6 +102,7 @@ export class PrePassRenderTarget extends MultiRenderTarget {
 
 
     /**
     /**
      * Resets the post processes chains applied to this RT.
      * Resets the post processes chains applied to this RT.
+     * @hidden
      */
      */
     public _resetPostProcessChain() {
     public _resetPostProcessChain() {
         this._beforeCompositionPostProcesses = [];
         this._beforeCompositionPostProcesses = [];

+ 2 - 2
src/Materials/Textures/renderTargetTexture.ts

@@ -144,7 +144,7 @@ export class RenderTargetTexture extends Texture {
     private _postProcesses: PostProcess[];
     private _postProcesses: PostProcess[];
     private _resizeObserver: Nullable<Observer<Engine>>;
     private _resizeObserver: Nullable<Observer<Engine>>;
 
 
-    private get _prePass() {
+    private get _prePassEnabled() {
         return !!this._prePassRenderTarget && this._prePassRenderTarget.enabled;
         return !!this._prePassRenderTarget && this._prePassRenderTarget.enabled;
     }
     }
 
 
@@ -865,7 +865,7 @@ export class RenderTargetTexture extends Texture {
      */
      */
     public _prepareFrame(scene: Scene, faceIndex?: number, layer?: number, useCameraPostProcess?: boolean) {
     public _prepareFrame(scene: Scene, faceIndex?: number, layer?: number, useCameraPostProcess?: boolean) {
         if (this._postProcessManager) {
         if (this._postProcessManager) {
-            if (!this._prePass) {
+            if (!this._prePassEnabled) {
                 this._postProcessManager._prepareFrame(this._texture, this._postProcesses);
                 this._postProcessManager._prepareFrame(this._texture, this._postProcesses);
             }
             }
         }
         }

+ 26 - 24
src/PostProcesses/postProcess.ts

@@ -28,6 +28,8 @@ declare type PrePassEffectConfiguration = import("../Rendering/prePassEffectConf
  */
  */
 export type PostProcessOptions = { width: number, height: number };
 export type PostProcessOptions = { width: number, height: number };
 
 
+type TextureCache = {texture: InternalTexture, postProcessChannel: number, lastUsedRenderId : number};
+
 /**
 /**
  * PostProcess can be used to apply a shader to a texture after it has been rendered
  * PostProcess can be used to apply a shader to a texture after it has been rendered
  * See https://doc.babylonjs.com/how_to/how_to_use_postprocesses
  * See https://doc.babylonjs.com/how_to/how_to_use_postprocesses
@@ -178,7 +180,7 @@ export class PostProcess {
     * Smart array of input and output textures for the post process.
     * Smart array of input and output textures for the post process.
     * @hidden
     * @hidden
     */
     */
-    private _textureCache: InternalTexture[] = [];
+    private _textureCache: TextureCache[] = [];
     /**
     /**
     * The index in _textures that corresponds to the output texture.
     * The index in _textures that corresponds to the output texture.
     * @hidden
     * @hidden
@@ -492,16 +494,15 @@ export class PostProcess {
 
 
     private _createRenderTargetTexture(textureSize: { width: number, height: number }, textureOptions: RenderTargetCreationOptions, channel = 0) {
     private _createRenderTargetTexture(textureSize: { width: number, height: number }, textureOptions: RenderTargetCreationOptions, channel = 0) {
         for (let i = 0; i < this._textureCache.length; i++) {
         for (let i = 0; i < this._textureCache.length; i++) {
-            if (this._textureCache[i].width === textureSize.width &&
-                this._textureCache[i].height === textureSize.height &&
-                this._textureCache[i]._postProcessChannel === channel) {
-                return this._textureCache[i];
+            if (this._textureCache[i].texture.width === textureSize.width &&
+                this._textureCache[i].texture.height === textureSize.height &&
+                this._textureCache[i].postProcessChannel === channel) {
+                return this._textureCache[i].texture;
             }
             }
         }
         }
 
 
         const tex = this._engine.createRenderTargetTexture(textureSize, textureOptions);
         const tex = this._engine.createRenderTargetTexture(textureSize, textureOptions);
-        tex._postProcessChannel = channel;
-        this._textureCache.push(tex);
+        this._textureCache.push({ texture: tex, postProcessChannel: channel, lastUsedRenderId : -1 });
 
 
         return tex;
         return tex;
     }
     }
@@ -510,16 +511,16 @@ export class PostProcess {
         const currentRenderId = this._renderId;
         const currentRenderId = this._renderId;
 
 
         for (let i = this._textureCache.length - 1; i >= 0; i--) {
         for (let i = this._textureCache.length - 1; i >= 0; i--) {
-            if (currentRenderId - this._textureCache[i]._lastUsedRenderId > 100) {
+            if (currentRenderId - this._textureCache[i].lastUsedRenderId > 100) {
                 let currentlyUsed = false;
                 let currentlyUsed = false;
                 for (var j = 0; j < this._textures.length; j++) {
                 for (var j = 0; j < this._textures.length; j++) {
-                    if (this._textures.data[j] === this._textureCache[i]) {
+                    if (this._textures.data[j] === this._textureCache[i].texture) {
                         currentlyUsed = true;
                         currentlyUsed = true;
                     }
                     }
                 }
                 }
 
 
                 if (!currentlyUsed) {
                 if (!currentlyUsed) {
-                    this._engine._releaseTexture(this._textureCache[i]);
+                    this._engine._releaseTexture(this._textureCache[i].texture);
                     this._textureCache.splice(i, 1);
                     this._textureCache.splice(i, 1);
                 }
                 }
             }
             }
@@ -633,7 +634,18 @@ export class PostProcess {
             this.height = this._forcedOutputTexture.height;
             this.height = this._forcedOutputTexture.height;
         } else {
         } else {
             target = this.inputTexture;
             target = this.inputTexture;
-            target._lastUsedRenderId = this._renderId;
+
+            let cache;
+            for (let i = 0; i < this._textureCache.length; i++) {
+                if (this._textureCache[i].texture === target) {
+                    cache = this._textureCache[i];
+                    break;
+                }
+            }
+
+            if (cache) {
+                cache.lastUsedRenderId = this._renderId;
+            }
         }
         }
 
 
         // Bind the input of this post process to be used as the output of the previous post process.
         // Bind the input of this post process to be used as the output of the previous post process.
@@ -736,26 +748,16 @@ export class PostProcess {
             return;
             return;
         }
         }
 
 
-        if (this._textures.length > 0) {
-            for (var i = 0; i < this._textures.length; i++) {
-                this._engine._releaseTexture(this._textures.data[i]);
-
-                const cacheIndex = this._textureCache.indexOf(this._textures.data[i]);
-                if (cacheIndex !== -1) {
-                    this._textureCache.splice(cacheIndex, 1);
-                }
-            }
-        }
-
         this._disposeTextureCache();
         this._disposeTextureCache();
         this._textures.dispose();
         this._textures.dispose();
     }
     }
 
 
     private _disposeTextureCache() {
     private _disposeTextureCache() {
         for (let i = this._textureCache.length - 1; i >= 0; i--) {
         for (let i = this._textureCache.length - 1; i >= 0; i--) {
-            this._engine._releaseTexture(this._textureCache[i]);
-            this._textureCache.splice(i, 1);
+            this._engine._releaseTexture(this._textureCache[i].texture);
         }
         }
+
+        this._textureCache.length = 0;
     }
     }
 
 
     /**
     /**

+ 3 - 3
src/Rendering/prePassRenderer.ts

@@ -157,7 +157,7 @@ export class PrePassRenderer {
     /**
     /**
      * Prevents the PrePassRenderer from using the GeometryBufferRenderer as a fallback
      * Prevents the PrePassRenderer from using the GeometryBufferRenderer as a fallback
      */
      */
-    public doNotUseGeometryRendererFallback = true;
+    public doNotUseGeometryRendererFallback = false;
 
 
     private _refreshGeometryBufferRendererLink() {
     private _refreshGeometryBufferRendererLink() {
         if (!this.doNotUseGeometryRendererFallback) {
         if (!this.doNotUseGeometryRendererFallback) {
@@ -230,7 +230,7 @@ export class PrePassRenderer {
      */
      */
     public _createRenderTarget(name: string, renderTargetTexture: Nullable<RenderTargetTexture>) : PrePassRenderTarget {
     public _createRenderTarget(name: string, renderTargetTexture: Nullable<RenderTargetTexture>) : PrePassRenderTarget {
         const rt = new PrePassRenderTarget(name, renderTargetTexture, { width: this._engine.getRenderWidth(), height: this._engine.getRenderHeight() }, 0, this._scene,
         const rt = new PrePassRenderTarget(name, renderTargetTexture, { width: this._engine.getRenderWidth(), height: this._engine.getRenderHeight() }, 0, this._scene,
-            { generateMipMaps: false, generateStencilBuffer: true, defaultType: Constants.TEXTURETYPE_UNSIGNED_INT, types: [], drawOnlyOnFirstAttachmentByDefault: true });
+            { generateMipMaps: false, generateStencilBuffer: this._engine.isStencilEnable, defaultType: Constants.TEXTURETYPE_UNSIGNED_INT, types: [], drawOnlyOnFirstAttachmentByDefault: true });
 
 
         this.renderTargets.push(rt);
         this.renderTargets.push(rt);
 
 
@@ -241,7 +241,7 @@ export class PrePassRenderer {
      * Indicates if rendering a prepass is supported
      * Indicates if rendering a prepass is supported
      */
      */
     public get isSupported() {
     public get isSupported() {
-        return this._engine.webGLVersion > 1 || this._scene.getEngine().getCaps().drawBuffersExtension;
+        return this._scene.getEngine().getCaps().drawBuffersExtension;
     }
     }
 
 
     /**
     /**

+ 1 - 1
src/Shaders/ShadersInclude/pbrFragmentDeclaration.fx

@@ -49,7 +49,7 @@ uniform vec2 vMicroSurfaceSamplerInfos;
 #endif
 #endif
 
 
 // Refraction Reflection
 // Refraction Reflection
-#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(SS_REFRACTION)
+#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(SS_REFRACTION) || defined(PREPASS)
 uniform mat4 view;
 uniform mat4 view;
 #endif
 #endif
 
 

+ 0 - 1
src/Shaders/geometry.fragment.fx

@@ -5,7 +5,6 @@
 #endif
 #endif
 
 
 precision highp float;
 precision highp float;
-precision highp int;
 
 
 #ifdef BUMP
 #ifdef BUMP
 varying mat4 vWorldView;
 varying mat4 vWorldView;

+ 0 - 1
src/Shaders/geometry.vertex.fx

@@ -1,5 +1,4 @@
 precision highp float;
 precision highp float;
-precision highp int;
 
 
 #include<bonesDeclaration>
 #include<bonesDeclaration>