From 040dd5f3bad7b6032f650a9fd88de217253c723a Mon Sep 17 00:00:00 2001 From: laochailan Date: Sat, 21 Jul 2012 18:07:36 +0200 Subject: [PATCH] Improved shader performance (hopefully) --- shader/alpha_depth.sha | 4 ++-- shader/bloom.sha | 21 +++++---------------- shader/boss_zoom.sha | 6 ++---- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/shader/alpha_depth.sha b/shader/alpha_depth.sha index 18587a08..0968fce8 100644 --- a/shader/alpha_depth.sha +++ b/shader/alpha_depth.sha @@ -13,8 +13,8 @@ void main(void) { uniform sampler2D tex; void main(void) { - vec4 clr = texture2D(tex, vec2(gl_TexCoord[0].xy)); + vec4 clr = texture2D(tex, gl_TexCoord[0].xy); gl_FragColor = vec4(0.1,0.0,0.07,1.0); - gl_FragDepth = 0.5*gl_FragCoord.z/clr.a; + gl_FragDepth = 0.5*gl_FragCoord.z/clr.a; } \ No newline at end of file diff --git a/shader/bloom.sha b/shader/bloom.sha index 746f1e03..e1188b29 100644 --- a/shader/bloom.sha +++ b/shader/bloom.sha @@ -13,25 +13,14 @@ void main(void) { uniform sampler2D tex; uniform float intensity; -float pi = 2.0 * asin(1.0); - void main(void) { vec2 pos = vec2(gl_TexCoord[0]); - float a; - float i = 0.0; - vec4 sum = vec4(0.0), c; + vec4 sum = vec4(0.0); - for(a = 0.0; a <= 2.0*pi; a+=0.6) { - c = texture2D(tex, pos + vec2(cos(a),sin(a))*0.01); - if(c != vec4(0.0)) { - sum += c; - i++; - } - } + for(int a = 0; a < 10; a++) { + sum += texture2D(tex, pos + vec2(cos(0.628*float(a)),sin(0.628*float(a)))*0.03);; + } - - gl_FragColor = texture2D(tex, pos) + intensity*sum*sum/i; - -// gl_FragColor = texture2D(tex, pos); + gl_FragColor = texture2D(tex, pos) + intensity*sum*sum/10.0; } \ No newline at end of file diff --git a/shader/boss_zoom.sha b/shader/boss_zoom.sha index fdfe4340..94b6dea5 100644 --- a/shader/boss_zoom.sha +++ b/shader/boss_zoom.sha @@ -24,14 +24,12 @@ void main(void) { vec2 pos1 = pos; pos1.y *= ratio; - if(length(pos1) < blur_rad) - pos *= length(pos1)/blur_rad; + pos *= min(length(pos1)/blur_rad,1.0); gl_FragColor = texture2D(tex, pos + blur_orig); pos1 = vec2(gl_TexCoord[0]) - fix_orig; pos1.y *= ratio; - if(length(pos1) < rad) - gl_FragColor *= pow(vec4(0.1,0.2,0.3,1),vec4(3.0*(rad - length(pos1)))); + gl_FragColor *= pow(vec4(0.1,0.2,0.3,1),vec4(3.0*max(0.0,rad - length(pos1)))); } \ No newline at end of file