File: glow_effect.cpp

package info (click to toggle)
movit 1.7.2-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 3,248 kB
  • sloc: cpp: 16,677; sh: 3,940; makefile: 167
file content (63 lines) | stat: -rw-r--r-- 1,527 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <assert.h>
#include <vector>

#include "blur_effect.h"
#include "effect_chain.h"
#include "glow_effect.h"
#include "mix_effect.h"
#include "util.h"

using namespace std;

namespace movit {

GlowEffect::GlowEffect()
	: blur(new BlurEffect),
	  cutoff(new HighlightCutoffEffect),
	  mix(new MixEffect)
{
	CHECK(blur->set_float("radius", 20.0f));
	CHECK(mix->set_float("strength_first", 1.0f));
	CHECK(mix->set_float("strength_second", 1.0f));
	CHECK(cutoff->set_float("cutoff", 0.2f));
}

void GlowEffect::rewrite_graph(EffectChain *graph, Node *self)
{
	assert(self->incoming_links.size() == 1);
	Node *input = self->incoming_links[0];

	Node *blur_node = graph->add_node(blur);
	Node *mix_node = graph->add_node(mix);
	Node *cutoff_node = graph->add_node(cutoff);
	graph->replace_receiver(self, mix_node);
	graph->connect_nodes(input, cutoff_node);
	graph->connect_nodes(cutoff_node, blur_node);
	graph->connect_nodes(blur_node, mix_node);
	graph->replace_sender(self, mix_node);

	self->disabled = true;
}

bool GlowEffect::set_float(const string &key, float value) {
	if (key == "blurred_mix_amount") {
		return mix->set_float("strength_second", value);
	}
	if (key == "highlight_cutoff") {
		return cutoff->set_float("cutoff", value);
	}
	return blur->set_float(key, value);
}

HighlightCutoffEffect::HighlightCutoffEffect()
	: cutoff(0.0f)
{
	register_float("cutoff", &cutoff);
}

string HighlightCutoffEffect::output_fragment_shader()
{
	return read_file("highlight_cutoff_effect.frag");
}

}  // namespace movit