]> git.sesse.net Git - movit/blob - glow_effect.cpp
Add (safe) asserts around all Effect::set_* return values, and add warnings for not...
[movit] / glow_effect.cpp
1 #include <math.h>
2 #include <assert.h>
3
4 #include "glow_effect.h"
5 #include "blur_effect.h"
6 #include "mix_effect.h"
7 #include "effect_chain.h"
8 #include "util.h"
9
10 GlowEffect::GlowEffect()
11         : blur(new BlurEffect),
12           cutoff(new HighlightCutoffEffect),
13           mix(new MixEffect)
14 {
15         CHECK(blur->set_float("radius", 20.0f));
16         CHECK(mix->set_float("strength_first", 1.0f));
17         CHECK(mix->set_float("strength_second", 1.0f));
18         CHECK(cutoff->set_float("cutoff", 0.2f));
19 }
20
21 void GlowEffect::rewrite_graph(EffectChain *graph, Node *self)
22 {
23         assert(self->incoming_links.size() == 1);
24         Node *input = self->incoming_links[0];
25
26         Node *blur_node = graph->add_node(blur);
27         Node *mix_node = graph->add_node(mix);
28         Node *cutoff_node = graph->add_node(cutoff);
29         graph->replace_receiver(self, mix_node);
30         graph->connect_nodes(input, cutoff_node);
31         graph->connect_nodes(cutoff_node, blur_node);
32         graph->connect_nodes(blur_node, mix_node);
33         graph->replace_sender(self, mix_node);
34
35         self->disabled = true;
36 }
37
38 bool GlowEffect::set_float(const std::string &key, float value) {
39         if (key == "blurred_mix_amount") {
40                 return mix->set_float("strength_second", value);
41         }
42         if (key == "highlight_cutoff") {
43                 return cutoff->set_float("cutoff", value);
44         }
45         return blur->set_float(key, value);
46 }
47
48 HighlightCutoffEffect::HighlightCutoffEffect()
49         : cutoff(0.0f)
50 {
51         register_float("cutoff", &cutoff);
52 }
53
54 std::string HighlightCutoffEffect::output_fragment_shader()
55 {
56         return read_file("highlight_cutoff_effect.frag");
57 }