I am writing a custom blur shader,
"#include <common>",
// blur samples
"const int SAMPLES = 10;",
"uniform float radius;",
"uniform sampler2D tDiffuse;",
"varying vec2 vUv;",
"void main() {",
// sample the source
" vec2 uv = vUv;",
" vec4 cTextureScreen = texture2D( tDiffuse, vUv );",
" vec3 res = vec3(0);",
" for(int i = 0; i < SAMPLES; ++i) {",
" res += cTextureScreen.a;",
" vec2 d = vec2(0.5) - uv;",
" uv += d * radius;",
" }",
" gl_FragColor = vec4(res/float(SAMPLES), 1.0);",
"}"
Which is a straight port of: https://www.shadertoy.com/view/ltVSRK
For use with the effect composer of THREE.
Unfortunately, it appears that tDiffuse
is not packed as rgb, and I am pretty confused as to how I can achieve the desired effect or the conversion I need.
See also the following question for more details: what do texture2D().r and texture2D().a mean?