CXXFLAGS=-Wall -g
LDFLAGS=-lSDL -lSDL_image -lGL
OBJS=main.o util.o widgets.o effect.o effect_chain.o input.o
-OBJS += lift_gamma_gain_effect.o gamma_expansion_effect.o gamma_compression_effect.o colorspace_conversion_effect.o saturation_effect.o vignette_effect.o mirror_effect.o blur_effect.o diffusion_effect.o sandbox_effect.o
+OBJS += lift_gamma_gain_effect.o gamma_expansion_effect.o gamma_compression_effect.o colorspace_conversion_effect.o saturation_effect.o vignette_effect.o mirror_effect.o blur_effect.o diffusion_effect.o glow_effect.o mix_effect.o sandbox_effect.o
test: $(OBJS)
$(CXX) -o test $(OBJS) $(LDFLAGS)
#include "vignette_effect.h"
#include "blur_effect.h"
#include "diffusion_effect.h"
+#include "glow_effect.h"
+#include "mix_effect.h"
#include "input.h"
EffectChain::EffectChain(unsigned width, unsigned height)
return new BlurEffect();
case EFFECT_DIFFUSION:
return new DiffusionEffect();
+ case EFFECT_GLOW:
+ return new GlowEffect();
+ case EFFECT_MIX:
+ return new MixEffect();
}
assert(false);
}
EFFECT_VIGNETTE,
EFFECT_BLUR,
EFFECT_DIFFUSION,
+ EFFECT_GLOW,
+
+ // Combining.
+ EFFECT_MIX,
};
#endif // !defined(_EFFECT_ID_H)
--- /dev/null
+#include <math.h>
+#include <assert.h>
+
+#include "glow_effect.h"
+#include "blur_effect.h"
+#include "mix_effect.h"
+#include "effect_chain.h"
+#include "util.h"
+
+GlowEffect::GlowEffect()
+ : blur(new BlurEffect),
+ mix(new MixEffect)
+{
+ mix->set_float("strength_first", 1.0f);
+ mix->set_float("strength_second", 0.3f);
+}
+
+void GlowEffect::add_self_to_effect_chain(EffectChain *chain, const std::vector<Effect *> &inputs) {
+ assert(inputs.size() == 1);
+ blur->add_self_to_effect_chain(chain, inputs);
+
+ std::vector<Effect *> 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);
+}
+
+bool GlowEffect::set_float(const std::string &key, float value) {
+ if (key == "blurred_mix_amount") {
+ return mix->set_float("strength_second", value);
+ }
+ return blur->set_float(key, value);
+}
--- /dev/null
+#ifndef _GLOW_EFFECT_H
+#define _GLOW_EFFECT_H 1
+
+// Glow: Simply add a blurred version of the image to itself.
+
+#include "effect.h"
+
+class BlurEffect;
+class MixEffect;
+
+class GlowEffect : public Effect {
+public:
+ GlowEffect();
+
+ virtual bool needs_srgb_primaries() const { return false; }
+
+ virtual void add_self_to_effect_chain(EffectChain *chain, const std::vector<Effect *> &input);
+ virtual bool set_float(const std::string &key, float value);
+
+ virtual std::string output_fragment_shader() {
+ assert(false);
+ }
+ virtual void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) {
+ assert(false);
+ }
+
+private:
+ BlurEffect *blur;
+ MixEffect *mix;
+};
+
+#endif // !defined(_GLOW_EFFECT_H)
--- /dev/null
+#include "mix_effect.h"
+#include "util.h"
+
+MixEffect::MixEffect()
+ : strength_first(0.5f), strength_second(0.5f)
+{
+ register_float("strength_first", &strength_first);
+ register_float("strength_second", &strength_second);
+}
+
+std::string MixEffect::output_fragment_shader()
+{
+ return read_file("mix_effect.frag");
+}
--- /dev/null
+vec4 FUNCNAME(vec2 tc) {
+ vec4 first = INPUT1(tc);
+ vec4 second = INPUT2(tc);
+ return vec4(PREFIX(strength_first)) * first + vec4(PREFIX(strength_second)) * second;
+}
--- /dev/null
+#ifndef _MIX_EFFECT_H
+#define _MIX_EFFECT_H 1
+
+// Combine two images: a*x + b*y. (If you set a within [0,1] and b=1-a, you will get a fade.)
+
+#include "effect.h"
+
+class MixEffect : public Effect {
+public:
+ MixEffect();
+ std::string output_fragment_shader();
+
+ virtual bool needs_srgb_primaries() const { return false; }
+ virtual unsigned num_inputs() const { return 2; }
+
+private:
+ float strength_first, strength_second;
+};
+
+#endif // !defined(_MIX_EFFECT_H)