Browse Source

split dof and bloom into separate merges

Trevor Baron 7 years ago
parent
commit
32e477b301

+ 18 - 6
Tools/Gulp/config.json

@@ -73,7 +73,8 @@
             "additionalPostProcess_depthOfFieldBlur",
             "additionalPostProcess_fxaa",
             "additionalPostProcess_circleOfConfusion",
-            "additionalPostProcess_defaultPipelineMerge",
+            "additionalPostProcess_depthOfFieldMerge",
+            "additionalPostProcess_bloomMerge",
             "additionalPostProcess_depthOfFieldEffect",
             "additionalPostProcess_bloomEffect",
             "additionalPostProcess_imageProcessing",
@@ -815,15 +816,26 @@
                 "grain.fragment"
             ]
         },
-        "additionalPostProcess_defaultPipelineMerge": {
+        "additionalPostProcess_depthOfFieldMerge": {
             "files": [
-                "../../src/PostProcess/babylon.defaultPipelineMergePostProcess.js"
+                "../../src/PostProcess/babylon.depthOfFieldMergePostProcess.js"
             ],
             "dependUpon": [
                 "postProcesses"
             ],
             "shaders": [
-                "defaultPipelineMerge.fragment"
+                "depthOfFieldMerge.fragment"
+            ]
+        },
+        "additionalPostProcess_bloomMerge": {
+            "files": [
+                "../../src/PostProcess/babylon.bloomMergePostProcess.js"
+            ],
+            "dependUpon": [
+                "postProcesses"
+            ],
+            "shaders": [
+                "bloomMerge.fragment"
             ]
         },
         "additionalPostProcess_depthOfFieldEffect": {
@@ -832,7 +844,7 @@
             ],
             "dependUpon": [
                 "additionalPostProcess_depthOfFieldBlur",
-                "additionalPostProcess_defaultPipelineMerge",
+                "additionalPostProcess_depthOfFieldMerge",
                 "additionalPostProcess_circleOfConfusion"
             ]
         },
@@ -842,7 +854,7 @@
             ],
             "dependUpon": [
                 "additionalPostProcess_blur",
-                "additionalPostProcess_defaultPipelineMerge",
+                "additionalPostProcess_bloomMerge",
                 "additionalPostProcess_extractHighlights"
             ]
         },

+ 21 - 48
src/PostProcess/RenderPipeline/Pipelines/babylon.defaultRenderingPipeline.ts

@@ -34,8 +34,6 @@
         public sharpen: SharpenPostProcess;
         private _sharpenEffect: PostProcessRenderEffect;
         private bloom: BloomEffect;
-        private _defaultPipelineMerge:DefaultPipelineMergeMergePostProcess;
-        private _defaultPipelineMergeEffect: PostProcessRenderEffect;
         /**
          * Depth of field effect, applies a blur based on how far away objects are from the focus distance.
          */
@@ -132,9 +130,7 @@
             if (this._bloomWeight === value) {
                 return;
             }
-            if(this._defaultPipelineMerge._mergeOptions && this._defaultPipelineMerge._mergeOptions.bloom){
-                this._defaultPipelineMerge._mergeOptions.bloom.weight = value;
-            }
+            this.bloom.weight = value;
             
             this._bloomWeight = value;
         }
@@ -200,7 +196,7 @@
         private _rebuildBloom(){
             // recreate bloom and dispose old as this setting is not dynamic
             var oldBloom = this.bloom;
-            this.bloom = new BloomEffect(this._scene, this.bloomScale, this.bloomKernel, this._defaultPipelineTextureType, false);
+            this.bloom = new BloomEffect(this._scene, this.bloomScale, this._bloomWeight, this.bloomKernel, this._defaultPipelineTextureType, false);
             this.bloom.threshold = oldBloom.threshold;
             for (var i = 0; i < this._cameras.length; i++) {
                 oldBloom.disposeEffects(this._cameras[i]);
@@ -380,12 +376,9 @@
             this.sharpen = new SharpenPostProcess("sharpen", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType, true);
             this._sharpenEffect = new PostProcessRenderEffect(engine, this.SharpenPostProcessId, () => { return this.sharpen; }, true);
 
-            this.depthOfField = new DepthOfFieldEffect(this._scene, null, this._depthOfFieldBlurLevel, this._defaultPipelineTextureType, false, true);
+            this.depthOfField = new DepthOfFieldEffect(this._scene, null, this._depthOfFieldBlurLevel, this._defaultPipelineTextureType, true);
             
-            this.bloom = new BloomEffect(this._scene, this._bloomScale, this.bloomKernel, this._defaultPipelineTextureType, false, true);
-
-            this._defaultPipelineMerge = new DefaultPipelineMergeMergePostProcess("defaultPipelineMerge", {}, 1, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, this._defaultPipelineTextureType, true);
-            this._defaultPipelineMergeEffect = new PostProcessRenderEffect(engine, "defaultPipelineMerge", () => { return this._defaultPipelineMerge; }, true);
+            this.bloom = new BloomEffect(this._scene, this._bloomScale, this._bloomWeight, this.bloomKernel, this._defaultPipelineTextureType, true);
 
             this.chromaticAberration = new ChromaticAberrationPostProcess("ChromaticAberration", engine.getRenderWidth(), engine.getRenderHeight(), 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType, true);
             this._chromaticAberrationEffect = new PostProcessRenderEffect(engine, this.ChromaticAberrationPostProcessId, () => { return this.chromaticAberration; }, true);
@@ -468,21 +461,7 @@
             this._hasCleared = false;
             this._firstPostProcess = null;
 
-            var mergeOptions = new DefaultPipelineMergePostProcessOptions();
-
-            if (this.fxaaEnabled) {
-                this.fxaa = new FxaaPostProcess("fxaa", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType);
-                this.addEffect(new PostProcessRenderEffect(engine, this.FxaaPostProcessId, () => { return this.fxaa; }, true));
-                this._setAutoClearAndTextureSharing(this.fxaa);
-            }
-
-            if (this.sharpenEnabled) {
-                if(!this.sharpen.isReady()){
-                    this.sharpen.updateEffect();
-                }
-                this.addEffect(this._sharpenEffect);
-                this._setAutoClearAndTextureSharing(this.sharpen);
-            }
+            
 
             if (this.depthOfFieldEnabled) {
                 var depthTexture = this._scene.enableDepthRenderer(this._cameras[0]).getDepthMap();
@@ -490,33 +469,17 @@
                 if(!this.depthOfField._isReady()){
                     this.depthOfField._updateEffects();
                 }
-                mergeOptions.depthOfField = {circleOfConfusion: this.depthOfField._effects[0], blurSteps: this.depthOfField._depthOfFieldBlurX};
-                if(!mergeOptions.originalFromInput){
-                    mergeOptions.originalFromInput=this.depthOfField._effects[0];
-                }
                 this.addEffect(this.depthOfField);
                 this._setAutoClearAndTextureSharing(this.depthOfField._effects[0], true);
             }
-            
+
             if (this.bloomEnabled) {
                 if(!this.bloom._isReady()){
                     this.bloom._updateEffects();
                 }
-                mergeOptions.bloom = {blurred: this.bloom._effects[this.bloom._effects.length-1], weight: this.bloomWeight}
-                if(!mergeOptions.originalFromInput){
-                    mergeOptions.originalFromInput=this.bloom._effects[0];
-                }
-                this.bloom._downscale._inputPostProcess = this._firstPostProcess;
                 this.addEffect(this.bloom);
                 this._setAutoClearAndTextureSharing(this.bloom._effects[0], true);
             }
-            
-            if(mergeOptions.originalFromInput){
-                this._defaultPipelineMerge._mergeOptions = mergeOptions;
-                this._defaultPipelineMerge.updateEffect();
-                this.addEffect(this._defaultPipelineMergeEffect);
-                this._setAutoClearAndTextureSharing(this._defaultPipelineMerge, true);
-            }
 
             if (this._imageProcessingEnabled) {	
                 this.imageProcessing = new ImageProcessingPostProcess("imageProcessing", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType);	
@@ -528,6 +491,14 @@
                 }		
             }
 
+            if (this.sharpenEnabled) {
+                if(!this.sharpen.isReady()){
+                    this.sharpen.updateEffect();
+                }
+                this.addEffect(this._sharpenEffect);
+                this._setAutoClearAndTextureSharing(this.sharpen);
+            }
+
             if (this.grainEnabled) {
                 if(!this.grain.isReady()){
                     this.grain.updateEffect();
@@ -544,11 +515,17 @@
                 this._setAutoClearAndTextureSharing(this.chromaticAberration);
             }
 
+            if (this.fxaaEnabled) {
+                this.fxaa = new FxaaPostProcess("fxaa", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, this._defaultPipelineTextureType);
+                this.addEffect(new PostProcessRenderEffect(engine, this.FxaaPostProcessId, () => { return this.fxaa; }, true));
+                this._setAutoClearAndTextureSharing(this.fxaa);
+            }
+
             if (this._cameras !== null) {
                 this._scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(this._name, this._cameras);
             }
 
-
+            
             if(!this._enableMSAAOnFirstPostProcess(this.samples) && this.samples > 1){
                 BABYLON.Tools.Warn("MSAA failed to enable, MSAA is only supported in browsers that support webGL >= 2.0");
             }
@@ -587,10 +564,6 @@
                     if(this.grain){
                         this.grain.dispose(camera);
                     }
-
-                    if(this._defaultPipelineMerge){
-                        this._defaultPipelineMerge.dispose(camera);
-                    }
                 }
             }
             

+ 21 - 11
src/PostProcess/babylon.bloomEffect.ts

@@ -14,8 +14,9 @@ module BABYLON {
         public _downscale:ExtractHighlightsPostProcess;
         private _blurX:BlurPostProcess;
         private _blurY:BlurPostProcess;
-        private _merge:Nullable<DefaultPipelineMergeMergePostProcess>;
-
+        private _upscale:PassPostProcess;
+        private _merge:BloomMergePostProcess;
+        
         /**
          * The luminance threshold to find bright areas of the image to bloom. 
          */
@@ -27,6 +28,16 @@ module BABYLON {
         }
 
         /**
+         * The strength of the bloom.
+         */
+        public get weight():number{
+            return this._merge.weight;
+        }
+        public set weight(value: number){
+            this._merge.weight = value;
+        }
+
+        /**
          * Specifies the size of the bloom blur kernel, relative to the final output size
          */
         public get kernel():number{
@@ -42,11 +53,11 @@ module BABYLON {
          * @param scene The scene the effect belongs to.
          * @param bloomScale The ratio of the blur texture to the input texture that should be used to compute the bloom.
          * @param bloomKernel The size of the kernel to be used when applying the blur.
+         * @param bloomWeight The the strength of bloom.
          * @param pipelineTextureType The type of texture to be used when performing the post processing.
-         * @param performMerge If the finalization merge should be performed by this effect.
          * @param blockCompilation If compilation of the shader should not be done in the constructor. The updateEffect method can be used to compile the shader at a later time. (default: false)
          */
-        constructor(scene: Scene, private bloomScale:number, bloomKernel:number, pipelineTextureType = 0, performMerge = true, blockCompilation = false) {
+        constructor(scene: Scene, private bloomScale:number, bloomWeight:number, bloomKernel:number, pipelineTextureType = 0, blockCompilation = false) {
             super(scene.getEngine(), "bloom", ()=>{
                 return this._effects;
             }, true);
@@ -59,17 +70,16 @@ module BABYLON {
             this._blurY = new BlurPostProcess("vertical blur", new Vector2(0, 1.0), 10.0, bloomScale, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, pipelineTextureType, undefined, blockCompilation);
             this._blurY.alwaysForcePOT = true;
             this._blurY.autoClear = false;
-            this._blurY._outputTextureScale = bloomScale;
 
             this.kernel = bloomKernel;
 
-            this._effects = [this._downscale, this._blurX, this._blurY];
+            this._upscale = new PassPostProcess("upscale", bloomScale, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, pipelineTextureType, blockCompilation);
+            this._upscale.autoClear = false;
+            this._effects = [this._downscale, this._blurX, this._blurY, this._upscale];
 
-            if(performMerge){
-                this._merge = new DefaultPipelineMergeMergePostProcess("defaultPipelineMerge", {originalFromInput: this._blurX, bloom: {blurred: this._blurY, weight: 0}}, 1, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, pipelineTextureType, blockCompilation);
-                this._merge.autoClear = false;
-                this._effects.push(this._merge);
-            }
+            this._merge = new BloomMergePostProcess("bloomMerge", this._downscale, this._blurY, bloomWeight, 1, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, pipelineTextureType, blockCompilation);
+            this._merge.autoClear = false;
+            this._effects.push(this._merge);
         }
 
         /**

+ 33 - 0
src/PostProcess/babylon.bloomMergePostProcess.ts

@@ -0,0 +1,33 @@
+module BABYLON {
+    /**
+     * The BloomMergePostProcess merges blurred images with the original based on the values of the circle of confusion.
+     */
+    export class BloomMergePostProcess extends PostProcess {
+        /**
+         * Creates a new instance of @see BloomMergePostProcess
+         * @param name The name of the effect.
+         * @param originalFromInput Post process which's input will be used for the merge.
+         * @param blurred Blurred highlights post process which's output will be used.
+         * @param weight Weight of the bloom to be added to the original input.
+         * @param options The required width/height ratio to downsize to before computing the render pass.
+         * @param camera The camera to apply the render pass to.
+         * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
+         * @param engine The engine which the post process will be applied. (default: current engine)
+         * @param reusable If the post process can be reused on the same frame. (default: false)
+         * @param textureType Type of textures used when performing the post process. (default: 0)
+         * @param blockCompilation If compilation of the shader should not be done in the constructor. The updateEffect method can be used to compile the shader at a later time. (default: false)
+         */
+        constructor(name: string, originalFromInput:PostProcess, blurred:PostProcess, /** Weight of the bloom to be added to the original input. */ public weight:number, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT, blockCompilation = false) {
+            super(name, "bloomMerge", ["bloomWeight"], ["circleOfConfusionSampler", "blurStep0", "blurStep1", "blurStep2", "bloomBlur"], options, camera, samplingMode, engine, reusable, null, textureType, undefined, null, true);
+            this.onApplyObservable.add((effect: Effect) => {
+                effect.setTextureFromPostProcess("textureSampler", originalFromInput);
+                effect.setTextureFromPostProcessOutput("bloomBlur", blurred);
+                effect.setFloat("bloomWeight", this.weight);   
+            });
+
+            if(!blockCompilation){
+                this.updateEffect();
+            }
+        }
+    }
+}

+ 6 - 9
src/PostProcess/babylon.depthOfFieldEffect.ts

@@ -26,7 +26,7 @@ module BABYLON {
          */
         public _depthOfFieldBlurX: Array<DepthOfFieldBlurPostProcess>;
         private _depthOfFieldBlurY: Array<DepthOfFieldBlurPostProcess>;
-        private _defaultPipelineMerge: Nullable<DefaultPipelineMergeMergePostProcess>;
+        private _dofMerge: Nullable<DepthOfFieldMergePostProcess>;
 
         /**
          * Internal post processes in depth of field effect
@@ -75,10 +75,9 @@ module BABYLON {
          * @param scene The scene the effect belongs to.
          * @param depthTexture The depth texture of the scene to compute the circle of confusion.This must be set in order for this to function but may be set after initialization if needed.
          * @param pipelineTextureType The type of texture to be used when performing the post processing.
-         * @param performMerge If the finalization merge should be performed by this effect.
          * @param blockCompilation If compilation of the shader should not be done in the constructor. The updateEffect method can be used to compile the shader at a later time. (default: false)
          */
-        constructor(scene: Scene, depthTexture: Nullable<RenderTargetTexture>, blurLevel: DepthOfFieldEffectBlurLevel = DepthOfFieldEffectBlurLevel.Low, pipelineTextureType = 0, performMerge = true, blockCompilation = false) {
+        constructor(scene: Scene, depthTexture: Nullable<RenderTargetTexture>, blurLevel: DepthOfFieldEffectBlurLevel = DepthOfFieldEffectBlurLevel.Low, pipelineTextureType = 0, blockCompilation = false) {
             super(scene.getEngine(), "depth of field", ()=>{
                 return this._effects;
             }, true);
@@ -126,12 +125,10 @@ module BABYLON {
                 this._effects.push(this._depthOfFieldBlurX[i]);
             }
 
-            if(performMerge){
-                // Merge blurred images with original image based on circleOfConfusion
-                this._defaultPipelineMerge = new DefaultPipelineMergeMergePostProcess("defaultPipelineMerge", {originalFromInput: this._circleOfConfusion, depthOfField: {circleOfConfusion: this._circleOfConfusion, blurSteps: this._depthOfFieldBlurX}}, 1, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, pipelineTextureType, blockCompilation);
-                this._defaultPipelineMerge.autoClear = false;
-                this._effects.push(this._defaultPipelineMerge);
-            }
+            // Merge blurred images with original image based on circleOfConfusion
+            this._dofMerge = new DepthOfFieldMergePostProcess("dofMerge", this._circleOfConfusion, this._circleOfConfusion, this._depthOfFieldBlurX, 1, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, pipelineTextureType, blockCompilation);
+            this._dofMerge.autoClear = false;
+            this._effects.push(this._dofMerge);
         }
 
         /**

+ 16 - 34
src/PostProcess/babylon.defaultPipelineMergePostProcess.ts

@@ -2,11 +2,11 @@ module BABYLON {
     /**
      * Options to be set when merging outputs from the default pipeline.
      */
-	export class DefaultPipelineMergePostProcessOptions {
+	export class DepthOfFieldMergePostProcessOptions {
         /**
          * The original image to merge on top of
          */
-        public originalFromInput?: PostProcess;
+        public originalFromInput: PostProcess;
         /**
          * Parameters to perform the merge of the depth of field effect
          */
@@ -24,18 +24,15 @@ module BABYLON {
     }
 
     /**
-     * The DefaultPipelineMergeMergePostProcess merges blurred images with the original based on the values of the circle of confusion.
+     * The DepthOfFieldMergePostProcess merges blurred images with the original based on the values of the circle of confusion.
      */
-    export class DefaultPipelineMergeMergePostProcess extends PostProcess {
+    export class DepthOfFieldMergePostProcess extends PostProcess {
         /**
-         * Internal, optins for the merge post process
-         */
-        public _mergeOptions:DefaultPipelineMergePostProcessOptions;
-
-        /**
-         * Creates a new instance of @see DefaultPipelineMergeMergePostProcess
+         * Creates a new instance of @see DepthOfFieldMergePostProcess
          * @param name The name of the effect.
-         * @param mergeOptions Options to be set when merging outputs from the default pipeline.
+         * @param originalFromInput Post process which's input will be used for the merge.
+         * @param circleOfConfusion Circle of confusion post process which's output will be used to blur each pixel.
+         * @param blurSteps Blur post processes from low to high which will be mixed with the original image.
          * @param options The required width/height ratio to downsize to before computing the render pass.
          * @param camera The camera to apply the render pass to.
          * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
@@ -44,23 +41,14 @@ module BABYLON {
          * @param textureType Type of textures used when performing the post process. (default: 0)
          * @param blockCompilation If compilation of the shader should not be done in the constructor. The updateEffect method can be used to compile the shader at a later time. (default: false)
          */
-        constructor(name: string, mergeOptions: DefaultPipelineMergePostProcessOptions, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT, blockCompilation = false) {
-            super(name, "defaultPipelineMerge", ["bloomWeight"], ["circleOfConfusionSampler", "blurStep0", "blurStep1", "blurStep2", "bloomBlur"], options, camera, samplingMode, engine, reusable, null, textureType, undefined, null, true);
-            this._mergeOptions = mergeOptions;
+        constructor(name: string, originalFromInput:PostProcess, circleOfConfusion:PostProcess, private blurSteps:Array<PostProcess>, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT, blockCompilation = false) {
+            super(name, "depthOfFieldMerge", ["bloomWeight"], ["circleOfConfusionSampler", "blurStep0", "blurStep1", "blurStep2", "bloomBlur"], options, camera, samplingMode, engine, reusable, null, textureType, undefined, null, true);
             this.onApplyObservable.add((effect: Effect) => {
-                if(this._mergeOptions.originalFromInput){
-                    effect.setTextureFromPostProcess("textureSampler", this._mergeOptions.originalFromInput);
-                }
-                if(this._mergeOptions.depthOfField){
-                    effect.setTextureFromPostProcessOutput("circleOfConfusionSampler", this._mergeOptions.depthOfField.circleOfConfusion);
-                    this._mergeOptions.depthOfField.blurSteps.forEach((step,index)=>{
-                        effect.setTextureFromPostProcessOutput("blurStep"+(this._mergeOptions.depthOfField!.blurSteps.length-index-1), step);
-                    });
-                }
-                if(this._mergeOptions.bloom){
-                    effect.setTextureFromPostProcessOutput("bloomBlur", this._mergeOptions.bloom.blurred);
-                    effect.setFloat("bloomWeight", this._mergeOptions.bloom.weight);
-                }        
+                effect.setTextureFromPostProcess("textureSampler", originalFromInput);
+                effect.setTextureFromPostProcessOutput("circleOfConfusionSampler", circleOfConfusion);
+                blurSteps.forEach((step,index)=>{
+                    effect.setTextureFromPostProcessOutput("blurStep"+(blurSteps.length-index-1), step);
+                });    
             });
 
             if(!blockCompilation){
@@ -81,13 +69,7 @@ module BABYLON {
             onCompiled?: (effect: Effect) => void, onError?: (effect: Effect, errors: string) => void) {
             if(!defines){
                 defines = "";
-                if(this._mergeOptions.depthOfField){
-                    defines += "#define DOF 1\n";
-                    defines += "#define BLUR_LEVEL "+(this._mergeOptions.depthOfField.blurSteps.length-1)+"\n";
-                }
-                if(this._mergeOptions.bloom){
-                    defines += "#define BLOOM 1\n";
-                }
+                defines += "#define BLUR_LEVEL "+(this.blurSteps.length-1)+"\n";
             }
             super.updateEffect(defines, uniforms, samplers, indexParameters, onCompiled, onError);
         }

+ 12 - 0
src/Shaders/bloomMerge.fragment.fx

@@ -0,0 +1,12 @@
+uniform sampler2D textureSampler;
+uniform sampler2D bloomBlur;
+
+varying vec2 vUV;
+uniform float bloomWeight;
+
+void main(void)
+{
+    gl_FragColor = texture2D(textureSampler, vUV);
+    vec3 blurred = texture2D(bloomBlur, vUV).rgb;
+    gl_FragColor.rgb = gl_FragColor.rgb + (blurred.rgb * bloomWeight); 
+}

+ 0 - 57
src/Shaders/defaultPipelineMerge.fragment.fx

@@ -1,57 +0,0 @@
-uniform sampler2D textureSampler;
-varying vec2 vUV;
-
-#ifdef DOF
-    uniform sampler2D circleOfConfusionSampler;
-    uniform sampler2D blurStep0;
-
-    #if BLUR_LEVEL > 0
-    uniform sampler2D blurStep1;
-    #endif
-    #if BLUR_LEVEL > 1
-    uniform sampler2D blurStep2;
-    #endif
-#endif
-
-#ifdef BLOOM
-    uniform sampler2D bloomBlur;
-    uniform float bloomWeight;
-#endif
-
-void main(void)
-{
-    gl_FragColor = texture2D(textureSampler, vUV);
-#ifdef DOF
-        float coc = texture2D(circleOfConfusionSampler, vUV).r;
-        vec4 original = texture2D(textureSampler, vUV);
-    #if BLUR_LEVEL == 0
-        vec4 blurred0 = texture2D(blurStep0, vUV);
-        gl_FragColor = mix(original, blurred0, coc);
-    #endif
-    #if BLUR_LEVEL == 1
-        vec4 blurred0 = texture2D(blurStep0, vUV);   
-        vec4 blurred1 = texture2D(blurStep1, vUV);
-        if(coc < 0.5){
-            gl_FragColor = mix(original, blurred1, coc/0.5);
-        }else{
-            gl_FragColor = mix(blurred1, blurred0, (coc-0.5)/0.5);
-        }
-    #endif
-    #if BLUR_LEVEL == 2
-        vec4 blurred0 = texture2D(blurStep0, vUV);
-        vec4 blurred1 = texture2D(blurStep1, vUV);
-        vec4 blurred2 = texture2D(blurStep2, vUV);
-        if(coc < 0.33){
-            gl_FragColor = mix(original, blurred2, coc/0.33);
-        }else if(coc < 0.66){
-            gl_FragColor = mix(blurred2, blurred1, (coc-0.33)/0.33);
-        }else{
-            gl_FragColor = mix(blurred1, blurred0, (coc-0.66)/0.34);
-        }
-    #endif
-#endif
-#ifdef BLOOM
-    vec3 blurred = texture2D(bloomBlur, vUV).rgb;
-    gl_FragColor.rgb = gl_FragColor.rgb + (blurred.rgb * bloomWeight); 
-#endif
-}

+ 45 - 0
src/Shaders/depthOfFieldMerge.fragment.fx

@@ -0,0 +1,45 @@
+uniform sampler2D textureSampler;
+varying vec2 vUV;
+
+uniform sampler2D circleOfConfusionSampler;
+uniform sampler2D blurStep0;
+
+#if BLUR_LEVEL > 0
+uniform sampler2D blurStep1;
+#endif
+#if BLUR_LEVEL > 1
+uniform sampler2D blurStep2;
+#endif
+
+void main(void)
+{
+    gl_FragColor = texture2D(textureSampler, vUV);
+
+    float coc = texture2D(circleOfConfusionSampler, vUV).r;
+    vec4 original = texture2D(textureSampler, vUV);
+#if BLUR_LEVEL == 0
+    vec4 blurred0 = texture2D(blurStep0, vUV);
+    gl_FragColor = mix(original, blurred0, coc);
+#endif
+#if BLUR_LEVEL == 1
+    vec4 blurred0 = texture2D(blurStep0, vUV);   
+    vec4 blurred1 = texture2D(blurStep1, vUV);
+    if(coc < 0.5){
+        gl_FragColor = mix(original, blurred1, coc/0.5);
+    }else{
+        gl_FragColor = mix(blurred1, blurred0, (coc-0.5)/0.5);
+    }
+#endif
+#if BLUR_LEVEL == 2
+    vec4 blurred0 = texture2D(blurStep0, vUV);
+    vec4 blurred1 = texture2D(blurStep1, vUV);
+    vec4 blurred2 = texture2D(blurStep2, vUV);
+    if(coc < 0.33){
+        gl_FragColor = mix(original, blurred2, coc/0.33);
+    }else if(coc < 0.66){
+        gl_FragColor = mix(blurred2, blurred1, (coc-0.33)/0.33);
+    }else{
+        gl_FragColor = mix(blurred1, blurred0, (coc-0.66)/0.34);
+    }
+#endif
+}