]> git.sesse.net Git - casparcg/commitdiff
2.0. mixer: Added screen blending mode.
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Wed, 22 Jun 2011 08:02:27 +0000 (08:02 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Wed, 22 Jun 2011 08:02:27 +0000 (08:02 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@937 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

core/core.vcxproj
core/core.vcxproj.filters
core/mixer/image/image_kernel.cpp
core/mixer/image/photoshop_math.h [new file with mode: 0644]
core/producer/frame/image_transform.cpp
core/producer/frame/image_transform.h
protocol/amcp/AMCPCommandsImpl.cpp

index e70447e5af29bb4222b311a144c79ef92d8ffbac..b2ab9d6b609224d93a8d737d7d9c6dca72f55c4d 100644 (file)
     <Lib />\r
   </ItemDefinitionGroup>\r
   <ItemGroup>\r
+    <ClInclude Include="mixer\image\photoshop_math.h" />\r
     <ClInclude Include="video_channel.h" />\r
     <ClInclude Include="video_channel_context.h" />\r
     <ClInclude Include="consumer\output.h" />\r
index 17ccc81b99617630dba3c41498b6710b8cfbd958..3530b12720601e0b9620db236699f02a7b265b2a 100644 (file)
     <ClInclude Include="video_channel_context.h">\r
       <Filter>source</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="mixer\image\photoshop_math.h">\r
+      <Filter>source\mixer\image</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClCompile Include="producer\transition\transition_producer.cpp">\r
index 7e6704e440c8244398ad651f912edf678016f850..0e84124946b85ae72963a3f9098896d7fb7eaf16 100644 (file)
@@ -160,7 +160,6 @@ public:
        {\r
                GL(glEnable(GL_POLYGON_STIPPLE));\r
                GL(glEnable(GL_BLEND));\r
-               GL(glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE));\r
 \r
                if(shaders_.empty())\r
                {\r
@@ -321,6 +320,15 @@ void image_kernel::draw(size_t width, size_t height, const core::pixel_format_de
        if(transform.get_opacity() < 0.001)\r
                return;\r
 \r
+       switch(transform.get_blend_mode())\r
+       {\r
+       case image_transform::screen:\r
+               GL(glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_COLOR, GL_ONE, GL_ONE));\r
+                       break;\r
+       default:\r
+               GL(glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE));\r
+       }\r
+\r
        GL(glEnable(GL_TEXTURE_2D));\r
        GL(glDisable(GL_DEPTH_TEST));   \r
 \r
diff --git a/core/mixer/image/photoshop_math.h b/core/mixer/image/photoshop_math.h
new file mode 100644 (file)
index 0000000..bfa8fe1
--- /dev/null
@@ -0,0 +1,251 @@
+#pragma once\r
+\r
+static std::string get_math_glsl()\r
+{\r
+       static std::string glsl = \r
+               "/*                                                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "** Photoshop & misc math                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "** Blending modes, RGB/HSL/Contrast/Desaturate, levels control                                                                                                                                                                                                                                                                                                    "\r
+               "**                                                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "** Romain Dura | Romz                                                                                                                                                                                                                                                                                                                                                                                     "\r
+               "** Blog: http://blog.mouaif.org                                                                                                                                                                                                                                                                                                                                                                   "\r
+               "** Post: http://blog.mouaif.org/?p=94                                                                                                                                                                                                                                                                                                                                                     "\r
+               "*/                                                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "/*                                                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "** Desaturation                                                                                                                                                                                                                                                                                                                                                                                                   "\r
+               "*/                                                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "vec4 Desaturate(vec3 color, float Desaturation)                                                                                                                                                                                                                                                                                                                                   "\r
+               "{                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "       vec3 grayXfer = vec3(0.3, 0.59, 0.11);                                                                                                                                                                                                                                                                                                                                             "\r
+               "       vec3 gray = vec3(dot(grayXfer, color));                                                                                                                                                                                                                                                                                                                                            "\r
+               "       return vec4(mix(color, gray, Desaturation), 1.0);                                                                                                                                                                                                                                                                                                                          "\r
+               "}                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "/*                                                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "** Hue, saturation, luminance                                                                                                                                                                                                                                                                                                                                                                     "\r
+               "*/                                                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "vec3 RGBToHSL(vec3 color)                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "{                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "       vec3 hsl; // init to 0 to avoid warnings ? (and reverse if + remove first part)                                                                                                                                                                                                                                                            "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "       float fmin = min(min(color.r, color.g), color.b);    //Min. value of RGB                                                                                                                                                                                                                                                                           "\r
+               "       float fmax = max(max(color.r, color.g), color.b);    //Max. value of RGB                                                                                                                                                                                                                                                                           "\r
+               "       float delta = fmax - fmin;             //Delta RGB value                                                                                                                                                                                                                                                                                                           "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "       hsl.z = (fmax + fmin) / 2.0; // Luminance                                                                                                                                                                                                                                                                                                                                          "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "       if (delta == 0.0)               //This is a gray, no chroma...                                                                                                                                                                                                                                                                                                             "\r
+               "       {                                                                                                                                                                                                                                                                                                                                                                                                                          "\r
+               "               hsl.x = 0.0;    // Hue                                                                                                                                                                                                                                                                                                                                                                     "\r
+               "               hsl.y = 0.0;    // Saturation                                                                                                                                                                                                                                                                                                                                                      "\r
+               "       }                                                                                                                                                                                                                                                                                                                                                                                                                          "\r
+               "       else                                    //Chromatic data...                                                                                                                                                                                                                                                                                                        "\r
+               "       {                                                                                                                                                                                                                                                                                                                                                                                                                          "\r
+               "               if (hsl.z < 0.5)                                                                                                                                                                                                                                                                                                                                                                                   "\r
+               "                       hsl.y = delta / (fmax + fmin); // Saturation                                                                                                                                                                                                                                                                                                               "\r
+               "               else                                                                                                                                                                                                                                                                                                                                                                                                       "\r
+               "                       hsl.y = delta / (2.0 - fmax - fmin); // Saturation                                                                                                                                                                                                                                                                                                         "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "               float deltaR = (((fmax - color.r) / 6.0) + (delta / 2.0)) / delta;                                                                                                                                                                                                                                                                                 "\r
+               "               float deltaG = (((fmax - color.g) / 6.0) + (delta / 2.0)) / delta;                                                                                                                                                                                                                                                                                 "\r
+               "               float deltaB = (((fmax - color.b) / 6.0) + (delta / 2.0)) / delta;                                                                                                                                                                                                                                                                                 "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "               if (color.r == fmax )                                                                                                                                                                                                                                                                                                                                                                      "\r
+               "                       hsl.x = deltaB - deltaG; // Hue                                                                                                                                                                                                                                                                                                                                            "\r
+               "               else if (color.g == fmax)                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "                       hsl.x = (1.0 / 3.0) + deltaR - deltaB; // Hue                                                                                                                                                                                                                                                                                                              "\r
+               "               else if (color.b == fmax)                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "                       hsl.x = (2.0 / 3.0) + deltaG - deltaR; // Hue                                                                                                                                                                                                                                                                                                              "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "               if (hsl.x < 0.0)                                                                                                                                                                                                                                                                                                                                                                                   "\r
+               "                       hsl.x += 1.0; // Hue                                                                                                                                                                                                                                                                                                                                                               "\r
+               "               else if (hsl.x > 1.0)                                                                                                                                                                                                                                                                                                                                                                      "\r
+               "                       hsl.x -= 1.0; // Hue                                                                                                                                                                                                                                                                                                                                                               "\r
+               "       }                                                                                                                                                                                                                                                                                                                                                                                                                          "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "       return hsl;                                                                                                                                                                                                                                                                                                                                                                                                        "\r
+               "}                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "float HueToRGB(float f1, float f2, float hue)                                                                                                                                                                                                                                                                                                                                     "\r
+               "{                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "       if (hue < 0.0)                                                                                                                                                                                                                                                                                                                                                                                             "\r
+               "               hue += 1.0;                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "       else if (hue > 1.0)                                                                                                                                                                                                                                                                                                                                                                                        "\r
+               "               hue -= 1.0;                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "       float res;                                                                                                                                                                                                                                                                                                                                                                                                         "\r
+               "       if ((6.0 * hue) < 1.0)                                                                                                                                                                                                                                                                                                                                                                             "\r
+               "               res = f1 + (f2 - f1) * 6.0 * hue;                                                                                                                                                                                                                                                                                                                                                  "\r
+               "       else if ((2.0 * hue) < 1.0)                                                                                                                                                                                                                                                                                                                                                                        "\r
+               "               res = f2;                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "       else if ((3.0 * hue) < 2.0)                                                                                                                                                                                                                                                                                                                                                                        "\r
+               "               res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0;                                                                                                                                                                                                                                                                                                                  "\r
+               "       else                                                                                                                                                                                                                                                                                                                                                                                                               "\r
+               "               res = f1;                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "       return res;                                                                                                                                                                                                                                                                                                                                                                                                        "\r
+               "}                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "vec3 HSLToRGB(vec3 hsl)                                                                                                                                                                                                                                                                                                                                                                                   "\r
+               "{                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "       vec3 rgb;                                                                                                                                                                                                                                                                                                                                                                                                          "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "       if (hsl.y == 0.0)                                                                                                                                                                                                                                                                                                                                                                                          "\r
+               "               rgb = vec3(hsl.z); // Luminance                                                                                                                                                                                                                                                                                                                                                    "\r
+               "       else                                                                                                                                                                                                                                                                                                                                                                                                               "\r
+               "       {                                                                                                                                                                                                                                                                                                                                                                                                                          "\r
+               "               float f2;                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "               if (hsl.z < 0.5)                                                                                                                                                                                                                                                                                                                                                                                   "\r
+               "                       f2 = hsl.z * (1.0 + hsl.y);                                                                                                                                                                                                                                                                                                                                                        "\r
+               "               else                                                                                                                                                                                                                                                                                                                                                                                                       "\r
+               "                       f2 = (hsl.z + hsl.y) - (hsl.y * hsl.z);                                                                                                                                                                                                                                                                                                                            "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "               float f1 = 2.0 * hsl.z - f2;                                                                                                                                                                                                                                                                                                                                                       "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "               rgb.r = HueToRGB(f1, f2, hsl.x + (1.0/3.0));                                                                                                                                                                                                                                                                                                                       "\r
+               "               rgb.g = HueToRGB(f1, f2, hsl.x);                                                                                                                                                                                                                                                                                                                                                   "\r
+               "               rgb.b= HueToRGB(f1, f2, hsl.x - (1.0/3.0));                                                                                                                                                                                                                                                                                                                                "\r
+               "       }                                                                                                                                                                                                                                                                                                                                                                                                                          "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "       return rgb;                                                                                                                                                                                                                                                                                                                                                                                                        "\r
+               "}                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "/*                                                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "** Contrast, saturation, brightness                                                                                                                                                                                                                                                                                                                                                       "\r
+               "** Code of this function is from TGM's shader pack                                                                                                                                                                                                                                                                                                                                "\r
+               "** http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=21057                                                                                                                                                                                                                                                                                                   "\r
+               "*/                                                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "// For all settings: 1.0 = 100% 0.5=50% 1.5 = 150%                                                                                                                                                                                                                                                                                                                                "\r
+               "vec3 ContrastSaturationBrightness(vec3 color, float brt, float sat, float con)                                                                                                                                                                                                                                                                    "\r
+               "{                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "       // Increase or decrease theese values to adjust r, g and b color channels seperately                                                                                                                                                                                                                                               "\r
+               "       const float AvgLumR = 0.5;                                                                                                                                                                                                                                                                                                                                                                         "\r
+               "       const float AvgLumG = 0.5;                                                                                                                                                                                                                                                                                                                                                                         "\r
+               "       const float AvgLumB = 0.5;                                                                                                                                                                                                                                                                                                                                                                         "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "       const vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721);                                                                                                                                                                                                                                                                                                                        "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "       vec3 AvgLumin = vec3(AvgLumR, AvgLumG, AvgLumB);                                                                                                                                                                                                                                                                                                                           "\r
+               "       vec3 brtColor = color * brt;                                                                                                                                                                                                                                                                                                                                                               "\r
+               "       vec3 intensity = vec3(dot(brtColor, LumCoeff));                                                                                                                                                                                                                                                                                                                            "\r
+               "       vec3 satColor = mix(intensity, brtColor, sat);                                                                                                                                                                                                                                                                                                                             "\r
+               "       vec3 conColor = mix(AvgLumin, satColor, con);                                                                                                                                                                                                                                                                                                                              "\r
+               "       return conColor;                                                                                                                                                                                                                                                                                                                                                                                           "\r
+               "}                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "/*                                                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "** Float blending modes                                                                                                                                                                                                                                                                                                                                                                                   "\r
+               "** Adapted from here: http://www.nathanm.com/photoshop-blending-math/                                                                                                                                                                                                                                                                                     "\r
+               "** But I modified the HardMix (wrong condition), Overlay, SoftLight, ColorDodge, ColorBurn, VividLight, PinLight (inverted layers) ones to have correct results                                                                                                   "\r
+               "*/                                                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "#define BlendLinearDodgef                                      BlendAddf                                                                                                                                                                                                                                                                                                                                          "\r
+               "#define BlendLinearBurnf                                       BlendSubstractf                                                                                                                                                                                                                                                                                                                            "\r
+               "#define BlendAddf(base, blend)                         min(base + blend, 1.0)                                                                                                                                                                                                                                                                                                     "\r
+               "#define BlendSubstractf(base, blend)           max(base + blend - 1.0, 0.0)                                                                                                                                                                                                                                                                                       "\r
+               "#define BlendLightenf(base, blend)             max(blend, base)                                                                                                                                                                                                                                                                                                           "\r
+               "#define BlendDarkenf(base, blend)                      min(blend, base)                                                                                                                                                                                                                                                                                                                   "\r
+               "#define BlendLinearLightf(base, blend)         (blend < 0.5 ? BlendLinearBurnf(base, (2.0 * blend)) : BlendLinearDodgef(base, (2.0 * (blend - 0.5))))                                                                                                                             "\r
+               "#define BlendScreenf(base, blend)                      (1.0 - ((1.0 - base) * (1.0 - blend)))                                                                                                                                                                                                                                                                     "\r
+               "#define BlendOverlayf(base, blend)             (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)))                                                                                                                                                                                   "\r
+               "#define BlendSoftLightf(base, blend)           ((blend < 0.5) ? (2.0 * base * blend + base * base * (1.0 - 2.0 * blend)) : (sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend)))                                                       "\r
+               "#define BlendColorDodgef(base, blend)          ((blend == 1.0) ? blend : min(base / (1.0 - blend), 1.0))                                                                                                                                                                                                                                  "\r
+               "#define BlendColorBurnf(base, blend)           ((blend == 0.0) ? blend : max((1.0 - ((1.0 - base) / blend)), 0.0))                                                                                                                                                                                                                "\r
+               "#define BlendVividLightf(base, blend)          ((blend < 0.5) ? BlendColorBurnf(base, (2.0 * blend)) : BlendColorDodgef(base, (2.0 * (blend - 0.5))))                                                                                                                                     "\r
+               "#define BlendPinLightf(base, blend)            ((blend < 0.5) ? BlendDarkenf(base, (2.0 * blend)) : BlendLightenf(base, (2.0 *(blend - 0.5))))                                                                                                                                                    "\r
+               "#define BlendHardMixf(base, blend)             ((BlendVividLightf(base, blend) < 0.5) ? 0.0 : 1.0)                                                                                                                                                                                                                                                "\r
+               "#define BlendReflectf(base, blend)             ((blend == 1.0) ? blend : min(base * base / (1.0 - blend), 1.0))                                                                                                                                                                                                           "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "/*                                                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "** Vector3 blending modes                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "*/                                                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "// Component wise blending                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "#define Blend(base, blend, funcf)                      vec3(funcf(base.r, blend.r), funcf(base.g, blend.g), funcf(base.b, blend.b))                                                                                                                                                                                       "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "#define BlendNormal(base, blend)                       (blend)                                                                                                                                                                                                                                                                                                                                    "\r
+               "#define BlendLighten                                           BlendLightenf                                                                                                                                                                                                                                                                                                                              "\r
+               "#define BlendDarken                                            BlendDarkenf                                                                                                                                                                                                                                                                                                                               "\r
+               "#define BlendMultiply(base, blend)             (base * blend)                                                                                                                                                                                                                                                                                                             "\r
+               "#define BlendAverage(base, blend)                      ((base + blend) / 2.0)                                                                                                                                                                                                                                                                                                     "\r
+               "#define BlendAdd(base, blend)                          min(base + blend, vec3(1.0))                                                                                                                                                                                                                                                                                               "\r
+               "#define BlendSubstract(base, blend)            max(base + blend - vec3(1.0), vec3(0.0))                                                                                                                                                                                                                                                                   "\r
+               "#define BlendDifference(base, blend)           abs(base - blend)                                                                                                                                                                                                                                                                                                                  "\r
+               "#define BlendNegation(base, blend)             (vec3(1.0) - abs(vec3(1.0) - base - blend))                                                                                                                                                                                                                                                                "\r
+               "#define BlendExclusion(base, blend)            (base + blend - 2.0 * base * blend)                                                                                                                                                                                                                                                                                "\r
+               "#define BlendScreen(base, blend)                       Blend(base, blend, BlendScreenf)                                                                                                                                                                                                                                                                                   "\r
+               "#define BlendOverlay(base, blend)                      Blend(base, blend, BlendOverlayf)                                                                                                                                                                                                                                                                                  "\r
+               "#define BlendSoftLight(base, blend)            Blend(base, blend, BlendSoftLightf)                                                                                                                                                                                                                                                                                "\r
+               "#define BlendHardLight(base, blend)            BlendOverlay(blend, base)                                                                                                                                                                                                                                                                                                  "\r
+               "#define BlendColorDodge(base, blend)           Blend(base, blend, BlendColorDodgef)                                                                                                                                                                                                                                                                       "\r
+               "#define BlendColorBurn(base, blend)            Blend(base, blend, BlendColorBurnf)                                                                                                                                                                                                                                                                                "\r
+               "#define BlendLinearDodge                                       BlendAdd                                                                                                                                                                                                                                                                                                                                           "\r
+               "#define BlendLinearBurn                                        BlendSubstract                                                                                                                                                                                                                                                                                                                             "\r
+               "// Linear Light is another contrast-increasing mode                                                                                                                                                                                                                                                                                                                       "\r
+               "// If the blend color is darker than midgray, Linear Light darkens the image by decreasing the brightness. If the blend color is lighter than midgray, the result is a brighter image due to increased brightness."\r
+               "#define BlendLinearLight(base, blend)          Blend(base, blend, BlendLinearLightf)                                                                                                                                                                                                                                                                      "\r
+               "#define BlendVividLight(base, blend)           Blend(base, blend, BlendVividLightf)                                                                                                                                                                                                                                                                       "\r
+               "#define BlendPinLight(base, blend)             Blend(base, blend, BlendPinLightf)                                                                                                                                                                                                                                                                         "\r
+               "#define BlendHardMix(base, blend)                      Blend(base, blend, BlendHardMixf)                                                                                                                                                                                                                                                                                  "\r
+               "#define BlendReflect(base, blend)                      Blend(base, blend, BlendReflectf)                                                                                                                                                                                                                                                                                  "\r
+               "#define BlendGlow(base, blend)                         BlendReflect(blend, base)                                                                                                                                                                                                                                                                                                  "\r
+               "#define BlendPhoenix(base, blend)                      (min(base, blend) - max(base, blend) + vec3(1.0))                                                                                                                                                                                                                                                  "\r
+               "#define BlendOpacity(base, blend, F, O)        (F(base, blend) * O + blend * (1.0 - O))                                                                                                                                                                                                                                                           "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "// Hue Blend mode creates the result color by combining the luminance and saturation of the base color with the hue of the blend color.                                                                                                                                                   "\r
+               "vec3 BlendHue(vec3 base, vec3 blend)                                                                                                                                                                                                                                                                                                                                                      "\r
+               "{                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "       vec3 baseHSL = RGBToHSL(base);                                                                                                                                                                                                                                                                                                                                                             "\r
+               "       return HSLToRGB(vec3(RGBToHSL(blend).r, baseHSL.g, baseHSL.b));                                                                                                                                                                                                                                                                                            "\r
+               "}                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "// Saturation Blend mode creates the result color by combining the luminance and hue of the base color with the saturation of the blend color.                                                                                                                                    "\r
+               "vec3 BlendSaturation(vec3 base, vec3 blend)                                                                                                                                                                                                                                                                                                                                       "\r
+               "{                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "       vec3 baseHSL = RGBToHSL(base);                                                                                                                                                                                                                                                                                                                                                             "\r
+               "       return HSLToRGB(vec3(baseHSL.r, RGBToHSL(blend).g, baseHSL.b));                                                                                                                                                                                                                                                                                            "\r
+               "}                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "// Color Mode keeps the brightness of the base color and applies both the hue and saturation of the blend color.                                                                                                                                                                                                  "\r
+               "vec3 BlendColor(vec3 base, vec3 blend)                                                                                                                                                                                                                                                                                                                                                    "\r
+               "{                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "       vec3 blendHSL = RGBToHSL(blend);                                                                                                                                                                                                                                                                                                                                                           "\r
+               "       return HSLToRGB(vec3(blendHSL.r, blendHSL.g, RGBToHSL(base).b));                                                                                                                                                                                                                                                                                           "\r
+               "}                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "// Luminosity Blend mode creates the result color by combining the hue and saturation of the base color with the luminance of the blend color.                                                                                                                                    "\r
+               "vec3 BlendLuminosity(vec3 base, vec3 blend)                                                                                                                                                                                                                                                                                                                                       "\r
+               "{                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "       vec3 baseHSL = RGBToHSL(base);                                                                                                                                                                                                                                                                                                                                                             "\r
+               "       return HSLToRGB(vec3(baseHSL.r, baseHSL.g, RGBToHSL(blend).b));                                                                                                                                                                                                                                                                                            "\r
+               "}                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "/*                                                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "** Gamma correction                                                                                                                                                                                                                                                                                                                                                                                       "\r
+               "** Details: http://blog.mouaif.org/2009/01/22/photoshop-gamma-correction-shader/                                                                                                                                                                                                                                                                  "\r
+               "*/                                                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "#define GammaCorrection(color, gamma)                                                          pow(color, 1.0 / gamma)                                                                                                                                                                                                                                            "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "/*                                                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "** Levels control (input (+gamma), output)                                                                                                                                                                                                                                                                                                                                                "\r
+               "** Details: http://blog.mouaif.org/2009/01/28/levels-control-shader/                                                                                                                                                                                                                                                                                      "\r
+               "*/                                                                                                                                                                                                                                                                                                                                                                                                                                "\r
+               "                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
+               "#define LevelsControlInputRange(color, minInput, maxInput)                             min(max(color - vec3(minInput), vec3(0.0)) / (vec3(maxInput) - vec3(minInput)), vec3(1.0))                                                                                                 "\r
+               "#define LevelsControlInput(color, minInput, gamma, maxInput)                           GammaCorrection(LevelsControlInputRange(color, minInput, maxInput), gamma)                                                                                                                         "\r
+               "#define LevelsControlOutputRange(color, minOutput, maxOutput)                  mix(vec3(minOutput), vec3(maxOutput), color)                                                                                                                                                                                       "\r
+               "#define LevelsControl(color, minInput, gamma, maxInput, minOutput, maxOutput)  LevelsControlOutputRange(LevelsControlInput(color, minInput, gamma, maxInput), minOutput, maxOutput)                                                       ";\r
+                                                                                                                                                                                                                                                                                                                                                                                                                                                  \r
+               return glsl;\r
+}
\ No newline at end of file
index fba4e5c281d4cb9b36b7b71b39dbd659e82274ef..d916ca101d598501b484c45f1d2c6cf4054ff8bb 100644 (file)
@@ -31,6 +31,7 @@ image_transform::image_transform()
        , mode_(video_mode::invalid)\r
        , is_key_(false)\r
        , deinterlace_(false)\r
+       , blend_mode_(image_transform::normal)\r
 {\r
        std::fill(fill_translation_.begin(), fill_translation_.end(), 0.0);\r
        std::fill(fill_scale_.begin(), fill_scale_.end(), 1.0);\r
@@ -122,6 +123,16 @@ bool image_transform::get_deinterlace() const
        return deinterlace_;\r
 }\r
 \r
+void image_transform::set_blend_mode(image_transform::blend_mode value)\r
+{\r
+       blend_mode_ = value;\r
+}\r
+\r
+image_transform::blend_mode image_transform::get_blend_mode() const\r
+{\r
+       return blend_mode_;\r
+}\r
+\r
 image_transform& image_transform::operator*=(const image_transform &other)\r
 {\r
        opacity_                                *= other.opacity_;\r
@@ -129,6 +140,7 @@ image_transform& image_transform::operator*=(const image_transform &other)
        if(other.mode_ != video_mode::invalid)\r
                mode_ = other.mode_;\r
 \r
+       blend_mode_                              = other.blend_mode_;\r
        gain_                                   *= other.gain_;\r
        deinterlace_                    |= other.deinterlace_;\r
        is_key_                                 |= other.is_key_;\r
@@ -162,6 +174,7 @@ image_transform tween(double time, const image_transform& source, const image_tr
 \r
        image_transform result; \r
        result.set_mode                         (dest.get_mode() != video_mode::invalid ? dest.get_mode() : source.get_mode());\r
+       result.set_blend_mode           (dest.get_blend_mode());\r
        result.set_is_key                       (source.get_is_key() | dest.get_is_key());\r
        result.set_deinterlace          (source.get_deinterlace() | dest.get_deinterlace());\r
        result.set_gain                         (do_tween(time, source.get_gain(), dest.get_gain(), duration, tweener));\r
index 6a48bc6e3329630c440496d7b2f8de6b12eece57..194e7b4f7c642b39bfc81ad537090419a2d15a1a 100644 (file)
@@ -32,6 +32,13 @@ struct pixel_format_desc;
 class image_transform \r
 {\r
 public:\r
+\r
+       enum blend_mode\r
+       {\r
+               normal,\r
+               screen\r
+       };\r
+\r
        image_transform();\r
 \r
        void set_opacity(double value);\r
@@ -64,6 +71,9 @@ public:
        void set_deinterlace(bool value);\r
        bool get_deinterlace() const;\r
 \r
+       void set_blend_mode(blend_mode value);\r
+       blend_mode get_blend_mode() const;\r
+\r
 private:\r
        double opacity_;\r
        double gain_;\r
@@ -74,6 +84,7 @@ private:
        video_mode::type mode_;\r
        bool is_key_;\r
        bool deinterlace_;\r
+       blend_mode blend_mode_;\r
 };\r
 \r
 image_transform tween(double time, const image_transform& source, const image_transform& dest, double duration, const tweener_t& tweener);\r
index 72be70888887aae9bf7e8abafdc4d5d448134aa5..5b249b303fe1f3f79a8b547ba464b19f6cd52ec2 100644 (file)
@@ -328,6 +328,26 @@ bool MixerCommand::DoExecute()
                                        }\r
                                }\r
                        }\r
+                       else if(_parameters[1] == L"BLEND")\r
+                       {\r
+                               auto blend_str = _parameters.at(2);\r
+                               auto transform = [=](image_transform transform) -> image_transform\r
+                               {\r
+                                       if(blend_str == L"NORMAL")\r
+                                               transform.set_blend_mode(image_transform::normal);\r
+                                       else if(blend_str == L"SCREEN")\r
+                                               transform.set_blend_mode(image_transform::screen);\r
+                               \r
+                                       return transform;\r
+                               };\r
+                               \r
+                               int layer = GetLayerIndex(std::numeric_limits<int>::min());\r
+                               if(layer != std::numeric_limits<int>::min())\r
+                                       GetChannel()->mixer()->apply_image_transform(GetLayerIndex(), transform, 0);\r
+                               else\r
+                                       GetChannel()->mixer()->apply_image_transform(transform, 0);                             \r
+\r
+                       }\r
                        else if(_parameters[1] == L"RESET")\r
                        {\r
                                int duration = _parameters.size() > 2 ? lexical_cast_or_default(_parameters[2], 0) : 0;\r