0f5c688a3702d7f81efffd1696281851eecd5ce1
[movit] / vignette_effect.cpp
1 #include <GL/glew.h>
2 #include <math.h>
3
4 #include "effect_util.h"
5 #include "vignette_effect.h"
6 #include "util.h"
7
8 VignetteEffect::VignetteEffect()
9         : center(0.5f, 0.5f),
10           aspect_correction(1.0f, 1.0f),
11           radius(0.3f),
12           inner_radius(0.3f)
13 {
14         register_vec2("center", (float *)&center);
15         register_float("radius", (float *)&radius);
16         register_float("inner_radius", (float *)&inner_radius);
17 }
18
19 std::string VignetteEffect::output_fragment_shader()
20 {
21         return read_file("vignette_effect.frag");
22 }
23
24 void VignetteEffect::inform_input_size(unsigned input_num, unsigned width, unsigned height) {
25         assert(input_num == 0);
26         if (width >= height) {
27                 aspect_correction = Point2D(float(width) / float(height), 1.0f);
28         } else {
29                 aspect_correction = Point2D(1.0f, float(height) / float(width));
30         }
31 }
32
33 void VignetteEffect::set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
34 {
35         Effect::set_gl_state(glsl_program_num, prefix, sampler_num);
36
37         set_uniform_float(glsl_program_num, prefix, "pihalf_div_radius", 0.5 * M_PI / radius);
38         set_uniform_vec2(glsl_program_num, prefix, "aspect_correction", (float *)&aspect_correction);
39
40         Point2D flipped_center(center.x, 1.0f - center.y);
41         set_uniform_vec2(glsl_program_num, prefix, "flipped_center", (float *)&flipped_center);
42 }