diff --git a/orx-fx/src/shaders/glsl/blur/box-blur.frag b/orx-fx/src/shaders/glsl/blur/box-blur.frag index a84c6d6e..a47eca7e 100644 --- a/orx-fx/src/shaders/glsl/blur/box-blur.frag +++ b/orx-fx/src/shaders/glsl/blur/box-blur.frag @@ -1,5 +1,11 @@ +#ifdef OR_IN_OUT in vec2 v_texCoord0; +#else +varying vec2 v_texCoord0; +#endif + uniform sampler2D tex0; +uniform vec2 textureSize0; uniform vec2 blurDirection; uniform int window; @@ -7,21 +13,42 @@ uniform float sigma; uniform float gain; uniform vec4 subtract; uniform float spread; + +#ifndef OR_GL_FRAGCOLOR out vec4 o_color; +#endif + void main() { - vec2 s = textureSize(tex0, 0).xy; - s = vec2(1.0/s.x, 1.0/s.y); + vec2 s = textureSize0; + s = vec2(1.0 / s.x, 1.0 / s.y); + #ifndef OR_WEBGL1 int w = window; + int WS = -window; + int WE = window; + #else + int w = 3; + #define WS -3 + #define WE 3 + #endif - vec4 sum = vec4(0, 0, 0, 0); - float weight = 0; - for (int x = -w; x<= w; ++x) { + vec4 sum = vec4(0.0, 0.0, 0.0, 0.0); + float weight = 0.0; + for (int x = WS; x<= WE; ++x) { float lw = 1.0; - sum += texture(tex0, v_texCoord0 + x * blurDirection * s * spread); + #ifndef OR_GL_TEXTURE2D + sum += texture(tex0, v_texCoord0 + float(x) * blurDirection * s * spread); + #else + sum += texture2D(tex0, v_texCoord0 + float(x) * blurDirection * s * spread); + #endif + weight += lw; } - o_color = (sum / weight) * gain; -// o_color.a = 1.0; + vec4 result = (sum / weight) * gain; + #ifdef OR_GL_FRAGCOLOR + gl_FragColor = result; + #else + o_color = result; + #endif } \ No newline at end of file