X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=glow_effect.cpp;h=778c55752fecceb984e4a9f97d39ba7cc4186e9d;hp=e4c9a421eef06cbec6a3d125e4b9cb5d92fbaa5e;hb=a5f32397f9c23fa8644fe195865d6c36685cf866;hpb=ef7665d0d3854b3464800d8d7fef9a90f14d9a9f diff --git a/glow_effect.cpp b/glow_effect.cpp index e4c9a42..778c557 100644 --- a/glow_effect.cpp +++ b/glow_effect.cpp @@ -1,33 +1,63 @@ -#include #include +#include -#include "glow_effect.h" #include "blur_effect.h" -#include "mix_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) { - mix->set_float("strength_first", 1.0f); - mix->set_float("strength_second", 0.3f); + 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::add_self_to_effect_chain(EffectChain *chain, const std::vector &inputs) { - assert(inputs.size() == 1); - blur->add_self_to_effect_chain(chain, inputs); +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); - std::vector mix_inputs; - mix_inputs.push_back(inputs[0]); - mix_inputs.push_back(chain->last_added_effect()); // FIXME - mix->add_self_to_effect_chain(chain, mix_inputs); + self->disabled = true; } -bool GlowEffect::set_float(const std::string &key, float value) { +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