Fix webgl compatibility for box-blur.frag

This commit is contained in:
Edwin Jakobs
2021-07-03 16:18:35 +02:00
parent a595d1427a
commit 23780a3102

View File

@@ -1,5 +1,11 @@
#ifdef OR_IN_OUT
in vec2 v_texCoord0; in vec2 v_texCoord0;
#else
varying vec2 v_texCoord0;
#endif
uniform sampler2D tex0; uniform sampler2D tex0;
uniform vec2 textureSize0;
uniform vec2 blurDirection; uniform vec2 blurDirection;
uniform int window; uniform int window;
@@ -7,21 +13,42 @@ uniform float sigma;
uniform float gain; uniform float gain;
uniform vec4 subtract; uniform vec4 subtract;
uniform float spread; uniform float spread;
#ifndef OR_GL_FRAGCOLOR
out vec4 o_color; out vec4 o_color;
#endif
void main() { void main() {
vec2 s = textureSize(tex0, 0).xy; vec2 s = textureSize0;
s = vec2(1.0 / s.x, 1.0 / s.y); s = vec2(1.0 / s.x, 1.0 / s.y);
#ifndef OR_WEBGL1
int w = window; 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); vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);
float weight = 0; float weight = 0.0;
for (int x = -w; x<= w; ++x) { for (int x = WS; x<= WE; ++x) {
float lw = 1.0; 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; weight += lw;
} }
o_color = (sum / weight) * gain; vec4 result = (sum / weight) * gain;
// o_color.a = 1.0; #ifdef OR_GL_FRAGCOLOR
gl_FragColor = result;
#else
o_color = result;
#endif
} }