1 #ifndef _MOVIT_COMPLEX_MODULATE_EFFECT_H
2 #define _MOVIT_COMPLEX_MODULATE_EFFECT_H 1
4 // An effect that treats each pixel as two complex numbers (xy and zw),
5 // and multiplies it with some other complex number (xy and xy, so the
6 // same in both cases). The latter can be repeated both horizontally and
7 // vertically if desired.
9 // The typical use is to implement convolution by way of FFT; since
10 // FFT(A ⊙ B) = FFT(A) * FFT(B), you can FFT both inputs (where B
11 // would often even be a constant, so you'd only need to do FFT once),
12 // multiply them together and then IFFT the result to get a convolution.
14 // It is in a sense “wrong” to do this directly on pixels, since the color
15 // channels are independent and real-valued (ie., not complex numbers), but
16 // since convolution is a linear operation, it's unproblematic to treat R + Gi
17 // as a single complex number and B + Ai and another one; barring numerical
18 // errors, there should be no leakage between the channels as long as you're
19 // convolving with a real quantity. (There are more sophisticated ways of doing
20 // two real FFTs with a single complex one, but we won't need them, as we
21 // don't care about the actual FFT result, just that the convolution property
33 class ComplexModulateEffect : public Effect {
35 ComplexModulateEffect();
36 virtual std::string effect_type_id() const { return "ComplexModulateEffect"; }
37 std::string output_fragment_shader();
39 // Technically we only need texture bounce for the second input
40 // (to be allowed to mess with its sampler state), but there's
41 // no way of expressing that currently.
42 virtual bool needs_texture_bounce() const { return true; }
43 virtual bool changes_output_size() const { return true; }
44 virtual bool sets_virtual_output_size() const { return false; }
46 virtual void inform_input_size(unsigned input_num, unsigned width, unsigned height);
47 virtual void get_output_size(unsigned *width, unsigned *height,
48 unsigned *virtual_width, unsigned *virtual_height) const;
49 virtual unsigned num_inputs() const { return 2; }
50 virtual void inform_added(EffectChain *chain) { this->chain = chain; }
52 void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num);
56 int primary_input_width, primary_input_height;
57 int num_repeats_x, num_repeats_y;
58 float uniform_num_repeats[2];
63 #endif // !defined(_MOVIT_COMPLEX_MODULATE_EFFECT_H)