From e33b485dcb7bdbe056f6511945d5eb118c085d65 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 7 Nov 2013 00:20:59 +0100 Subject: [PATCH] Promote MultiplyEffect to a real effect. 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.) --- effect_chain_test.cpp | 27 +++++++++++---------------- multiply_effect.cpp | 15 +++++++++++++++ multiply.frag => multiply_effect.frag | 0 multiply_effect.h | 24 ++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 multiply_effect.cpp rename multiply.frag => multiply_effect.frag (100%) create mode 100644 multiply_effect.h diff --git a/effect_chain_test.cpp b/effect_chain_test.cpp index 442c2fb..8814e1f 100644 --- a/effect_chain_test.cpp +++ b/effect_chain_test.cpp @@ -11,6 +11,7 @@ #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" @@ -638,18 +639,6 @@ TEST(EffectChainTest, ResizeDownByFourThenUpByFour) { 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: @@ -680,11 +669,14 @@ TEST(EffectChainTest, DiamondGraph) { }; 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(); - ASSERT_TRUE(mul_half->set_float("factor", 0.5f)); + ASSERT_TRUE(mul_half->set_vec4("factor", half)); 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); @@ -726,11 +718,14 @@ TEST(EffectChainTest, DiamondGraphWithOneInputUsedInTwoPhases) { }; 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(); - ASSERT_TRUE(mul_half->set_float("factor", 0.5f)); + ASSERT_TRUE(mul_half->set_vec4("factor", half)); 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(); diff --git a/multiply_effect.cpp b/multiply_effect.cpp new file mode 100644 index 0000000..f3610d3 --- /dev/null +++ b/multiply_effect.cpp @@ -0,0 +1,15 @@ +#include + +#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"); +} diff --git a/multiply.frag b/multiply_effect.frag similarity index 100% rename from multiply.frag rename to multiply_effect.frag diff --git a/multiply_effect.h b/multiply_effect.h new file mode 100644 index 0000000..8de261a --- /dev/null +++ b/multiply_effect.h @@ -0,0 +1,24 @@ +#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 +#include + +#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) -- 2.39.2