From 822c65e0cc327e377248f1d0bc574582efb96876 Mon Sep 17 00:00:00 2001 From: jgk Date: Fri, 20 Aug 2021 13:23:06 +0200 Subject: [PATCH] Tweak bloom --- shader/texture/bloomBlur.frag | 67 ++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/shader/texture/bloomBlur.frag b/shader/texture/bloomBlur.frag index 730da3e48..b39522ce1 100644 --- a/shader/texture/bloomBlur.frag +++ b/shader/texture/bloomBlur.frag @@ -22,11 +22,11 @@ const vec2 off[9] = vec2[] , vec2(-hOff,-vOff ) ); const vec2 fiveOff[5] = vec2[] - ( vec2( vOff,0.0 ) - , vec2( 0.0,hOff ) - , vec2( 0.0,0.0 ) - , vec2( 0.0,-hOff ) - , vec2( -vOff,0.0 ) + ( vec2( vOff, hOff ) + , vec2( vOff,-hOff ) + , vec2( 0.0, 0.0 ) + , vec2(-vOff, hOff ) + , vec2(-vOff,-hOff ) ); vec4 combinef (vec4 ac, vec4 bc) //{ return vec4 (max(ac.x,bc.x),max(ac.y,bc.y),max(ac.z,bc.z),ac.w + bc.w - @@ -36,30 +36,39 @@ vec4 combinef (vec4 ac, vec4 bc) } void main() { - vec4 sampleTex[9]; - for(int i=0; i<9; i++) + vec4 sumFive = vec4 (0,0,0,0); + for (int i=0; i<5; i++) { - sampleTex[i] = vec4(texture(screenTexture, vTexPos + off[i])); + sumFive += vec4(texture(screenTexture, vTexPos + fiveOff[i])); } - vec4 sampleFive[5]; - for(int i=0; i<5; i++) - { - sampleFive[i] = vec4(texture(screenTexture, vTexPos + fiveOff[i])); - } - vec4 col = vec4(0,0,0,0); - for (int i = 0; i < 9; i++) - col = combinef(col,sampleTex[i]); - //col += sampleTex[i] * frac; - float alph = 0.0; - for (int i = 0; i < 9; i++) - //alph += sampleTex[i].a; - alph = max(alph, 0.5 * sampleTex[i].a); - alph = max(sampleTex[4].a, alph); - // - //fColor = col; - fColor = vec4(col.rgb/col.a,alph); - //if (col.a == 0.0) - //{ fColor = vec4(0,0,0,0); } - //else - //{ fColor = vec4( col.r/col.a , col.g/col.a , col.b/col.a, col.a/9.0); } + // divinding by 4 is not ideal, because it adds extra alpha + // but has more juice than dividing by 5 + fColor = max(texture(screenTexture,vTexPos), sumFive / 4); + //fColor = sumFive / 4; +// vec4 sampleTex[9]; +// for(int i=0; i<9; i++) +// { +// sampleTex[i] = vec4(texture(screenTexture, vTexPos + off[i])); +// } +// vec4 sampleFive[5]; +// for(int i=0; i<5; i++) +// { +// sampleFive[i] = vec4(texture(screenTexture, vTexPos + fiveOff[i])); +// } +// vec4 col = vec4(0,0,0,0); +// for (int i = 0; i < 9; i++) +// col = combinef(col,sampleTex[i]); +// //col += sampleTex[i] * frac; +// float alph = 0.0; +// for (int i = 0; i < 9; i++) +// //alph += sampleTex[i].a; +// alph = max(alph, 0.5 * sampleTex[i].a); +// alph = max(sampleTex[4].a, alph); +// // +// //fColor = col; +// fColor = vec4(col.rgb/col.a,alph); +// //if (col.a == 0.0) +// //{ fColor = vec4(0,0,0,0); } +// //else +// //{ fColor = vec4( col.r/col.a , col.g/col.a , col.b/col.a, col.a/9.0); } }