瀏覽代碼

Improved lens pipeline

David catuhe 9 年之前
父節點
當前提交
d2397bcce6

文件差異過大導致無法顯示
+ 6 - 6
dist/preview release/babylon.core.js


文件差異過大導致無法顯示
+ 1539 - 1534
dist/preview release/babylon.d.ts


文件差異過大導致無法顯示
+ 13 - 13
dist/preview release/babylon.js


文件差異過大導致無法顯示
+ 21 - 11
dist/preview release/babylon.max.js


文件差異過大導致無法顯示
+ 13 - 13
dist/preview release/babylon.noworker.js


+ 1 - 1
src/Materials/babylon.material.js

@@ -152,7 +152,7 @@ var BABYLON;
         };
         Material.prototype.trackCreation = function (onCompiled, onError) {
         };
-        Material.prototype.resetCheckReadyOnlyOnceFlag = function () {
+        Material.prototype.markDirty = function () {
             this._wasPreviouslyReady = false;
         };
         Material.prototype._preBind = function () {

+ 1 - 1
src/Materials/babylon.material.ts

@@ -167,7 +167,7 @@
         public trackCreation(onCompiled: (effect: Effect) => void, onError: (effect: Effect, errors: string) => void) {
         }
 
-        public resetCheckReadyOnlyOnceFlag(): void {
+        public markDirty(): void {
             this._wasPreviouslyReady = false;
         }
 

+ 3 - 1
src/Particles/babylon.solidParticleSystem.js

@@ -32,6 +32,7 @@ var BABYLON;
             this._axisZ = BABYLON.Axis.Z;
             this._fakeCamPos = BABYLON.Vector3.Zero();
             this._rotMatrix = new BABYLON.Matrix();
+            this._invertMatrix = new BABYLON.Matrix();
             this._rotated = BABYLON.Vector3.Zero();
             this._quaternion = new BABYLON.Quaternion();
             this._vertex = BABYLON.Vector3.Zero();
@@ -311,7 +312,8 @@ var BABYLON;
                 this._roll = this.mesh.rotation.z;
                 this._quaternionRotationYPR();
                 this._quaternionToRotationMatrix();
-                BABYLON.Vector3.TransformCoordinatesToRef(this._camera.globalPosition, this._rotMatrix, this._fakeCamPos);
+                this._rotMatrix.invertToRef(this._invertMatrix);
+                BABYLON.Vector3.TransformCoordinatesToRef(this._camera.globalPosition, this._invertMatrix, this._fakeCamPos);
                 // set two orthogonal vectors (_cam_axisX and and _cam_axisY) to the cam-mesh axis (_cam_axisZ)
                 (this._fakeCamPos).subtractToRef(this.mesh.position, this._cam_axisZ);
                 BABYLON.Vector3.CrossToRef(this._cam_axisZ, this._axisX, this._cam_axisY);

+ 0 - 7
src/Particles/babylon.solidParticleSystem.ts

@@ -634,10 +634,3 @@ module BABYLON {
         }
     }
 }
-
-
-
-
-
-
-

+ 8 - 5
src/PostProcess/babylon.lensRenderingPipeline.js

@@ -113,8 +113,12 @@ var BABYLON;
         LensRenderingPipeline.prototype.disableDepthOfField = function () { this._dofDistance = -1; };
         LensRenderingPipeline.prototype.setAperture = function (amount) { this._dofAperture = amount; };
         LensRenderingPipeline.prototype.setDarkenOutOfFocus = function (amount) { this._dofDarken = amount; };
-        LensRenderingPipeline.prototype.enablePentagonBokeh = function () { this._dofPentagon = true; };
-        LensRenderingPipeline.prototype.disablePentagonBokeh = function () { this._dofPentagon = false; };
+        LensRenderingPipeline.prototype.enablePentagonBokeh = function () {
+            this._highlightsPostProcess.updateEffect("#define PENTAGON\n");
+        };
+        LensRenderingPipeline.prototype.disablePentagonBokeh = function () {
+            this._highlightsPostProcess.updateEffect();
+        };
         LensRenderingPipeline.prototype.enableNoiseBlur = function () { this._blurNoise = true; };
         LensRenderingPipeline.prototype.disableNoiseBlur = function () { this._blurNoise = false; };
         LensRenderingPipeline.prototype.setHighlightsGain = function (amount) {
@@ -157,13 +161,12 @@ var BABYLON;
         // highlights enhancing
         LensRenderingPipeline.prototype._createHighlightsPostProcess = function (ratio) {
             var _this = this;
-            this._highlightsPostProcess = new BABYLON.PostProcess("LensHighlights", "lensHighlights", ["pentagon", "gain", "threshold", "screen_width", "screen_height"], // uniforms
+            this._highlightsPostProcess = new BABYLON.PostProcess("LensHighlights", "lensHighlights", ["gain", "threshold", "screen_width", "screen_height"], // uniforms
             [], // samplers
-            ratio, null, BABYLON.Texture.TRILINEAR_SAMPLINGMODE, this._scene.getEngine(), false);
+            ratio, null, BABYLON.Texture.TRILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, this._dofPentagon ? "#define PENTAGON\n" : "");
             this._highlightsPostProcess.onApply = function (effect) {
                 effect.setFloat('gain', _this._highlightsGain);
                 effect.setFloat('threshold', _this._highlightsThreshold);
-                effect.setBool('pentagon', _this._dofPentagon);
                 effect.setTextureFromPostProcess("textureSampler", _this._chromaticAberrationPostProcess);
                 effect.setFloat('screen_width', _this._scene.getEngine().getRenderingCanvas().width);
                 effect.setFloat('screen_height', _this._scene.getEngine().getRenderingCanvas().height);

+ 10 - 6
src/PostProcess/babylon.lensRenderingPipeline.ts

@@ -134,8 +134,12 @@ module BABYLON {
         public disableDepthOfField() { this._dofDistance = -1; }
         public setAperture(amount: number) { this._dofAperture = amount; }
         public setDarkenOutOfFocus(amount: number) { this._dofDarken = amount; }
-        public enablePentagonBokeh() { this._dofPentagon = true; }
-        public disablePentagonBokeh() { this._dofPentagon = false; }
+        public enablePentagonBokeh() {
+            this._highlightsPostProcess.updateEffect("#define PENTAGON\n");
+        }
+        public disablePentagonBokeh() {
+            this._highlightsPostProcess.updateEffect();
+        }
         public enableNoiseBlur() { this._blurNoise = true; }
         public disableNoiseBlur() { this._blurNoise = false; }
         public setHighlightsGain(amount: number) {
@@ -185,15 +189,15 @@ module BABYLON {
         // highlights enhancing
         private _createHighlightsPostProcess(ratio: number): void {
             this._highlightsPostProcess = new PostProcess("LensHighlights", "lensHighlights",
-                ["pentagon", "gain", "threshold", "screen_width", "screen_height"],      // uniforms
+                ["gain", "threshold", "screen_width", "screen_height"],      // uniforms
                 [],     // samplers
-                ratio, null, Texture.TRILINEAR_SAMPLINGMODE,
-                this._scene.getEngine(), false);
+                ratio,
+                null, Texture.TRILINEAR_SAMPLINGMODE,
+                this._scene.getEngine(), false, this._dofPentagon ? "#define PENTAGON\n" : "");
 
             this._highlightsPostProcess.onApply = (effect: Effect) => {
                 effect.setFloat('gain', this._highlightsGain);
                 effect.setFloat('threshold', this._highlightsThreshold);
-                effect.setBool('pentagon', this._dofPentagon);
                 effect.setTextureFromPostProcess("textureSampler", this._chromaticAberrationPostProcess);
                 effect.setFloat('screen_width', this._scene.getEngine().getRenderingCanvas().width);
                 effect.setFloat('screen_height', this._scene.getEngine().getRenderingCanvas().height);

+ 8 - 3
src/PostProcess/babylon.postProcess.js

@@ -23,10 +23,15 @@ var BABYLON;
             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 : "");
+            this._samplers = samplers || [];
+            this._samplers.push("textureSampler");
+            this._fragmentUrl = fragmentUrl;
+            this._parameters = parameters || [];
+            this.updateEffect(defines);
         }
+        PostProcess.prototype.updateEffect = function (defines) {
+            this._effect = this._engine.createEffect({ vertex: "postprocess", fragment: this._fragmentUrl }, ["position"], this._parameters, this._samplers, defines !== undefined ? defines : "");
+        };
         PostProcess.prototype.isReusable = function () {
             return this._reusable;
         };

+ 15 - 5
src/PostProcess/babylon.postProcess.ts

@@ -19,6 +19,9 @@
         public _textures = new SmartArray<WebGLTexture>(2);
         public _currentRenderTextureInd = 0;
         private _effect: Effect;
+        private _samplers: string[];
+        private _fragmentUrl: string;
+        private _parameters: 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) {
@@ -36,13 +39,20 @@
             this._reusable = reusable || false;
             this._textureType = textureType;
 
-            samplers = samplers || [];
-            samplers.push("textureSampler");
+            this._samplers = samplers || [];
+            this._samplers.push("textureSampler");
 
-            this._effect = this._engine.createEffect({ vertex: "postprocess", fragment: fragmentUrl },
+            this._fragmentUrl = fragmentUrl;
+            this._parameters = parameters || []
+
+            this.updateEffect(defines);
+        }
+
+        public updateEffect(defines?: string) {
+            this._effect = this._engine.createEffect({ vertex: "postprocess", fragment: this._fragmentUrl },
                 ["position"],
-                parameters || [],
-                samplers, defines !== undefined ? defines : "");
+                this._parameters,
+                this._samplers, defines !== undefined ? defines : "");
         }
 
         public isReusable(): boolean {

+ 3 - 5
src/Shaders/lensHighlights.fragment.fx

@@ -6,7 +6,6 @@ uniform sampler2D textureSampler;	// original color
 // uniforms
 uniform float gain;
 uniform float threshold;
-uniform bool pentagon;
 uniform float screen_width;
 uniform float screen_height;
 
@@ -47,7 +46,7 @@ void main(void)
 	// compute blurred color
 	vec4 blurred = vec4(0.0, 0.0, 0.0, 0.0);
 
-	if (pentagon) {
+#ifdef PENTAGON
 		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.84*w, 0.43*h)));
 		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.48*w, -1.29*h)));
 		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.61*w, 1.51*h)));
@@ -87,8 +86,7 @@ void main(void)
 		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.60*w, 3.17*h)));
 		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-3.14*w, -1.19*h)));
 		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(3.00*w, -1.19*h)));
-	}
-	else {
+#else
 		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.85*w, 0.36*h)));
 		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.52*w, -1.14*h)));
 		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.46*w, 1.42*h)));
@@ -128,7 +126,7 @@ void main(void)
 		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.21*w, 2.88*h)));
 		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.84*w, -1.30*h)));
 		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.98*w, -0.96*h)));
-	}
+#endif
 
 	blurred /= 39.0;