Forráskód Böngészése

set dof blur using outputs instead of inputs

Trevor Baron 7 éve
szülő
commit
4b64801911

+ 1 - 1
src/PostProcess/babylon.depthOfFieldEffect.ts

@@ -116,7 +116,7 @@ module BABYLON {
             }
 
             // Merge blurred images with original image based on circleOfConfusion
-            this._depthOfFieldMerge = new DepthOfFieldMergePostProcess("depthOfFieldMerge", this._circleOfConfusion, this._circleOfConfusion, this._depthOfFieldBlurY.slice(0, this._depthOfFieldBlurY.length-1), 1, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, pipelineTextureType, blockCompilation);
+            this._depthOfFieldMerge = new DepthOfFieldMergePostProcess("depthOfFieldMerge", this._circleOfConfusion, this._circleOfConfusion, this._depthOfFieldBlurY, 1, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, pipelineTextureType, blockCompilation);
             this._depthOfFieldMerge.autoClear = false;
             
             // Set all post processes on the effect.

+ 4 - 4
src/PostProcess/babylon.depthOfFieldMergePostProcess.ts

@@ -18,12 +18,12 @@ module BABYLON {
          * @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, original: 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", [], ["circleOfConfusionSampler", "originalSampler", "blurStep1", "blurStep2"], options, camera, samplingMode, engine, reusable, null, textureType, undefined, null, true);
+            super(name, "depthOfFieldMerge", [], ["circleOfConfusionSampler", "blurStep0", "blurStep1", "blurStep2"], options, camera, samplingMode, engine, reusable, null, textureType, undefined, null, true);
             this.onApplyObservable.add((effect: Effect) => {
                 effect.setTextureFromPostProcessOutput("circleOfConfusionSampler", circleOfConfusion);
-                effect.setTextureFromPostProcess("originalSampler", original);
+                effect.setTextureFromPostProcess("textureSampler", original);
                 blurSteps.forEach((step,index)=>{
-                    effect.setTextureFromPostProcessOutput("blurStep"+(index+1), step);
+                    effect.setTextureFromPostProcessOutput("blurStep"+(blurSteps.length-index-1), step);
                 });
             });
 
@@ -43,7 +43,7 @@ module BABYLON {
          */
         public updateEffect(defines: Nullable<string> = null, uniforms: Nullable<string[]> = null, samplers: Nullable<string[]> = null, indexParameters?: any,
             onCompiled?: (effect: Effect) => void, onError?: (effect: Effect, errors: string) => void) {
-            super.updateEffect(defines ? defines : "#define BLUR_LEVEL "+this.blurSteps.length+"\n", uniforms, samplers, indexParameters, onCompiled, onError);
+            super.updateEffect(defines ? defines : "#define BLUR_LEVEL "+(this.blurSteps.length-1)+"\n", uniforms, samplers, indexParameters, onCompiled, onError);
         }
     }
 }

+ 12 - 10
src/Shaders/depthOfFieldMerge.fragment.fx

@@ -1,7 +1,7 @@
 // samplers
 uniform sampler2D textureSampler;
-uniform sampler2D originalSampler;
 uniform sampler2D circleOfConfusionSampler;
+uniform sampler2D blurStep0;
 
 #if BLUR_LEVEL > 0
 uniform sampler2D blurStep1;
@@ -14,31 +14,33 @@ varying vec2 vUV;
 
 void main(void)
 {
+    gl_FragColor = texture2D(textureSampler, vUV);
+
     float coc = texture2D(circleOfConfusionSampler, vUV).r;
-    vec4 original = texture2D(originalSampler, vUV);
+    vec4 original = texture2D(textureSampler, vUV);
 #if BLUR_LEVEL == 0
-    vec4 blurred1 = texture2D(textureSampler, vUV);
-    gl_FragColor = mix(original, blurred1, coc);
+    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);
-    vec4 blurred2 = texture2D(textureSampler, vUV);    
     if(coc < 0.5){
         gl_FragColor = mix(original, blurred1, coc/0.5);
     }else{
-        gl_FragColor = mix(blurred1, blurred2, (coc-0.5)/0.5);
+        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);
-    vec4 blurred3 = texture2D(textureSampler, vUV);
     if(coc < 0.33){
-        gl_FragColor = mix(original, blurred1, coc/0.33);
+        gl_FragColor = mix(original, blurred2, coc/0.33);
     }else if(coc < 0.66){
-        gl_FragColor = mix(blurred1, blurred2, (coc-0.33)/0.33);
+        gl_FragColor = mix(blurred2, blurred1, (coc-0.33)/0.33);
     }else{
-        gl_FragColor = mix(blurred2, blurred3, (coc-0.66)/0.34);
+        gl_FragColor = mix(blurred1, blurred0, (coc-0.66)/0.34);
     }
 #endif
 }