X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=blur_effect.cpp;h=2084768bc54393985bbfccdf48f0be1f10741f08;hp=027d25b1113ef83e37f472e5dc561b95251a5484;hb=c6c3847558f3724f2b8973aa503de0e6c3de5816;hpb=8b58b0d92cbf62e173bd8a903774ba0d2c91c81f diff --git a/blur_effect.cpp b/blur_effect.cpp index 027d25b..2084768 100644 --- a/blur_effect.cpp +++ b/blur_effect.cpp @@ -108,8 +108,9 @@ SingleBlurPassEffect::SingleBlurPassEffect(BlurEffect *parent) num_taps(16), radius(3.0f), direction(HORIZONTAL), - width(1280), - height(720) + width(1280), + height(720), + uniform_samples(NULL) { register_float("radius", &radius); register_int("direction", (int *)&direction); @@ -120,11 +121,18 @@ SingleBlurPassEffect::SingleBlurPassEffect(BlurEffect *parent) register_int("num_taps", &num_taps); } +SingleBlurPassEffect::~SingleBlurPassEffect() +{ + delete[] uniform_samples; +} + string SingleBlurPassEffect::output_fragment_shader() { char buf[256]; sprintf(buf, "#define DIRECTION_VERTICAL %d\n#define NUM_TAPS %d\n", (direction == VERTICAL), num_taps); + uniform_samples = new float[2 * (num_taps / 2 + 1)]; + register_uniform_vec2_array("samples", uniform_samples, num_taps / 2 + 1); return buf + read_file("blur_effect.frag"); } @@ -176,36 +184,35 @@ void SingleBlurPassEffect::set_gl_state(GLuint glsl_program_num, const string &p // // We pack the parameters into a float4: The relative sample coordinates // in (x,y), and the weight in z. w is unused. - float* samples = new float[2 * (num_taps / 2 + 1)]; // Center sample. - samples[2 * 0 + 0] = 0.0f; - samples[2 * 0 + 1] = weight[0]; + uniform_samples[2 * 0 + 0] = 0.0f; + uniform_samples[2 * 0 + 1] = weight[0]; // 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]; - - float offset, total_weight; - combine_two_samples(w1, w2, &offset, &total_weight, NULL); - + int size; if (direction == HORIZONTAL) { - samples[2 * i + 0] = (base_pos + offset) / (float)width; + size = width; } else if (direction == VERTICAL) { - samples[2 * i + 0] = (base_pos + offset) / (float)height; + size = height; } else { assert(false); } - samples[2 * i + 1] = total_weight; - } + 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); - set_uniform_vec2_array(glsl_program_num, prefix, "samples", samples, num_taps / 2 + 1); + uniform_samples[2 * i + 0] = pos; + uniform_samples[2 * i + 1] = total_weight; + } delete[] weight; - delete[] samples; } void SingleBlurPassEffect::clear_gl_state()