ソースを参照

Added: - option to specify the sampling mode of a renderTargetTexture
- option to override the sampling mode used by a PostProcess effect (defaulted to NEAREST as it is faster, usually perfectly suited for full screen post process effects and consumes a bit less fillrate)
- option to add FSAA 4X antialiasing (uses passPostProcess with ratio x2 and bilinear sampling)
fixed: - bug when removing the first post process of a post processing chain

Simon Ferquel 11 年 前
コミット
f74d71849b

+ 6 - 2
Babylon/PostProcess/babylon.postProcess.js

@@ -1,7 +1,7 @@
 var BABYLON = BABYLON || {};
 
 (function () {
-    BABYLON.PostProcess = function (name, fragmentUrl, parameters, samplers, ratio, camera) {
+    BABYLON.PostProcess = function (name, fragmentUrl, parameters, samplers, ratio, camera, samplingMode) {
         this.name = name;
         this._camera = camera;
         this._scene = camera.getScene();
@@ -10,6 +10,7 @@
         this._renderRatio = ratio;
         this.width = -1;
         this.height = -1;
+        this.renderTargetSamplingMode = samplingMode ? samplingMode : BABYLON.TextureSamplingModes.NEAREST;
 
         samplers = samplers || [];
         samplers.push("textureSampler");
@@ -34,7 +35,7 @@
             }
             this.width = desiredWidth;
             this.height = desiredHeight;
-            this._texture = this._engine.createRenderTargetTexture({ width: this.width, height: this.height }, { generateMipMaps: false, generateDepthBuffer: this._camera.postProcesses.indexOf(this) === 0 });
+            this._texture = this._engine.createRenderTargetTexture({ width: this.width, height: this.height }, { generateMipMaps: false, generateDepthBuffer: this._camera.postProcesses.indexOf(this) === 0, samplingMode: this.renderTargetSamplingMode });
             if (this.onSizeChanged) {
                 this.onSizeChanged();
             }
@@ -74,6 +75,9 @@
         
         var index = this._camera.postProcesses.indexOf(this);
         this._camera.postProcesses.splice(index, 1);
+        if (index == 0 && this._camera.postProcesses.length > 0) {
+            this._camera.postProcesses[0].width = -1; // invalidate frameBuffer to hint the postprocess to create a depth buffer
+        }
     };
 
 })();

+ 31 - 3
Babylon/babylon.engine.js

@@ -1,6 +1,12 @@
 var BABYLON = BABYLON || {};
 
 (function () {
+    BABYLON.TextureSamplingModes = {
+        NEAREST : 1,
+        BILINEAR: 2,
+        TRILINEAR: 3,
+        DEFAULT : 3
+    };
     BABYLON.Engine = function (canvas, antialias) {
         this._renderingCanvas = canvas;
 
@@ -713,20 +719,42 @@
         // in the same way, generateDepthBuffer is defaulted to true
         var generateMipMaps = false;
         var generateDepthBuffer = true;
+        var samplingMode = BABYLON.TextureSamplingModes.DEFAULT;
         if (options !== undefined) {
             generateMipMaps = options.generateMipMaps === undefined ? options : options.generateMipmaps;
             generateDepthBuffer = options.generateDepthBuffer === undefined ? true : options.generateDepthBuffer;
+            if (options.samplingMode !== undefined) {
+                samplingMode = options.samplingMode;
+            }
         }
         var gl = this._gl;
 
+        
+
         var texture = gl.createTexture();
         gl.bindTexture(gl.TEXTURE_2D, texture);
 
         var width = size.width || size;
         var height = size.height || size;
-
-        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
-        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, generateMipMaps ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);
+        var magFilter = gl.NEAREST;
+        var minFilter = gl.NEAREST;
+        if (samplingMode === BABYLON.TextureSamplingModes.BILINEAR) {
+            magFilter = gl.LINEAR;
+            if (generateMipMaps) {
+                minFilter = gl.LINEAR_MIPMAP_NEAREST;
+            } else {
+                minFilter = gl.LINEAR;
+            }
+        } else if (samplingMode === BABYLON.TextureSamplingModes.TRILINEAR) {
+            magFilter = gl.LINEAR;
+            if (generateMipMaps) {
+                minFilter = gl.LINEAR_MIPMAP_LINEAR;
+            } else {
+                minFilter = gl.LINEAR;
+            }
+        }
+        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);
+        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);
         gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
         gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
         gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);

ファイルの差分が大きいため隠しています
+ 2 - 2
Samples/babylon.js


+ 1 - 0
Samples/index.html

@@ -273,6 +273,7 @@
                         <button class="buttonControlPanel" id="touchCamera">Switch to touch camera</button>
                         <button class="buttonControlPanel" id="deviceOrientationCamera">Switch to device orientation camera</button>
                         <button class="buttonControlPanel" id="toggleFxaa">Toggle FXAA (antialiasing)</button>
+                        <button class="buttonControlPanel" id="toggleFsaa4">Toggle FSAA 4X (antialiasing)</button>
                         <button class="buttonControlPanel" id="toggleBandW">Toggle Black and white</button>
                     </p>
                 </div>

+ 15 - 0
Samples/index.js

@@ -93,6 +93,8 @@
     var deviceOrientationCamera = document.getElementById("deviceOrientationCamera");
     var camerasList = document.getElementById("camerasList");
     var toggleFxaa = document.getElementById("toggleFxaa");
+    var toggleFsaa4 = document.getElementById("toggleFsaa4");
+    var toggleBandW = document.getElementById("toggleBandW");
 
     var sceneChecked;
 
@@ -610,6 +612,19 @@
             }
         }
     });
+    toggleFsaa4.addEventListener("click", function () {
+
+        if (scene && scene.activeCamera) {
+            if (scene.activeCamera.__fsaa_cookie) {
+                scene.activeCamera.__fsaa_cookie.dispose(),
+                scene.activeCamera.__fsaa_cookie = null;
+            } else {
+                var fx = new BABYLON.PassPostProcess("fsaa", 2.0, scene.activeCamera);
+                fx.renderTargetSamplingMode = BABYLON.TextureSamplingModes.BILINEAR;
+                scene.activeCamera.__fsaa_cookie = fx;
+            }
+        }
+    });
 
     // Cameras
     camerasList.addEventListener("change", function (ev) {

ファイルの差分が大きいため隠しています
+ 2 - 2
babylon.js