Clamp alpha in MixEffect.
[movit] / mix_effect_test.cpp
index d49efd7..096ecd5 100644 (file)
@@ -80,6 +80,34 @@ TEST(MixEffectTest, DoesNotSumToOne) {
        expect_equal(expected_data, out_data, 4, 1);
 }
 
+TEST(MixEffectTest, AdditiveBlendingWorksForBothTotallyOpaqueAndPartiallyTranslucent) {
+       float data_a[] = {
+               0.0f, 0.5f, 0.75f, 1.0f,
+               1.0f, 1.0f, 1.0f, 0.2f,
+       };
+       float data_b[] = {
+               1.0f, 0.25f, 0.15f, 1.0f,
+               1.0f, 1.0f, 1.0f, 0.5f,
+       };
+
+       float expected_data[] = {
+               1.0f, 0.75f, 0.9f, 1.0f,
+               1.0f, 1.0f, 1.0f, 0.7f,
+       };
+
+       float out_data[4];
+       EffectChainTester tester(data_a, 1, 2, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
+       Effect *input1 = tester.get_chain()->last_added_effect();
+       Effect *input2 = tester.add_input(data_b, FORMAT_RGBA_POSTMULTIPLIED_ALPHA, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       Effect *mix_effect = tester.get_chain()->add_effect(new MixEffect(), input1, input2);
+       ASSERT_TRUE(mix_effect->set_float("strength_first", 1.0f));
+       ASSERT_TRUE(mix_effect->set_float("strength_second", 1.0f));
+       tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(expected_data, out_data, 4, 2);
+}
+
 TEST(MixEffectTest, MixesLinearlyDespitesRGBInputsAndOutputs) {
        float data_a[] = {
                0.0f, 0.25f,