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