]> git.sesse.net Git - movit/commitdiff
Add a high-cutoff filter to the glow effect.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 16 Oct 2012 22:15:15 +0000 (00:15 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 16 Oct 2012 22:15:15 +0000 (00:15 +0200)
glow_effect.cpp
glow_effect.h
highlight_cutoff_effect.frag [new file with mode: 0644]

index 0868eb057662909fdc10e3544d996f1dc6bf6db6..a4775052d4503dbf7b6c0fc7f5b5d53ad584f811 100644 (file)
@@ -9,10 +9,13 @@
 
 GlowEffect::GlowEffect()
        : blur(new BlurEffect),
 
 GlowEffect::GlowEffect()
        : blur(new BlurEffect),
+         cutoff(new HighlightCutoffEffect),
          mix(new MixEffect)
 {
          mix(new MixEffect)
 {
+       blur->set_float("radius", 20.0f);
        mix->set_float("strength_first", 1.0f);
        mix->set_float("strength_first", 1.0f);
-       mix->set_float("strength_second", 0.3f);
+       mix->set_float("strength_second", 1.0f);
+       cutoff->set_float("cutoff", 0.2f);
 }
 
 void GlowEffect::rewrite_graph(EffectChain *graph, Node *self)
 }
 
 void GlowEffect::rewrite_graph(EffectChain *graph, Node *self)
@@ -22,8 +25,10 @@ void GlowEffect::rewrite_graph(EffectChain *graph, Node *self)
 
        Node *blur_node = graph->add_node(blur);
        Node *mix_node = graph->add_node(mix);
 
        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->replace_receiver(self, mix_node);
-       graph->connect_nodes(input, blur_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);
 
        graph->connect_nodes(blur_node, mix_node);
        graph->replace_sender(self, mix_node);
 
@@ -34,5 +39,19 @@ bool GlowEffect::set_float(const std::string &key, float value) {
        if (key == "blurred_mix_amount") {
                return mix->set_float("strength_second", 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);
 }
        return blur->set_float(key, value);
 }
+
+HighlightCutoffEffect::HighlightCutoffEffect()
+       : cutoff(0.0f)
+{
+       register_float("cutoff", &cutoff);
+}
+
+std::string HighlightCutoffEffect::output_fragment_shader()
+{
+       return read_file("highlight_cutoff_effect.frag");
+}
index 04b48f9aa165e55ab7ba139dba36c883fb492f9b..8b21e521a9449979aae90ad7df14ef903f8c6b34 100644 (file)
@@ -1,12 +1,14 @@
 #ifndef _GLOW_EFFECT_H
 #define _GLOW_EFFECT_H 1
 
 #ifndef _GLOW_EFFECT_H
 #define _GLOW_EFFECT_H 1
 
-// Glow: Simply add a blurred version of the image to itself.
+// Glow: Cut out the highlights of the image (everything above a certain threshold),
+// blur them, and overlay them onto the original image.
 
 #include "effect.h"
 
 class BlurEffect;
 class MixEffect;
 
 #include "effect.h"
 
 class BlurEffect;
 class MixEffect;
+class HighlightCutoffEffect;
 
 class GlowEffect : public Effect {
 public:
 
 class GlowEffect : public Effect {
 public:
@@ -27,7 +29,22 @@ public:
 
 private:
        BlurEffect *blur;
 
 private:
        BlurEffect *blur;
+       HighlightCutoffEffect *cutoff;
        MixEffect *mix;
 };
 
        MixEffect *mix;
 };
 
+// An effect that cuts out only the highlights of an image;
+// anything at the cutoff or below is set to 0.0, and then all other pixels
+// get the cutoff subtracted. Used only as part of GlowEffect.
+
+class HighlightCutoffEffect : public Effect {
+public:
+       HighlightCutoffEffect();
+       virtual std::string effect_type_id() const { return "HighlightCutoffEffect"; }
+       std::string output_fragment_shader();
+
+private:
+       float cutoff;
+};
+
 #endif // !defined(_GLOW_EFFECT_H)
 #endif // !defined(_GLOW_EFFECT_H)
diff --git a/highlight_cutoff_effect.frag b/highlight_cutoff_effect.frag
new file mode 100644 (file)
index 0000000..cb76630
--- /dev/null
@@ -0,0 +1,3 @@
+vec4 FUNCNAME(vec2 tc) {
+       return max(INPUT(tc) - vec4(PREFIX(cutoff)), 0.0);
+}