Back to index

nux  3.0.0
RenderingPipeTextureBlendShaderSource.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010-2012 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *              Robert Carr <racarr@canonical.com>
00020  */
00021 
00022 #ifndef RENDERING_PIPE_TEXTURE_BLEND_SHADER_SOURCE_H
00023 #define RENDERING_PIPE_TEXTURE_BLEND_SHADER_SOURCE_H
00024 
00025 namespace nux
00026 {
00027 static const char* const BlendNormalShader = "                                          \n\
00028 vec3 BlendNormal(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                    \n\
00029 {                                                                                             \n\
00030   return L;                                                                                   \n\
00031 }";
00032 
00033 static const char* const BlendLightenShader = "                                         \n\
00034 vec3 BlendLighten(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                   \n\
00035 {                                                                                             \n\
00036   // This mode is commutative                                                                 \n\
00037   vec3 V = max(L, B);                                                                         \n\
00038   return V;                                                                                   \n\
00039 }";
00040 
00041 static const char* const BlendDarkenShader = "                                          \n\
00042 vec3 BlendDarken(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                    \n\
00043 {                                                                                             \n\
00044   vec3 V = min(L, B);                                                                         \n\
00045   return V;                                                                                   \n\
00046 }";
00047 
00048 static const char* const BlendMultiplyShader = "                                        \n\
00049 vec3 BlendMultiply(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                  \n\
00050 {                                                                                             \n\
00051   return(B * L);                                                                              \n\
00052 }";
00053 
00054 static const char* const BlendAverageShader = "                                         \n\
00055 vec3 BlendAverage(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                   \n\
00056 {                                                                                             \n\
00057   // This mode is commutative                                                                 \n\
00058   return((B + L) / 2.0);                                                                      \n\
00059 }";
00060 
00061   // *** Additive Modes ***
00062 static const char* const BlendAddShader = "                                             \n\
00063 vec3 BlendAdd(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                       \n\
00064 {                                                                                             \n\
00065   return min(B + L, vec3(1.0));                                                               \n\
00066 }";
00067 
00068 static const char* const BlendSubstractShader = "                                       \n\
00069 vec3 BlendSubstract(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                 \n\
00070 {                                                                                             \n\
00071   return max(B + L - vec3(1.0), vec3(0.0));                                                   \n\
00072 }";
00073 
00074 // *** Difference Modes ***
00075 static const char* const BlendDifferenceShader = "                                      \n\
00076 vec3 BlendDifference(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                \n\
00077 {                                                                                             \n\
00078   return abs(B - L);                                                                          \n\
00079 }";
00080 
00081 static const char* const BlendNegationShader = "                                        \n\
00082 vec3 BlendNegation(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                  \n\
00083 {                                                                                             \n\
00084   return(vec3(1.0) - abs(vec3(1.0) - B - L));                                                 \n\
00085 }";
00086 
00087 static const char* const BlendExclusionShader = "                                       \n\
00088 vec3 BlendExclusion(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                 \n\
00089 {                                                                                             \n\
00090   return(B + L - 2.0 * B * L);                                                                \n\
00091 }";
00092 
00093 static const char* const BlendScreenShader = "                                          \n\
00094 vec3 BlendScreen(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                    \n\
00095 {                                                                                             \n\
00096   return(1.0 - (1.0 - B) * (1.0 - L));                                                        \n\
00097 }";
00098 
00099 static const char* const BlendOverlayShader = "                                         \n\
00100 float _BlendOverlay(float B /*background layer*/, float L /*foreground layer*/)               \n\
00101 {                                                                                             \n\
00102   if (L < 0.5)                                                                                \n\
00103     return(2.0 * B * L);                                                                      \n\
00104   else                                                                                        \n\
00105     return(1.0 - 2.0 * (1.0 - B) * (1.0 - L));                                                \n\
00106 }                                                                                             \n\
00107 vec3 BlendOverlay(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                   \n\
00108 {                                                                                             \n\
00109   return vec3(_BlendOverlay(B.r,L.r), _BlendOverlay(B.g ,L.g), _BlendOverlay(B.b,L.b));  \n\
00110 }";
00111 
00112 static const char* const BlendSoftLightShader = "                                             \n\
00113 float _BlendSoftLight(float B /*background layer*/, float L /*foreground layer*/)                   \n\
00114 {                                                                                                   \n\
00115   if (L < 0.5)                                                                                      \n\
00116     return(2.0 * B * L + B * B * (1.0 - 2.0 * L);                                                   \n\
00117   else                                                                                              \n\
00118     return sqrt(B) * (2.0 * L - 1.0) + 2.0 * B * (1.0 - L);                                         \n\
00119 }                                                                                                   \n\
00120 vec3 BlendSoftLight(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                       \n\
00121 {                                                                                                   \n\
00122   return vec3(_BlendSoftLight(B.r, L.r), _BlendSoftLight(B.g, L.g), _BlendSoftLight(B.b, L.b));  \n\
00123 }";
00124 
00125 static const char* const BlendHardLightShader = "                                             \n\
00126 float _BlendHardLight(float B /*background layer*/, float L /*foreground layer*/)                   \n\
00127 {                                                                                                   \n\
00128   if (L < 0.5)                                                                                      \n\
00129     return(2.0 * B * L);                                                                            \n\
00130   else                                                                                              \n\
00131     return(1.0 - 2.0 * (1.0 - B) * (1.0 - L));                                                      \n\
00132 }                                                                                                   \n\
00133 vec3 BlendHardLight(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                       \n\
00134 {                                                                                                   \n\
00135   return vec3(_BlendHardLight(B.r, L.r), _BlendHardLight(B.g, L.g), _BlendHardLight(B.b, L.b));  \n\
00136 }";
00137 
00138 static const char* const BlendColorDodgeShader = "                                              \n\
00139 float _BlendColorDodge(float B /*background layer*/, float L /*foreground layer*/)                    \n\
00140 {                                                                                                     \n\
00141   if (L == 1.0)                                                                                       \n\
00142     return 1.0;                                                                                       \n\
00143   else                                                                                                \n\
00144     return min(B / (1.0 - L), 1.0);                                                                   \n\
00145 }                                                                                                     \n\
00146 vec3 BlendColorDodge(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                        \n\
00147 {                                                                                                     \n\
00148   return vec3(_BlendColorDodge(B.r, L.r), _BlendColorDodge(B.g, L.g), _BlendColorDodge(B.b, L.b)); \n\
00149 }";
00150 
00151 static const char* const BlendLinearDodgeShader = "                                                 \n\
00152 float _BlendLinearDodge(float B /*background layer*/, float L /*foreground layer*/)                       \n\
00153 {                                                                                                         \n\
00154   return min(B + L, 1.0);                                                                                 \n\
00155 }                                                                                                         \n\
00156 vec3 BlendLinearDodge(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                           \n\
00157 {                                                                                                         \n\
00158   return vec3(_BlendLinearDodge(B.r, L.r), _BlendLinearDodge(B.g, L.g), _BlendLinearDodge(B.b, L.b));  \n\
00159 }";
00160 
00161 static const char* const BlendColorBurnShader = "                                                   \n\
00162 float _BlendColorBurn(float B /*background layer*/, float L /*foreground layer*/)                         \n\
00163 {                                                                                                         \n\
00164   if (L == 0.0)                                                                                           \n\
00165     return 0.0;                                                                                           \n\
00166   else                                                                                                    \n\
00167     return max(1.0 - ((1.0 - B) / L), 0.0);                                                               \n\
00168 }                                                                                                         \n\
00169 vec3 BlendColorBurn(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                             \n\
00170 {                                                                                                         \n\
00171   return vec3(_BlendColorBurn(B.r, L.r), _BlendColorBurn(B.g, L.g), _BlendColorBurn(B.b, L.b));        \n\
00172 }";
00173 
00174 static const char* const BlendLinearBurnShader = "                                                  \n\
00175 float _BlendLinearBurn(float B /*background layer*/, float L /*foreground layer*/)                        \n\
00176 {                                                                                                         \n\
00177   return max(B + L - 1.0, 0.0);                                                                           \n\
00178 }                                                                                                         \n\
00179 vec3 BlendLinearBurn(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                            \n\
00180 {                                                                                                         \n\
00181   return vec3(_BlendLinearBurn(B.r, L.r), _BlendLinearBurn(B.g, L.g), _BlendLinearBurn(B.b, L.b));     \n\
00182 }";
00183 
00184 static const char* const BlendLinearLightShader = "                                                 \n\
00185 float _BlendLinearLight(float B /*background layer*/, float L /*foreground layer*/)                       \n\
00186 {                                                                                                         \n\
00187   if (L < 0.5)                                                                                            \n\
00188     return _BlendLinearBurn(B, (2.0 * L));                                                                \n\
00189   else                                                                                                    \n\
00190     return _BlendLinearDodge(B, (2.0 * (L - 0.5)));                                                       \n\
00191 }                                                                                                         \n\
00192 vec3 BlendLinearLight(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                           \n\
00193 {                                                                                                         \n\
00194   return vec3(_BlendLinearLight(B.r, L.r), _BlendLinearLight(B.g, L.g), _BlendLinearLight(B.b, L.b));  \n\
00195 }";
00196 
00197 static const char* const BlendVividLightShader = "                                                  \n\
00198 float _BlendVividLight(float B /*background layer*/, float L /*foreground layer*/)                        \n\
00199 {                                                                                                         \n\
00200   if (L < 0.5)                                                                                            \n\
00201     return _BlendColorBurn(B, (2.0 * L));                                                                 \n\
00202   else                                                                                                    \n\
00203     return _BlendColorDodge(B, (2.0 * (L - 0.5))));                                                       \n\
00204 }                                                                                                         \n\
00205 vec3 BlendVividLight(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                            \n\
00206 {                                                                                                         \n\
00207   return vec3(_BlendVividLight(B.r, L.r), _BlendVividLight(B.g, L.g), _BlendVividLight(B.b, L.b));        \n\
00208 }";
00209 
00210 static const char* const BlendPinLightShader = "                                                    \n\
00211 float _BlendPinLight(float B /*background layer*/, float L /*foreground layer*/)                          \n\
00212 {                                                                                                         \n\
00213   if (L < 0.5)                                                                                            \n\
00214     return _BlendDarken(B, (2.0 * L));                                                                    \n\
00215   else                                                                                                    \n\
00216     return _BlendLighten(B, (2.0 * (L - 0.5))));                                                          \n\
00217 }                                                                                                         \n\
00218 vec3 BlendPinLight(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                              \n\
00219 {                                                                                                         \n\
00220   return vec3(_BlendPinLight(B.r, L.r), _BlendPinLight(B.g, L.g), _BlendPinLight(B.b, L.b));              \n\
00221 }";
00222 
00223 static const char* const BlendHardMixShader = "                                                     \n\
00224 float _BlendHardMix(float B /*background layer*/, float L /*foreground layer*/)                           \n\
00225 {                                                                                                         \n\
00226   if (_BlendVividLight(B, L) < 0.5)                                                                       \n\
00227     return 0.0;                                                                                           \n\
00228   else                                                                                                    \n\
00229     return 1.0;                                                                                           \n\
00230 }                                                                                                         \n\
00231 vec3 BlendHardMix(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                               \n\
00232 {                                                                                                         \n\
00233   return vec3(_BlendHardMix(B.r, L.r), _BlendHardMix(B.g, L.g), _BlendHardMix(B.b, L.b));                 \n\
00234 }";
00235 
00236 static const char* const BlendReflectShader = "                                                     \n\
00237 float _BlendReflect(float B /*background layer*/, float L /*foreground layer*/)                           \n\
00238 {                                                                                                         \n\
00239   if (L == 1.0)                                                                                           \n\
00240     return 1.0;                                                                                           \n\
00241   else                                                                                                    \n\
00242     return min(B * B / (1.0 - L), 1.0);                                                                   \n\
00243 }                                                                                                         \n\
00244 vec3 BlendReflect(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                               \n\
00245 {                                                                                                         \n\
00246   return vec3(_BlendReflect(B.r, L.r), _BlendReflect(B.g, L.g), _BlendReflect(B.b, L.b));                 \n\
00247 }";
00248 
00249 static const char* const BlendGlowShader = "                                                        \n\
00250 float _BlendGlow(float B /*background layer*/, float L /*foreground layer*/)                              \n\
00251 {                                                                                                         \n\
00252   if (L == 1.0)                                                                                           \n\
00253     return 1.0;                                                                                           \n\
00254   else                                                                                                    \n\
00255     return min(L * L / (1.0 - B), 1.0);                                                                   \n\
00256 }                                                                                                         \n\
00257 vec3 BlendGlow(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                                  \n\
00258 {                                                                                                         \n\
00259   return vec3(_BlendGlow(B.r, L.r), _BlendGlow(B.g, L.g), _BlendGlow(B.b, L.b));                          \n\
00260 }";
00261 
00262 static const char* const BlendPhoenixShader = "                                                     \n\
00263 vec3 BlendPhoenix(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                               \n\
00264 {                                                                                                         \n\
00265   return min(B, L) - max(B, L) + vec3(1.0);                                                               \n\
00266 }";
00267 
00268 static const char* const BlendOpacityShader = "                                                     \n\
00269 vec3 BlendOpacity(vec3 B /*background layer*/, vec3 L /*foreground layer*/)                               \n\
00270 {                                                                                                         \n\
00271   return O * L + (1 - O) * B;                                                                             \n\
00272 }";
00273 
00274 }
00275 
00276 #endif