瀏覽代碼

enable msaa in default pipeline when availible

Trevor Baron 7 年之前
父節點
當前提交
57bdb0c942

+ 2 - 0
src/PostProcess/RenderPipeline/Pipelines/babylon.defaultRenderingPipeline.ts

@@ -382,6 +382,8 @@
             if (this._cameras !== null) {
                 this._scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(this._name, this._cameras);
             }
+
+            this._enableMSAAOnFirstPostProcess();
         }
 
         private _disposePostProcesses(): void {

+ 14 - 1
src/PostProcess/RenderPipeline/babylon.postProcessRenderPipeline.ts

@@ -10,7 +10,7 @@ module BABYLON {
         @serialize()
         public _name: string;
 
-        constructor(engine: Engine, name: string) {
+        constructor(private engine: Engine, name: string) {
             this._name = name;
 
             this._renderEffects = {};
@@ -143,6 +143,19 @@ module BABYLON {
             this._renderEffectsForIsolatedPass = new Array<PostProcessRenderEffect>();
         }
 
+        protected _enableMSAAOnFirstPostProcess():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 >= 2 && effectKeys.length > 0){
+                var postProcesses = this._renderEffects[effectKeys[0]].getPostProcesses();
+                if(postProcesses){
+                    postProcesses[0].samples = 4;
+                    return true;
+                }
+            }
+            return false;
+        }
+
         public dispose() {
            // Must be implemented by children 
         }