]> git.sesse.net Git - casparcg/blobdiff - core/mixer/image/shader/blending_glsl.h
straighten alpha before applying contrast-saturation-brightness when contrast is...
[casparcg] / core / mixer / image / shader / blending_glsl.h
index bba4e44a29e8450d24ab68ab51b4e840c1757cd8..18aeffa7358b14beb9ad3305e5160b5bd0eee2de 100644 (file)
@@ -30,19 +30,27 @@ static std::string get_adjustement_glsl()
                "\n     ** http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=21057                                                                                                                                                                                                                                                                                                 "\r
                "\n     */                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
                "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
-               "\n     vec3 ContrastSaturationBrightness(vec3 color, float brt, float sat, float con)                                                                                                                                                                                                                                                                     "\r
+               "\n     vec3 ContrastSaturationBrightness(vec4 color, float brt, float sat, float con)                                                                                                                                                                                                                                                                     "\r
                "\n     {                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
                "\n             const float AvgLumR = 0.5;                                                                                                                                                                                                                                                                                                                                                                         "\r
                "\n             const float AvgLumG = 0.5;                                                                                                                                                                                                                                                                                                                                                                         "\r
                "\n             const float AvgLumB = 0.5;                                                                                                                                                                                                                                                                                                                                                                         "\r
                "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
                "\n             const vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721);                                                                                                                                                                                                                                                                                                                        "\r
+               "\n             bool demultiply_remultiply = con < 1.0;                                                                                                                                                                                                                                                                                                                                                                                                            "\r
+               "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
+               "\n             if (demultiply_remultiply && color.a > 0.0)                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
+               "\n                     color.rgb /= color.a;                                                                                                                                                                                                                                                                                                                                                                                                              "\r
                "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
                "\n             vec3 AvgLumin = vec3(AvgLumR, AvgLumG, AvgLumB);                                                                                                                                                                                                                                                                                                                           "\r
-               "\n             vec3 brtColor = color * brt;                                                                                                                                                                                                                                                                                                                                                               "\r
+               "\n             vec3 brtColor = color.rgb * brt;                                                                                                                                                                                                                                                                                                                                                                   "\r
                "\n             vec3 intensity = vec3(dot(brtColor, LumCoeff));                                                                                                                                                                                                                                                                                                                            "\r
                "\n             vec3 satColor = mix(intensity, brtColor, sat);                                                                                                                                                                                                                                                                                                                             "\r
                "\n             vec3 conColor = mix(AvgLumin, satColor, con);                                                                                                                                                                                                                                                                                                                              "\r
+               "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
+               "\n             if (demultiply_remultiply)                                                                                                                                                                                                                                                                                                                                 "\r
+               "\n                     conColor.rgb *= color.a;                                                                                                                                                                                                                                                                                                                                                                                                           "\r
+               "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
                "\n             return conColor;                                                                                                                                                                                                                                                                                                                                                                                           "\r
                "\n     }                                                                                                                                                                                                                                                                                                                                                                                                                                       "\r
                "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r