]> git.sesse.net Git - casparcg/blob - accelerator/ogl/image/blending_glsl.h
aab2ae4faf92bb31f60f44fc98e2d9d62b5dbd74
[casparcg] / accelerator / ogl / image / blending_glsl.h
1 /*\r
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 * This file is part of CasparCG (www.casparcg.com).\r
5 *\r
6 * CasparCG is free software: you can redistribute it and/or modify\r
7 * it under the terms of the GNU General Public License as published by\r
8 * the Free Software Foundation, either version 3 of the License, or\r
9 * (at your option) any later version.\r
10 *\r
11 * CasparCG is distributed in the hope that it will be useful,\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14 * GNU General Public License for more details.\r
15 *\r
16 * You should have received a copy of the GNU General Public License\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
18 *\r
19 * Author: Robert Nagy, ronag89@gmail.com\r
20 */\r
21 \r
22 #pragma once\r
23 \r
24 static std::string get_adjustement_glsl()\r
25 {\r
26         return                                                                                                                                                                                                                                                                                                                                                                                                                                          \r
27                 "\n     /*                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
28                 "\n     ** Contrast, saturation, brightness                                                                                                                                                                                                                                                                                                                                                              "\r
29                 "\n     ** Code of this function is from TGM's shader pack                                                                                                                                                                                                                                                                                                                                 "\r
30                 "\n     ** http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=21057                                                                                                                                                                                                                                                                                                 "\r
31                 "\n     */                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
32                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
33                 "\n     vec3 ContrastSaturationBrightness(vec3 color, float brt, float sat, float con)                                                                                                                                                                                                                                                                     "\r
34                 "\n     {                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
35                 "\n             const float AvgLumR = 0.5;                                                                                                                                                                                                                                                                                                                                                                         "\r
36                 "\n             const float AvgLumG = 0.5;                                                                                                                                                                                                                                                                                                                                                                         "\r
37                 "\n             const float AvgLumB = 0.5;                                                                                                                                                                                                                                                                                                                                                                         "\r
38                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
39                 "\n             const vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721);                                                                                                                                                                                                                                                                                                                        "\r
40                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
41                 "\n             vec3 AvgLumin = vec3(AvgLumR, AvgLumG, AvgLumB);                                                                                                                                                                                                                                                                                                                           "\r
42                 "\n             vec3 brtColor = color * brt;                                                                                                                                                                                                                                                                                                                                                               "\r
43                 "\n             vec3 intensity = vec3(dot(brtColor, LumCoeff));                                                                                                                                                                                                                                                                                                                            "\r
44                 "\n             vec3 satColor = mix(intensity, brtColor, sat);                                                                                                                                                                                                                                                                                                                             "\r
45                 "\n             vec3 conColor = mix(AvgLumin, satColor, con);                                                                                                                                                                                                                                                                                                                              "\r
46                 "\n             return conColor;                                                                                                                                                                                                                                                                                                                                                                                           "\r
47                 "\n     }                                                                                                                                                                                                                                                                                                                                                                                                                                       "\r
48                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
49                 "\n     /*                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
50                 "\n     ** Gamma correction                                                                                                                                                                                                                                                                                                                                                                                                     "\r
51                 "\n     ** Details: http://blog.mouaif.org/2009/01/22/photoshop-gamma-correction-shader/                                                                                                                                                                                                                                                                   "\r
52                 "\n     */                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
53                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
54                 "\n#define GammaCorrection(color, gamma)                                                                pow(color, vec3(1.0 / gamma))                           \n                                                                                                                                                                                                      "\r
55                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
56                 "\n     /*                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
57                 "\n     ** Levels control (input (+gamma), output)                                                                                                                                                                                                                                                                                                                                                 "\r
58                 "\n     ** Details: http://blog.mouaif.org/2009/01/28/levels-control-shader/                                                                                                                                                                                                                                                                                       "\r
59                 "\n     */                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
60                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
61                 "\n#define LevelsControlInputRange(color, minInput, maxInput)                           min(max(color - vec3(minInput), vec3(0.0)) / (vec3(maxInput) - vec3(minInput)), vec3(1.0))              \n                                                                                 "\r
62                 "\n#define LevelsControlInput(color, minInput, gamma, maxInput)                         GammaCorrection(LevelsControlInputRange(color, minInput, maxInput), gamma)                                      \n                                                                                              "       \r
63                 "\n#define LevelsControlOutputRange(color, minOutput, maxOutput)                        mix(vec3(minOutput), vec3(maxOutput), color)                                                                                                                    \n                                                                 "\r
64                 "\n#define LevelsControl(color, minInput, gamma, maxInput, minOutput, maxOutput)        LevelsControlOutputRange(LevelsControlInput(color, minInput, gamma, maxInput), minOutput, maxOutput)    \n                                                      "\r
65                 ;\r
66 }\r
67 \r
68 static std::string get_blend_glsl()\r
69 {\r
70         static std::string glsl = \r
71                 "\n     /*                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
72                 "\n     ** Photoshop & misc math                                                                                                                                                                                                                                                                                                                                                                                   "\r
73                 "\n     ** Blending modes, RGB/HSL/Contrast/Desaturate, levels control                                                                                                                                                                                                                                                                                                     "\r
74                 "\n     **                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
75                 "\n     ** Romain Dura | Romz                                                                                                                                                                                                                                                                                                                                                                                      "\r
76                 "\n     ** Blog: http://blog.mouaif.org                                                                                                                                                                                                                                                                                                                                                            "\r
77                 "\n     ** Post: http://blog.mouaif.org/?p=94                                                                                                                                                                                                                                                                                                                                                      "\r
78                 "\n     */                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
79                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
80                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
81                 "\n     /*                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
82                 "\n     ** Desaturation                                                                                                                                                                                                                                                                                                                                                                                            "\r
83                 "\n     */                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
84                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
85                 "\n     vec4 Desaturate(vec3 color, float Desaturation)                                                                                                                                                                                                                                                                                                                            "\r
86                 "\n     {                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
87                 "\n             vec3 grayXfer = vec3(0.3, 0.59, 0.11);                                                                                                                                                                                                                                                                                                                                             "\r
88                 "\n             vec3 gray = vec3(dot(grayXfer, color));                                                                                                                                                                                                                                                                                                                                            "\r
89                 "\n             return vec4(mix(color, gray, Desaturation), 1.0);                                                                                                                                                                                                                                                                                                                          "\r
90                 "\n     }                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
91                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
92                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
93                 "\n     /*                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
94                 "\n     ** Hue, saturation, luminance                                                                                                                                                                                                                                                                                                                                                                      "\r
95                 "\n     */                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
96                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
97                 "\n     vec3 RGBToHSL(vec3 color)                                                                                                                                                                                                                                                                                                                                                                                  "\r
98                 "\n     {                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
99                 "\n             vec3 hsl;                                                                                                                                                                                                                                                          "\r
100                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
101                 "\n             float fmin = min(min(color.r, color.g), color.b);                                                                                                                                                                                                                                                                  "\r
102                 "\n             float fmax = max(max(color.r, color.g), color.b);                                                                                                                                                                                                                                                                  "\r
103                 "\n             float delta = fmax - fmin;                                                                                                                                                                                                                                                                                                 "\r
104                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
105                 "\n             hsl.z = (fmax + fmin) / 2.0;                                                                                                                                                                                                                                                                                                                       "\r
106                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
107                 "\n             if (delta == 0.0)                                                                                                                                                                                                                                                                                                                  "\r
108                 "\n             {                                                                                                                                                                                                                                                                                                                                                                                                                          "\r
109                 "\n                     hsl.x = 0.0;                                                                                                                                                                                                                                                                                                                                                               "\r
110                 "\n                     hsl.y = 0.0;                                                                                                                                                                                                                                                                                                                                                       "\r
111                 "\n             }                                                                                                                                                                                                                                                                                                                                                                                                                          "\r
112                 "\n             else                                                                                                                                                                                                                                                                                                                       "\r
113                 "\n             {                                                                                                                                                                                                                                                                                                                                                                                                                          "\r
114                 "\n                     if (hsl.z < 0.5)                                                                                                                                                                                                                                                                                                                                                                                   "\r
115                 "\n                             hsl.y = delta / (fmax + fmin);                                                                                                                                                                                                                                                                                             "\r
116                 "\n                     else                                                                                                                                                                                                                                                                                                                                                                                                       "\r
117                 "\n                             hsl.y = delta / (2.0 - fmax - fmin);                                                                                                                                                                                                                                                                                               "\r
118                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
119                 "\n                     float deltaR = (((fmax - color.r) / 6.0) + (delta / 2.0)) / delta;                                                                                                                                                                                                                                                                                 "\r
120                 "\n                     float deltaG = (((fmax - color.g) / 6.0) + (delta / 2.0)) / delta;                                                                                                                                                                                                                                                                                 "\r
121                 "\n                     float deltaB = (((fmax - color.b) / 6.0) + (delta / 2.0)) / delta;                                                                                                                                                                                                                                                                                 "\r
122                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
123                 "\n                     if (color.r == fmax )                                                                                                                                                                                                                                                                                                                                                                      "\r
124                 "\n                             hsl.x = deltaB - deltaG;                                                                                                                                                                                                                                                                                                                                   "\r
125                 "\n                     else if (color.g == fmax)                                                                                                                                                                                                                                                                                                                                                                  "\r
126                 "\n                             hsl.x = (1.0 / 3.0) + deltaR - deltaB;                                                                                                                                                                                                                                                                                                     "\r
127                 "\n                     else if (color.b == fmax)                                                                                                                                                                                                                                                                                                                                                                  "\r
128                 "\n                             hsl.x = (2.0 / 3.0) + deltaG - deltaR;                                                                                                                                                                                                                                                                                                     "\r
129                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
130                 "\n                     if (hsl.x < 0.0)                                                                                                                                                                                                                                                                                                                                                                                   "\r
131                 "\n                             hsl.x += 1.0;                                                                                                                                                                                                                                                                                                                                                      "\r
132                 "\n                     else if (hsl.x > 1.0)                                                                                                                                                                                                                                                                                                                                                                      "\r
133                 "\n                             hsl.x -= 1.0;                                                                                                                                                                                                                                                                                                                                                      "\r
134                 "\n             }                                                                                                                                                                                                                                                                                                                                                                                                                          "\r
135                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
136                 "\n             return hsl;                                                                                                                                                                                                                                                                                                                                                                                                        "\r
137                 "\n     }                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
138                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
139                 "\n     float HueToRGB(float f1, float f2, float hue)                                                                                                                                                                                                                                                                                                                                      "\r
140                 "\n     {                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
141                 "\n             if (hue < 0.0)                                                                                                                                                                                                                                                                                                                                                                                             "\r
142                 "\n                     hue += 1.0;                                                                                                                                                                                                                                                                                                                                                                                                "\r
143                 "\n             else if (hue > 1.0)                                                                                                                                                                                                                                                                                                                                                                                        "\r
144                 "\n                     hue -= 1.0;                                                                                                                                                                                                                                                                                                                                                                                                "\r
145                 "\n             float res;                                                                                                                                                                                                                                                                                                                                                                                                         "\r
146                 "\n             if ((6.0 * hue) < 1.0)                                                                                                                                                                                                                                                                                                                                                                             "\r
147                 "\n                     res = f1 + (f2 - f1) * 6.0 * hue;                                                                                                                                                                                                                                                                                                                                                  "\r
148                 "\n             else if ((2.0 * hue) < 1.0)                                                                                                                                                                                                                                                                                                                                                                        "\r
149                 "\n                     res = f2;                                                                                                                                                                                                                                                                                                                                                                                                  "\r
150                 "\n             else if ((3.0 * hue) < 2.0)                                                                                                                                                                                                                                                                                                                                                                        "\r
151                 "\n                     res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0;                                                                                                                                                                                                                                                                                                                  "\r
152                 "\n             else                                                                                                                                                                                                                                                                                                                                                                                                               "\r
153                 "\n                     res = f1;                                                                                                                                                                                                                                                                                                                                                                                                  "\r
154                 "\n             return res;                                                                                                                                                                                                                                                                                                                                                                                                        "\r
155                 "\n     }                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
156                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
157                 "\n     vec3 HSLToRGB(vec3 hsl)                                                                                                                                                                                                                                                                                                                                                                            "\r
158                 "\n     {                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
159                 "\n             vec3 rgb;                                                                                                                                                                                                                                                                                                                                                                                                          "\r
160                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
161                 "\n             if (hsl.y == 0.0)                                                                                                                                                                                                                                                                                                                                                                                          "\r
162                 "\n                     rgb = vec3(hsl.z);                                                                                                                                                                                                                                                                                                                                         "\r
163                 "\n             else                                                                                                                                                                                                                                                                                                                                                                                                               "\r
164                 "\n             {                                                                                                                                                                                                                                                                                                                                                                                                                          "\r
165                 "\n                     float f2;                                                                                                                                                                                                                                                                                                                                                                                                  "\r
166                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
167                 "\n                     if (hsl.z < 0.5)                                                                                                                                                                                                                                                                                                                                                                                   "\r
168                 "\n                             f2 = hsl.z * (1.0 + hsl.y);                                                                                                                                                                                                                                                                                                                                                        "\r
169                 "\n                     else                                                                                                                                                                                                                                                                                                                                                                                                       "\r
170                 "\n                             f2 = (hsl.z + hsl.y) - (hsl.y * hsl.z);                                                                                                                                                                                                                                                                                                                            "\r
171                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
172                 "\n                     float f1 = 2.0 * hsl.z - f2;                                                                                                                                                                                                                                                                                                                                                       "\r
173                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
174                 "\n                     rgb.r = HueToRGB(f1, f2, hsl.x + (1.0/3.0));                                                                                                                                                                                                                                                                                                                       "\r
175                 "\n                     rgb.g = HueToRGB(f1, f2, hsl.x);                                                                                                                                                                                                                                                                                                                                                   "\r
176                 "\n                     rgb.b= HueToRGB(f1, f2, hsl.x - (1.0/3.0));                                                                                                                                                                                                                                                                                                                                "\r
177                 "\n             }                                                                                                                                                                                                                                                                                                                                                                                                                          "\r
178                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
179                 "\n             return rgb;                                                                                                                                                                                                                                                                                                                                                                                                        "\r
180                 "\n     }                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
181                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
182                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                                "\r
183                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
184                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
185                 "\n     /*                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
186                 "\n     ** Float blending modes                                                                                                                                                                                                                                                                                                                                                                            "\r
187                 "\n     ** Adapted from here: http://www.nathanm.com/photoshop-blending-math/                                                                                                                                                                                                                                                                                      "\r
188                 "\n     ** But I modified the HardMix (wrong condition), Overlay, SoftLight, ColorDodge, ColorBurn, VividLight, PinLight (inverted layers) ones to have correct results                                                                                            "\r
189                 "\n     */                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
190                 "\n                                                                                                                                                                                                                                                                                                                                                                                             \n                                         "\r
191                 "\n#define BlendLinearDodgef                                    BlendAddf                                                                                                                                                                                                                                                                               \n                                                 "\r
192                 "\n#define BlendLinearBurnf                                     BlendSubstractf                                                                                                                                                                                                                                                                 \n                                                 "\r
193                 "\n#define BlendAddf(base, blend)                               min(base + blend, 1.0)                                                                                                                                                                                                                                                  \n                                         "\r
194                 "\n#define BlendSubstractf(base, blend)                 max(base + blend - 1.0, 0.0)                                                                                                                                                                                                                                    \n                                                 "\r
195                 "\n#define BlendLightenf(base, blend)           max(blend, base)                                                                                                                                                                                                                                                                        \n                                 "\r
196                 "\n#define BlendDarkenf(base, blend)                    min(blend, base)                                                                                                                                                                                                                                                                \n                                                 "\r
197                 "\n#define BlendLinearLightf(base, blend)       (blend < 0.5 ? BlendLinearBurnf(base, (2.0 * blend)) : BlendLinearDodgef(base, (2.0 * (blend - 0.5))))                                                                                          \n                                 "\r
198                 "\n#define BlendScreenf(base, blend)                    (1.0 - ((1.0 - base) * (1.0 - blend)))                                                                                                                                                                                                                  \n                                                 "\r
199                 "\n#define BlendOverlayf(base, blend)           (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)))                                                                                                                                        \n                                         "\r
200                 "\n#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)))    \n                                                 "\r
201                 "\n#define BlendColorDodgef(base, blend)                ((blend == 1.0) ? blend : min(base / (1.0 - blend), 1.0))                                                                                                                                                                               \n                                                 "\r
202                 "\n#define BlendColorBurnf(base, blend)                 ((blend == 0.0) ? blend : max((1.0 - ((1.0 - base) / blend)), 0.0))                                                                                                                                                             \n                                                 "\r
203                 "\n#define BlendVividLightf(base, blend)                ((blend < 0.5) ? BlendColorBurnf(base, (2.0 * blend)) : BlendColorDodgef(base, (2.0 * (blend - 0.5))))                                                                                  \n                                                 "\r
204                 "\n#define BlendPinLightf(base, blend)          ((blend < 0.5) ? BlendDarkenf(base, (2.0 * blend)) : BlendLightenf(base, (2.0 *(blend - 0.5))))                                                                                                         \n                                         "\r
205                 "\n#define BlendHardMixf(base, blend)           ((BlendVividLightf(base, blend) < 0.5) ? 0.0 : 1.0)                                                                                                                                                                                                     \n                                         "\r
206                 "\n#define BlendReflectf(base, blend)           ((blend == 1.0) ? blend : min(base * base / (1.0 - blend), 1.0))                                                                                                                                                                        \n                                 "\r
207                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
208                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
209                 "\n     /*                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
210                 "\n     ** Vector3 blending modes                                                                                                                                                                                                                                                                                                                                                                                  "\r
211                 "\n     */                                                                                                                                                                                                                                                                                                                                                                                                                                 "\r
212                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
213                 "\n#define Blend(base, blend, funcf)                    vec3(funcf(base.r, blend.r), funcf(base.g, blend.g), funcf(base.b, blend.b))                            \n                                                                                                                                                         "\r
214                 "\n                                                                                                                                                                                                                                                                                     \n                                                                                                                                                 "\r
215                 "\n#define BlendNormal(base, blend)                     (blend)                                                                                                                                                                         \n                                                                                                                                                         "\r
216                 "\n#define BlendLighten                                         BlendLightenf                                                                                                                                                                   \n                                                                                                                                                         "\r
217                 "\n#define BlendDarken                                          BlendDarkenf                                                                                                                                                                    \n                                                                                                                                                         "\r
218                 "\n#define BlendMultiply(base, blend)           (base * blend)                                                                                                                                                                  \n                                                                                                                                         "\r
219                 "\n#define BlendAverage(base, blend)                    ((base + blend) / 2.0)                                                                                                                                          \n                                                                                                                                                         "\r
220                 "\n#define BlendAdd(base, blend)                                min(base + blend, vec3(1.0))                                                                                                                            \n                                                                                                                                                                 "\r
221                 "\n#define BlendSubstract(base, blend)          max(base + blend - vec3(1.0), vec3(0.0))                                                                                                                \n                                                                                                                                                 "\r
222                 "\n#define BlendDifference(base, blend)                 abs(base - blend)                                                                                                                                                       \n                                                                                                                                                         "\r
223                 "\n#define BlendNegation(base, blend)           (vec3(1.0) - abs(vec3(1.0) - base - blend))                                                                                                             \n                                                                                                                                                 "\r
224                 "\n#define BlendExclusion(base, blend)          (base + blend - 2.0 * base * blend)                                                                                                                             \n                                                                                                                                                 "\r
225                 "\n#define BlendScreen(base, blend)                     Blend(base, blend, BlendScreenf)                                                                                                                        \n                                                                                                                                                         "\r
226                 "\n#define BlendOverlay(base, blend)                    Blend(base, blend, BlendOverlayf)                                                                                                                       \n                                                                                                                                                         "\r
227                 "\n#define BlendSoftLight(base, blend)          Blend(base, blend, BlendSoftLightf)                                                                                                                             \n                                                                                                                                                 "\r
228                 "\n#define BlendHardLight(base, blend)          BlendOverlay(blend, base)                                                                                                                                               \n                                                                                                                                                 "\r
229                 "\n#define BlendColorDodge(base, blend)                 Blend(base, blend, BlendColorDodgef)                                                                                                            \n                                                                                                                                                         "\r
230                 "\n#define BlendColorBurn(base, blend)          Blend(base, blend, BlendColorBurnf)                                                                                                                             \n                                                                                                                                                 "\r
231                 "\n#define BlendLinearDodge                                     BlendAdd                                                                                                                                                                                \n                                                                                                                                                         "\r
232                 "\n#define BlendLinearBurn                                      BlendSubstract                                                                                                                                                                  \n                                                                                                                                                         "\r
233                 "\n#define BlendLinearLight(base, blend)                Blend(base, blend, BlendLinearLightf)                                                                                                           \n                                                                                                                                                         "\r
234                 "\n#define BlendVividLight(base, blend)                 Blend(base, blend, BlendVividLightf)                                                                                                            \n                                                                                                                                                         "\r
235                 "\n#define BlendPinLight(base, blend)           Blend(base, blend, BlendPinLightf)                                                                                                                              \n                                                                                                                                         "\r
236                 "\n#define BlendHardMix(base, blend)                    Blend(base, blend, BlendHardMixf)                                                                                                                       \n                                                                                                                                                         "\r
237                 "\n#define BlendReflect(base, blend)                    Blend(base, blend, BlendReflectf)                                                                                                                       \n                                                                                                                                                         "\r
238                 "\n#define BlendGlow(base, blend)                       BlendReflect(blend, base)                                                                                                                                               \n                                                                                                                                                 "\r
239                 "\n#define BlendPhoenix(base, blend)                    (min(base, blend) - max(base, blend) + vec3(1.0))                                                                                       \n                                                                                                                                                         "\r
240                 "\n#define BlendOpacity(base, blend, F, O)      (F(base, blend) * O + blend * (1.0 - O))                                                                                                                \n                                                                                                                                                         "\r
241                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
242                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
243                 "\n     vec3 BlendHue(vec3 base, vec3 blend)                                                                                                                                                                                                                                                                                                                                                       "\r
244                 "\n     {                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
245                 "\n             vec3 baseHSL = RGBToHSL(base);                                                                                                                                                                                                                                                                                                                                                             "\r
246                 "\n             return HSLToRGB(vec3(RGBToHSL(blend).r, baseHSL.g, baseHSL.b));                                                                                                                                                                                                                                                                                            "\r
247                 "\n     }                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
248                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
249                 "\n     vec3 BlendSaturation(vec3 base, vec3 blend)                                                                                                                                                                                                                                                                                                                                        "\r
250                 "\n     {                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
251                 "\n             vec3 baseHSL = RGBToHSL(base);                                                                                                                                                                                                                                                                                                                                                             "\r
252                 "\n             return HSLToRGB(vec3(baseHSL.r, RGBToHSL(blend).g, baseHSL.b));                                                                                                                                                                                                                                                                                            "\r
253                 "\n     }                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
254                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
255                 "\n     vec3 BlendColor(vec3 base, vec3 blend)                                                                                                                                                                                                                                                                                                                                                     "\r
256                 "\n     {                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
257                 "\n             vec3 blendHSL = RGBToHSL(blend);                                                                                                                                                                                                                                                                                                                                                           "\r
258                 "\n             return HSLToRGB(vec3(blendHSL.r, blendHSL.g, RGBToHSL(base).b));                                                                                                                                                                                                                                                                                           "\r
259                 "\n     }                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
260                 "\n                                                                                                                                                                                                                                                                                                                                                                                                                                        "\r
261                 "\n     vec3 BlendLuminosity(vec3 base, vec3 blend)                                                                                                                                                                                                                                                                                                                                        "\r
262                 "\n     {                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
263                 "\n             vec3 baseHSL = RGBToHSL(base);                                                                                                                                                                                                                                                                                                                                                             "\r
264                 "\n             return HSLToRGB(vec3(baseHSL.r, baseHSL.g, RGBToHSL(blend).b));                                                                                                                                                                                                                                                                                            "\r
265                 "\n     }                                                                                                                                                                                                                                                                                                                                                                                                                                  "\r
266                 "\n                                                                                                                                                                                                                                                                                                                                                                                                        "\r
267                 ;\r
268                                                                                                                                                                                                                                                                                                                                                                                                                                                    \r
269                 return glsl;\r
270 }