X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=fft_pass_effect.cpp;h=4069be93f636d72a7682cb4971a2d9822afc4f98;hp=c2b47f047c0747459b92682895be7b9a147f5de2;hb=0cdd6e9e30a807056699ed9b3fa023a23ce83af9;hpb=c2371eea5dadf97add7c1a71b8ea660973c9c6de diff --git a/fft_pass_effect.cpp b/fft_pass_effect.cpp index c2b47f0..4069be9 100644 --- a/fft_pass_effect.cpp +++ b/fft_pass_effect.cpp @@ -1,6 +1,7 @@ #include #include +#include "effect_chain.h" #include "effect_util.h" #include "fp16.h" #include "fft_pass_effect.h" @@ -40,15 +41,13 @@ void FFTPassEffect::set_gl_state(GLuint glsl_program_num, const string &prefix, int input_size = (direction == VERTICAL) ? input_height : input_width; - // See the comments on changes_output_size() in the .h file to see - // why this is legal. It is _needed_ because it counteracts the - // precision issues we get because we sample the input texture with - // normalized coordinates (especially when the repeat count along - // the axis is not a power of two); we very rapidly end up in narrowly - // missing a texel center, which causes precision loss to propagate - // throughout the FFT. - assert(*sampler_num == 1); - glActiveTexture(GL_TEXTURE0); + // This is needed because it counteracts the precision issues we get + // because we sample the input texture with normalized coordinates + // (especially when the repeat count along the axis is not a power of + // two); we very rapidly end up in narrowly missing a texel center, + // which causes precision loss to propagate throughout the FFT. + Node *self = chain->find_node_for_effect(this); + glActiveTexture(chain->get_input_sampler(self, 0)); check_error(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); check_error(); @@ -118,15 +117,17 @@ void FFTPassEffect::set_gl_state(GLuint glsl_program_num, const string &prefix, // is that we can have multiple FFTs along the same line, // and want to reuse the support texture by repeating it. int base = k * stride * 2 + offset; - int support_texture_index; + int support_texture_index = i; + int src1 = base; + int src2 = base + stride; if (direction == FFTPassEffect::VERTICAL) { // Compensate for OpenGL's bottom-left convention. - support_texture_index = fft_size - i - 1; - } else { - support_texture_index = i; + support_texture_index = fft_size - support_texture_index - 1; + src1 = fft_size - src1 - 1; + src2 = fft_size - src2 - 1; } - tmp[support_texture_index * 4 + 0] = fp64_to_fp16((base - support_texture_index) / double(input_size)); - tmp[support_texture_index * 4 + 1] = fp64_to_fp16((base + stride - support_texture_index) / double(input_size)); + tmp[support_texture_index * 4 + 0] = fp64_to_fp16((src1 - support_texture_index) / double(input_size)); + tmp[support_texture_index * 4 + 1] = fp64_to_fp16((src2 - support_texture_index) / double(input_size)); tmp[support_texture_index * 4 + 2] = fp64_to_fp16(twiddle_real); tmp[support_texture_index * 4 + 3] = fp64_to_fp16(twiddle_imag); }