]> git.sesse.net Git - movit/blob - blur_effect.cpp
Hook up a blur radius control.
[movit] / blur_effect.cpp
1 #define GL_GLEXT_PROTOTYPES 1
2
3 #include <math.h>
4 #include <GL/gl.h>
5 #include <GL/glext.h>
6
7 #include "blur_effect.h"
8 #include "util.h"
9
10 BlurEffect::BlurEffect()
11         : radius(3.0f)
12 {
13         register_float("radius", (float *)&radius);
14 }
15
16 std::string BlurEffect::output_fragment_shader()
17 {
18         return read_file("blur_effect.frag");
19 }
20
21 void BlurEffect::set_uniforms(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
22 {
23         Effect::set_uniforms(glsl_program_num, prefix, sampler_num);
24
25         //glActiveTexture(GL_TEXTURE0);
26         //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
27         //check_error();
28
29         set_uniform_float(glsl_program_num, prefix, "pixel_offset", 1.0f / 1280.0f);  // FIXME
30
31         // Simple Gaussian weights for now.
32         float weight[15], total = 0.0f;
33         for (unsigned i = 0; i < 15; ++i) {
34                 float z = (i - 7.0f) / radius;
35                 weight[i] = exp(-(z*z));
36                 total += weight[i];
37         }
38         for (unsigned i = 0; i < 15; ++i) {
39                 weight[i] /= total;
40                 printf("%f\n", weight[i]);
41         }
42         printf("\n");
43         set_uniform_float_array(glsl_program_num, prefix, "weight", weight, 15);
44 }