Просмотр исходного кода

Merge pull request #6648 from sebavan/master

Fix MSAA Samples overflow on post process.
sebavan 6 лет назад
Родитель
Сommit
4f1c951b54

+ 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) {

+ 16 - 4
src/Materials/effectRenderer.ts

@@ -206,7 +206,7 @@ interface EffectWrapperCreationOptions {
     /**
      * Vertex shader for the effect
      */
-    vertexShader: string;
+    vertexShader?: string;
     /**
      * Attributes to use in the shader
      */
@@ -243,11 +243,23 @@ export class EffectWrapper {
      * @param creationOptions options to create the effect
      */
     constructor(creationOptions: EffectWrapperCreationOptions) {
-        this.effect = new Effect({
+        let effectCreationOptions: any;
+        if (creationOptions.vertexShader) {
+            effectCreationOptions = {
                 fragmentSource: creationOptions.fragmentShader,
-                vertexSource: creationOptions.vertexShader || "postprocess",
+                vertexSource: creationOptions.vertexShader,
                 spectorName: creationOptions.name || "effectWrapper"
-            },
+            };
+        }
+        else {
+            effectCreationOptions = {
+                fragmentSource: creationOptions.fragmentShader,
+                vertex: "postprocess",
+                spectorName: creationOptions.name || "effectWrapper"
+            };
+        }
+
+        this.effect = new Effect(effectCreationOptions,
             creationOptions.attributeNames || ["position"],
             creationOptions.uniformNames || ["scale"],
             creationOptions.samplerNames,

+ 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) {