I'm new the the glsl shaders in three.js, now trying to make simple and fast blur effect on a mesh texture. This is my fragment shader code:
void blurh(in vec4 inh, out vec4 outh, int r) {
for(int x = -r; x < r+1; x++) {
float coordx = vUv[0] + float(x) / uResolution[0];
coordx = max(0.0, min(1.0, coordx));
inh += texture2D(uTexture, vec2 (coordx, vUv[1]));
}
outh = inh / float(r + r + 1);
}
void blurv(in vec4 inv, out vec4 outv, int r) {
for(int y = -r; y < r+1; y++) {
float coordy = vUv[1] + float(y) / uResolution[1];
coordy = max(0.0, min(1.0, coordy));
inv += texture2D(uTexture, vec2 (vUv[0], coordy));
}
outv = inv / float(r + r + 1);
}
void main() {
int r = 200; // radius
gl_FragColor = texture2D(uTexture, vUv);
blurh(gl_FragColor, gl_FragColor, r);
blurv(gl_FragColor, gl_FragColor, r);
}
it supposed to give me a box blur, but it is only bluring on the vertical direction.
seems the vertical blur function is not using the horizontal blur result as input.
so the first question is, how do I reuse horizontal blur function output as input of vertical blur function? Second is, how do I store/save some variable in fragment shader for later use?