#include <math.h>
#include <GL/gl.h>
#include <GL/glext.h>
+#include <assert.h>
#include "blur_effect.h"
#include "util.h"
BlurEffect::BlurEffect()
- : radius(3.0f)
+ : radius(3.0f),
+ direction(HORIZONTAL)
{
register_float("radius", (float *)&radius);
+ register_int("direction", (int *)&direction);
}
std::string BlurEffect::output_fragment_shader()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, base_mipmap_level);
check_error();
- set_uniform_float(glsl_program_num, prefix, "pixel_offset", pixel_size / 1280.0f); // FIXME
+ // FIXME
+ if (direction == HORIZONTAL) {
+ float ps[] = { pixel_size / 1280.0f, 0.0f };
+ set_uniform_vec2(glsl_program_num, prefix, "pixel_offset", ps);
+ } else if (direction == VERTICAL) {
+ float ps[] = { 0.0f, pixel_size / 720.0f };
+ set_uniform_vec2(glsl_program_num, prefix, "pixel_offset", ps);
+ } else {
+ assert(false);
+ }
// Simple Gaussian weights for now.
float weight[15], total = 0.0f;
-// A simple, very stupid horizontal blur. Will be fixed soonish.
+// A simple unidirectional blur.
-uniform float PREFIX(pixel_offset);
+uniform vec2 PREFIX(pixel_offset);
uniform float PREFIX(weight)[15];
vec4 FUNCNAME(vec2 tc) {
vec4 x = LAST_INPUT(tc);
return
- vec4(PREFIX(weight)[ 0]) * LAST_INPUT(vec2(tc.x - 7.0 * PREFIX(pixel_offset), tc.y)) +
- vec4(PREFIX(weight)[ 1]) * LAST_INPUT(vec2(tc.x - 6.0 * PREFIX(pixel_offset), tc.y)) +
- vec4(PREFIX(weight)[ 2]) * LAST_INPUT(vec2(tc.x - 5.0 * PREFIX(pixel_offset), tc.y)) +
- vec4(PREFIX(weight)[ 3]) * LAST_INPUT(vec2(tc.x - 4.0 * PREFIX(pixel_offset), tc.y)) +
- vec4(PREFIX(weight)[ 4]) * LAST_INPUT(vec2(tc.x - 3.0 * PREFIX(pixel_offset), tc.y)) +
- vec4(PREFIX(weight)[ 5]) * LAST_INPUT(vec2(tc.x - 2.0 * PREFIX(pixel_offset), tc.y)) +
- vec4(PREFIX(weight)[ 6]) * LAST_INPUT(vec2(tc.x - PREFIX(pixel_offset), tc.y)) +
+ 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(vec2(tc.x + PREFIX(pixel_offset), tc.y)) +
- vec4(PREFIX(weight)[ 9]) * LAST_INPUT(vec2(tc.x + 2.0 * PREFIX(pixel_offset), tc.y)) +
- vec4(PREFIX(weight)[10]) * LAST_INPUT(vec2(tc.x + 3.0 * PREFIX(pixel_offset), tc.y)) +
- vec4(PREFIX(weight)[11]) * LAST_INPUT(vec2(tc.x + 4.0 * PREFIX(pixel_offset), tc.y)) +
- vec4(PREFIX(weight)[12]) * LAST_INPUT(vec2(tc.x + 5.0 * PREFIX(pixel_offset), tc.y));
- vec4(PREFIX(weight)[13]) * LAST_INPUT(vec2(tc.x + 6.0 * PREFIX(pixel_offset), tc.y));
- vec4(PREFIX(weight)[14]) * LAST_INPUT(vec2(tc.x + 7.0 * PREFIX(pixel_offset), tc.y));
+ 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));
}
void set_uniforms(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num);
+ enum Direction { HORIZONTAL = 0, VERTICAL = 1 };
+
private:
float radius;
+ Direction direction;
};
#endif // !defined(_BLUR_EFFECT_H)
chain.add_input(inout_format);
Effect *lift_gamma_gain_effect = chain.add_effect(EFFECT_LIFT_GAMMA_GAIN);
Effect *saturation_effect = chain.add_effect(EFFECT_SATURATION);
- Effect *blur_effect = chain.add_effect(EFFECT_BLUR);
+ Effect *hblur_effect = chain.add_effect(EFFECT_BLUR);
+ Effect *vblur_effect = chain.add_effect(EFFECT_BLUR);
Effect *vignette_effect = chain.add_effect(EFFECT_VIGNETTE);
//chain.add_effect(EFFECT_MIRROR);
chain.add_output(inout_format);
vignette_effect->set_float("radius", radius);
vignette_effect->set_float("inner_radius", inner_radius);
//vignette_effect->set_vec2("center", (float[]){ 0.7f, 0.5f });
- blur_effect->set_float("radius", blur_radius);
+
+ hblur_effect->set_int("direction", 0);
+ hblur_effect->set_float("radius", blur_radius);
+
+ vblur_effect->set_int("direction", 1);
+ vblur_effect->set_float("radius", blur_radius);
+
chain.render_to_screen(src_img);
glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 1);