Prechádzať zdrojové kódy

Merge pull request #572 from julien-moreau/master

Adding features in BABYLON.PostProcess
David Catuhe 10 rokov pred
rodič
commit
f17a60254f

+ 7 - 5
Babylon/PostProcess/babylon.postProcess.js

@@ -1,8 +1,9 @@
 var BABYLON;
 (function (BABYLON) {
     var PostProcess = (function () {
-        function PostProcess(name, fragmentUrl, parameters, samplers, ratio, camera, samplingMode, engine, reusable, defines) {
+        function PostProcess(name, fragmentUrl, parameters, samplers, ratio, camera, samplingMode, engine, reusable, defines, textureType) {
             if (samplingMode === void 0) { samplingMode = BABYLON.Texture.NEAREST_SAMPLINGMODE; }
+            if (textureType === void 0) { textureType = BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT; }
             this.name = name;
             this.width = -1;
             this.height = -1;
@@ -21,6 +22,7 @@ var BABYLON;
             this._renderRatio = ratio;
             this.renderTargetSamplingMode = samplingMode ? samplingMode : BABYLON.Texture.NEAREST_SAMPLINGMODE;
             this._reusable = reusable || false;
+            this._textureType = textureType;
             samplers = samplers || [];
             samplers.push("textureSampler");
             this._effect = this._engine.createEffect({ vertex: "postprocess", fragment: fragmentUrl }, ["position"], parameters || [], samplers, defines !== undefined ? defines : "");
@@ -34,8 +36,8 @@ var BABYLON;
             var maxSize = camera.getEngine().getCaps().maxTextureSize;
             var desiredWidth = ((sourceTexture ? sourceTexture._width : this._engine.getRenderingCanvas().width) * this._renderRatio) | 0;
             var desiredHeight = ((sourceTexture ? sourceTexture._height : this._engine.getRenderingCanvas().height) * this._renderRatio) | 0;
-            desiredWidth = BABYLON.Tools.GetExponantOfTwo(desiredWidth, maxSize);
-            desiredHeight = BABYLON.Tools.GetExponantOfTwo(desiredHeight, maxSize);
+            desiredWidth = this._renderRatio.width || BABYLON.Tools.GetExponantOfTwo(desiredWidth, maxSize);
+            desiredHeight = this._renderRatio.height || BABYLON.Tools.GetExponantOfTwo(desiredHeight, maxSize);
             if (this.width !== desiredWidth || this.height !== desiredHeight) {
                 if (this._textures.length > 0) {
                     for (var i = 0; i < this._textures.length; i++) {
@@ -45,9 +47,9 @@ var BABYLON;
                 }
                 this.width = desiredWidth;
                 this.height = desiredHeight;
-                this._textures.push(this._engine.createRenderTargetTexture({ width: this.width, height: this.height }, { generateMipMaps: false, generateDepthBuffer: camera._postProcesses.indexOf(this) === camera._postProcessesTakenIndices[0], samplingMode: this.renderTargetSamplingMode }));
+                this._textures.push(this._engine.createRenderTargetTexture({ width: this.width, height: this.height }, { generateMipMaps: false, generateDepthBuffer: camera._postProcesses.indexOf(this) === camera._postProcessesTakenIndices[0], samplingMode: this.renderTargetSamplingMode, type: this._textureType }));
                 if (this._reusable) {
-                    this._textures.push(this._engine.createRenderTargetTexture({ width: this.width, height: this.height }, { generateMipMaps: false, generateDepthBuffer: camera._postProcesses.indexOf(this) === camera._postProcessesTakenIndices[0], samplingMode: this.renderTargetSamplingMode }));
+                    this._textures.push(this._engine.createRenderTargetTexture({ width: this.width, height: this.height }, { generateMipMaps: false, generateDepthBuffer: camera._postProcesses.indexOf(this) === camera._postProcessesTakenIndices[0], samplingMode: this.renderTargetSamplingMode, type: this._textureType }));
                 }
                 if (this.onSizeChanged) {
                     this.onSizeChanged();

+ 10 - 6
Babylon/PostProcess/babylon.postProcess.ts

@@ -2,6 +2,7 @@
     export class PostProcess {
         public onApply: (effect: Effect) => void;
         public onBeforeRender: (effect: Effect) => void;
+        public onAfterRender: (effect: Effect) => void;
         public onSizeChanged: () => void;
         public onActivate: (camera: Camera) => void;
         public width = -1;
@@ -12,13 +13,14 @@
         private _camera: Camera;
         private _scene: Scene;
         private _engine: Engine;
-        private _renderRatio: number;
+        private _renderRatio: number|any;
         private _reusable = false;
+        private _textureType: number;
         public _textures = new SmartArray<WebGLTexture>(2);
         public _currentRenderTextureInd = 0;
         private _effect: Effect;
 
-        constructor(public name: string, fragmentUrl: string, parameters: string[], samplers: string[], ratio: number, camera: Camera, samplingMode: number = Texture.NEAREST_SAMPLINGMODE, engine?: Engine, reusable?: boolean, defines?: string) {
+        constructor(public name: string, fragmentUrl: string, parameters: string[], samplers: string[], ratio: number|any, camera: Camera, samplingMode: number = Texture.NEAREST_SAMPLINGMODE, engine?: Engine, reusable?: boolean, defines?: string, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
             if (camera != null) {
                 this._camera = camera;
                 this._scene = camera.getScene();
@@ -32,6 +34,7 @@
             this._renderRatio = ratio;
             this.renderTargetSamplingMode = samplingMode ? samplingMode : Texture.NEAREST_SAMPLINGMODE;
             this._reusable = reusable || false;
+            this._textureType = textureType;
 
             samplers = samplers || [];
             samplers.push("textureSampler");
@@ -51,11 +54,12 @@
 
             var scene = camera.getScene();
             var maxSize = camera.getEngine().getCaps().maxTextureSize;
+
             var desiredWidth = ((sourceTexture ? sourceTexture._width : this._engine.getRenderingCanvas().width) * this._renderRatio) | 0;
             var desiredHeight = ((sourceTexture ? sourceTexture._height : this._engine.getRenderingCanvas().height) * this._renderRatio) | 0;
 
-            desiredWidth = Tools.GetExponantOfTwo(desiredWidth, maxSize);
-            desiredHeight = Tools.GetExponantOfTwo(desiredHeight, maxSize);
+            desiredWidth = this._renderRatio.width || Tools.GetExponantOfTwo(desiredWidth, maxSize);
+            desiredHeight = this._renderRatio.height || Tools.GetExponantOfTwo(desiredHeight, maxSize);
 
             if (this.width !== desiredWidth || this.height !== desiredHeight) {
                 if (this._textures.length > 0) {
@@ -66,10 +70,10 @@
                 }
                 this.width = desiredWidth;
                 this.height = desiredHeight;
-                this._textures.push(this._engine.createRenderTargetTexture({ width: this.width, height: this.height }, { generateMipMaps: false, generateDepthBuffer: camera._postProcesses.indexOf(this) === camera._postProcessesTakenIndices[0], samplingMode: this.renderTargetSamplingMode }));
+                this._textures.push(this._engine.createRenderTargetTexture({ width: this.width, height: this.height }, { generateMipMaps: false, generateDepthBuffer: camera._postProcesses.indexOf(this) === camera._postProcessesTakenIndices[0], samplingMode: this.renderTargetSamplingMode, type: this._textureType }));
 
                 if (this._reusable) {
-                    this._textures.push(this._engine.createRenderTargetTexture({ width: this.width, height: this.height }, { generateMipMaps: false, generateDepthBuffer: camera._postProcesses.indexOf(this) === camera._postProcessesTakenIndices[0], samplingMode: this.renderTargetSamplingMode }));
+                    this._textures.push(this._engine.createRenderTargetTexture({ width: this.width, height: this.height }, { generateMipMaps: false, generateDepthBuffer: camera._postProcesses.indexOf(this) === camera._postProcessesTakenIndices[0], samplingMode: this.renderTargetSamplingMode, type: this._textureType }));
                 }
 
                 if (this.onSizeChanged) {

+ 6 - 0
Babylon/PostProcess/babylon.postProcessManager.js

@@ -62,6 +62,9 @@ var BABYLON;
                     engine.bindBuffers(this._vertexBuffer, this._indexBuffer, this._vertexDeclaration, this._vertexStrideSize, effect);
                     // Draw order
                     engine.draw(true, 0, 6);
+                    if (pp.onAfterRender) {
+                        pp.onAfterRender(effect);
+                    }
                 }
             }
             // Restore depth buffer
@@ -101,6 +104,9 @@ var BABYLON;
                     engine.bindBuffers(this._vertexBuffer, this._indexBuffer, this._vertexDeclaration, this._vertexStrideSize, effect);
                     // Draw order
                     engine.draw(true, 0, 6);
+                    if (pp.onAfterRender) {
+                        pp.onAfterRender(effect);
+                    }
                 }
             }
             // Restore depth buffer

+ 8 - 0
Babylon/PostProcess/babylon.postProcessManager.ts

@@ -78,6 +78,10 @@
 
                     // Draw order
                     engine.draw(true, 0, 6);
+
+                    if (pp.onAfterRender) {
+                        pp.onAfterRender(effect);
+                    }
                 }
             }
 
@@ -123,6 +127,10 @@
 
                     // Draw order
                     engine.draw(true, 0, 6);
+
+                    if (pp.onAfterRender) {
+                        pp.onAfterRender(effect);
+                    }
                 }
             }