X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=blur_effect.frag;h=8853854229038c067b0ab8f677008a24d67e64b7;hp=8c0a01d6216c35bdb59836fbe6a8d831dc2e2fee;hb=refs%2Fheads%2Fepoxy;hpb=f25eed80a570ae049f03b098757a070188efbc39 diff --git a/blur_effect.frag b/blur_effect.frag index 8c0a01d..8853854 100644 --- a/blur_effect.frag +++ b/blur_effect.frag @@ -1,24 +1,24 @@ -// A simple unidirectional blur. +// A simple un.directional blur. +// DIRECTION_VERTICAL will be #defined to 1 if we are doing a vertical blur, +// 0 otherwise. -uniform vec2 PREFIX(pixel_offset); -uniform float PREFIX(weight)[15]; +#define NUM_TAPS 16 + +uniform vec2 PREFIX(samples)[NUM_TAPS + 1]; vec4 FUNCNAME(vec2 tc) { - vec4 x = LAST_INPUT(tc); - return - vec4(PREFIX(weight)[ 0]) * LAST_INPUT(tc - 7.0 * PREFIX(pixel_offset)) + - vec4(PREFIX(weight)[ 1]) * LAST_INPUT(tc - 6.0 * PREFIX(pixel_offset)) + - vec4(PREFIX(weight)[ 2]) * LAST_INPUT(tc - 5.0 * PREFIX(pixel_offset)) + - vec4(PREFIX(weight)[ 3]) * LAST_INPUT(tc - 4.0 * PREFIX(pixel_offset)) + - vec4(PREFIX(weight)[ 4]) * LAST_INPUT(tc - 3.0 * PREFIX(pixel_offset)) + - vec4(PREFIX(weight)[ 5]) * LAST_INPUT(tc - 2.0 * PREFIX(pixel_offset)) + - vec4(PREFIX(weight)[ 6]) * LAST_INPUT(tc - PREFIX(pixel_offset)) + - vec4(PREFIX(weight)[ 7]) * LAST_INPUT(tc) + - vec4(PREFIX(weight)[ 8]) * LAST_INPUT(tc + PREFIX(pixel_offset)) + - vec4(PREFIX(weight)[ 9]) * LAST_INPUT(tc + 2.0 * PREFIX(pixel_offset)) + - vec4(PREFIX(weight)[10]) * LAST_INPUT(tc + 3.0 * PREFIX(pixel_offset)) + - vec4(PREFIX(weight)[11]) * LAST_INPUT(tc + 4.0 * PREFIX(pixel_offset)) + - vec4(PREFIX(weight)[12]) * LAST_INPUT(tc + 5.0 * PREFIX(pixel_offset)) + - vec4(PREFIX(weight)[13]) * LAST_INPUT(tc + 6.0 * PREFIX(pixel_offset)) + - vec4(PREFIX(weight)[14]) * LAST_INPUT(tc + 7.0 * PREFIX(pixel_offset)); + vec4 sum = vec4(PREFIX(samples)[0].y) * INPUT(tc); + for (int i = 1; i < NUM_TAPS + 1; ++i) { + vec2 sample = PREFIX(samples)[i]; + vec2 sample1_tc = tc, sample2_tc = tc; +#if DIRECTION_VERTICAL + sample1_tc.y -= sample.x; + sample2_tc.y += sample.x; +#else + sample1_tc.x -= sample.x; + sample2_tc.x += sample.x; +#endif + sum += vec4(sample.y) * (INPUT(sample1_tc) + INPUT(sample2_tc)); + } + return sum; }