The intended use is for overlays, where you'd want to do e.g.
0.2*x atop y instead of just x atop y, fading the overlay in or out.
Also, give it full RGBA inputs, as that might potentially be useful
for someone. It certainly was useful for adapting it to continue to
be used in the EffectChain unit test, at least. (It doesn't have
its own unit test, since it's so trivial.)
#include "gtest/gtest.h"
#include "input.h"
#include "mirror_effect.h"
#include "gtest/gtest.h"
#include "input.h"
#include "mirror_effect.h"
+#include "multiply_effect.h"
#include "resize_effect.h"
#include "test_util.h"
#include "util.h"
#include "resize_effect.h"
#include "test_util.h"
#include "util.h"
expect_equal(expected_data, out_data, 4, 16);
}
expect_equal(expected_data, out_data, 4, 16);
}
-// An effect that multiplies with a constant. Used below.
-class MultiplyEffect : public Effect {
-public:
- MultiplyEffect() { register_float("factor", &factor); }
- virtual std::string effect_type_id() const { return "MultiplyEffect"; }
- std::string output_fragment_shader() { return read_file("multiply.frag"); }
- virtual AlphaHandling alpha_handling() const { return DONT_CARE_ALPHA_TYPE; }
-
-private:
- float factor;
-};
-
// An effect that adds its two inputs together. Used below.
class AddEffect : public Effect {
public:
// An effect that adds its two inputs together. Used below.
class AddEffect : public Effect {
public:
};
float out_data[2 * 2];
};
float out_data[2 * 2];
+ const float half[] = { 0.5f, 0.5f, 0.5f, 0.5f };
+ const float two[] = { 2.0f, 2.0f, 2.0f, 0.5f };
+
MultiplyEffect *mul_half = new MultiplyEffect();
MultiplyEffect *mul_half = new MultiplyEffect();
- ASSERT_TRUE(mul_half->set_float("factor", 0.5f));
+ ASSERT_TRUE(mul_half->set_vec4("factor", half));
MultiplyEffect *mul_two = new MultiplyEffect();
MultiplyEffect *mul_two = new MultiplyEffect();
- ASSERT_TRUE(mul_two->set_float("factor", 2.0f));
+ ASSERT_TRUE(mul_two->set_vec4("factor", two));
EffectChainTester tester(NULL, 2, 2);
EffectChainTester tester(NULL, 2, 2);
};
float out_data[2 * 2];
};
float out_data[2 * 2];
+ const float half[] = { 0.5f, 0.5f, 0.5f, 0.5f };
+ const float two[] = { 2.0f, 2.0f, 2.0f, 0.5f };
+
MultiplyEffect *mul_half = new MultiplyEffect();
MultiplyEffect *mul_half = new MultiplyEffect();
- ASSERT_TRUE(mul_half->set_float("factor", 0.5f));
+ ASSERT_TRUE(mul_half->set_vec4("factor", half));
MultiplyEffect *mul_two = new MultiplyEffect();
MultiplyEffect *mul_two = new MultiplyEffect();
- ASSERT_TRUE(mul_two->set_float("factor", 2.0f));
+ ASSERT_TRUE(mul_two->set_vec4("factor", two));
BouncingIdentityEffect *bounce = new BouncingIdentityEffect();
BouncingIdentityEffect *bounce = new BouncingIdentityEffect();
--- /dev/null
+#include <GL/glew.h>
+
+#include "multiply_effect.h"
+#include "util.h"
+
+MultiplyEffect::MultiplyEffect()
+ : factor(1.0f, 1.0f, 1.0f, 1.0f)
+{
+ register_vec4("factor", (float *)&factor);
+}
+
+std::string MultiplyEffect::output_fragment_shader()
+{
+ return read_file("multiply_effect.frag");
+}
--- /dev/null
+#ifndef _MOVIT_MULTIPLY_EFFECT_H
+#define _MOVIT_MULTIPLY_EFFECT_H 1
+
+// An effect that multiplies every pixel by a constant (separate for each of
+// R, G, B, A). A common use would be to reduce the alpha of an overlay before
+// sending it through OverlayEffect, e.g. with R=G=B=A=0.3 to get 30% alpha
+// (remember, alpha is premultiplied).
+
+#include <GL/glew.h>
+#include <string>
+
+#include "effect.h"
+
+class MultiplyEffect : public Effect {
+public:
+ MultiplyEffect();
+ virtual std::string effect_type_id() const { return "MultiplyEffect"; }
+ std::string output_fragment_shader();
+
+private:
+ RGBATuple factor;
+};
+
+#endif // !defined(_MOVIT_MULTIPLY_EFFECT_H)