X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=blur_effect.cpp;h=d2178d873706244707a096e5e17b93317a7620f4;hp=2084768bc54393985bbfccdf48f0be1f10741f08;hb=1c44926155efb721da02916f82af87d186a7fb57;hpb=9c12e38b7cd88a77ef297d080b7c41e6bd6326fb diff --git a/blur_effect.cpp b/blur_effect.cpp index 2084768..d2178d8 100644 --- a/blur_effect.cpp +++ b/blur_effect.cpp @@ -6,6 +6,7 @@ #include "blur_effect.h" #include "effect_chain.h" #include "effect_util.h" +#include "init.h" #include "util.h" using namespace std; @@ -21,7 +22,7 @@ BlurEffect::BlurEffect() // The first blur pass will forward resolution information to us. hpass = new SingleBlurPassEffect(this); CHECK(hpass->set_int("direction", SingleBlurPassEffect::HORIZONTAL)); - vpass = new SingleBlurPassEffect(NULL); + vpass = new SingleBlurPassEffect(nullptr); CHECK(vpass->set_int("direction", SingleBlurPassEffect::VERTICAL)); update_radius(); @@ -110,7 +111,7 @@ SingleBlurPassEffect::SingleBlurPassEffect(BlurEffect *parent) direction(HORIZONTAL), width(1280), height(720), - uniform_samples(NULL) + uniform_samples(nullptr) { register_float("radius", &radius); register_int("direction", (int *)&direction); @@ -189,24 +190,26 @@ void SingleBlurPassEffect::set_gl_state(GLuint glsl_program_num, const string &p uniform_samples[2 * 0 + 0] = 0.0f; uniform_samples[2 * 0 + 1] = weight[0]; + int size; + if (direction == HORIZONTAL) { + size = width; + } else if (direction == VERTICAL) { + size = height; + } else { + assert(false); + } + float num_subtexels = size / movit_texel_subpixel_precision; + float inv_num_subtexels = movit_texel_subpixel_precision / size; + // All other samples. for (int i = 1; i < num_taps / 2 + 1; ++i) { unsigned base_pos = i * 2 - 1; float w1 = weight[base_pos]; float w2 = weight[base_pos + 1]; - int size; - if (direction == HORIZONTAL) { - size = width; - } else if (direction == VERTICAL) { - size = height; - } else { - assert(false); - } float pos1 = base_pos / (float)size; - float pos2 = (base_pos + 1) / (float)size; float pos, total_weight; - combine_two_samples(w1, w2, pos1, pos2, size, &pos, &total_weight, NULL); + combine_two_samples(w1, w2, pos1, 1.0 / (float)size, size, num_subtexels, inv_num_subtexels, &pos, &total_weight, nullptr); uniform_samples[2 * i + 0] = pos; uniform_samples[2 * i + 1] = total_weight;