Parcourir la source

Fix MSAA Samples overflow on post process.

sebavan il y a 6 ans
Parent
commit
467f5ab45b

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

@@ -261,7 +261,7 @@ Engine.prototype.updateMultipleRenderTargetTextureSampleCount = function(texture
 
     var gl = this._gl;
 
-    samples = Math.min(samples, gl.getParameter(gl.MAX_SAMPLES));
+    samples = Math.min(samples, this.getCaps().maxMSAASamples);
 
     // Dispose previous render buffers
     if (textures[0]._depthStencilBuffer) {

+ 4 - 1
src/Engines/engine.ts

@@ -193,6 +193,8 @@ export class EngineCapabilities {
     public parallelShaderCompile: {
         COMPLETION_STATUS_KHR: number;
     };
+    /** Max number of texture samples for MSAA */
+    public maxMSAASamples = 1;
 }
 
 /** Interface defining initialization parameters for Engine class */
@@ -1467,6 +1469,7 @@ export class Engine {
         // Draw buffers
         if (this._webGLVersion > 1) {
             this._caps.drawBuffersExtension = true;
+            this._caps.maxMSAASamples = this._gl.getParameter(this._gl.MAX_SAMPLES);
         } else {
             var drawBuffersExtension = this._gl.getExtension('WEBGL_draw_buffers');
 
@@ -4932,7 +4935,7 @@ export class Engine {
 
         var gl = this._gl;
 
-        samples = Math.min(samples, gl.getParameter(gl.MAX_SAMPLES));
+        samples = Math.min(samples, this.getCaps().maxMSAASamples);
 
         // Dispose previous render buffers
         if (texture._depthStencilBuffer) {

+ 2 - 2
src/PostProcesses/RenderPipeline/postProcessRenderPipeline.ts

@@ -201,12 +201,12 @@ export class PostProcessRenderPipeline {
     }
 
     protected _enableMSAAOnFirstPostProcess(sampleCount: number): boolean {
-        // Set samples of the very first post process to 4 to enable native anti-aliasing in browsers that support webGL 2.0 (See: https://github.com/BabylonJS/Babylon.js/issues/3754)
-        var effectKeys = Object.keys(this._renderEffects);
         if (this.engine.webGLVersion === 1) {
             return false;
         }
 
+        // Set samples of the very first post process to 4 to enable native anti-aliasing in browsers that support webGL 2.0 (See: https://github.com/BabylonJS/Babylon.js/issues/3754)
+        var effectKeys = Object.keys(this._renderEffects);
         if (effectKeys.length > 0) {
             var postProcesses = this._renderEffects[effectKeys[0]].getPostProcesses();
             if (postProcesses) {

+ 1 - 1
src/PostProcesses/postProcess.ts

@@ -113,7 +113,7 @@ export class PostProcess {
     }
 
     public set samples(n: number) {
-        this._samples = n;
+        this._samples = Math.min(n, this._engine.getCaps().maxMSAASamples);
 
         this._textures.forEach((texture) => {
             if (texture.samples !== this._samples) {