]> git.sesse.net Git - movit/blob - diffusion_effect.h
Merge branch 'master' into epoxy
[movit] / diffusion_effect.h
1 #ifndef _MOVIT_DIFFUSION_EFFECT_H
2 #define _MOVIT_DIFFUSION_EFFECT_H 1
3
4 // There are many different effects that go under the name of "diffusion",
5 // seemingly all of the inspired by the effect you get when you put a
6 // diffusion filter in front of your camera lens. The effect most people
7 // want is a general flattening/smoothing of the light, and reduction of
8 // fine detail (most notably, blemishes in people's skin), without ruining
9 // edges, which a regular blur would do.
10 //
11 // We do a relatively simple version, sometimes known as "white diffusion",
12 // where we first blur the picture, and then overlay it on the original
13 // using the original as a matte.
14
15 #include <epoxy/gl.h>
16 #include <assert.h>
17 #include <string>
18
19 #include "effect.h"
20
21 namespace movit {
22
23 class BlurEffect;
24 class EffectChain;
25 class Node;
26 class OverlayMatteEffect;
27
28 class DiffusionEffect : public Effect {
29 public:
30         DiffusionEffect();
31         virtual std::string effect_type_id() const { return "DiffusionEffect"; }
32
33         virtual void rewrite_graph(EffectChain *graph, Node *self);
34         virtual bool set_float(const std::string &key, float value);
35         
36         virtual std::string output_fragment_shader() {
37                 assert(false);
38         }
39         virtual void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) {
40                 assert(false);
41         }
42
43 private:
44         BlurEffect *blur;
45         OverlayMatteEffect *overlay_matte;
46 };
47
48 // Used internally by DiffusionEffect; combines the blurred and the original
49 // version using the original as a matte.
50 class OverlayMatteEffect : public Effect {
51 public:
52         OverlayMatteEffect();
53         virtual std::string effect_type_id() const { return "OverlayMatteEffect"; }
54         std::string output_fragment_shader();
55         virtual AlphaHandling alpha_handling() const { return INPUT_PREMULTIPLIED_ALPHA_KEEP_BLANK; }
56
57         unsigned num_inputs() const { return 2; }
58
59 private:
60         float blurred_mix_amount;
61 };
62
63 }  // namespace movit
64
65 #endif // !defined(_MOVIT_DIFFUSION_EFFECT_H)