2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUiEffects_RendererEffectShader.cpp
20 * @brief This is the file with effects library shaders sources
24 #include <FUiEffects_RendererEffectShader.h>
26 #include <FBaseSysLog.h>
30 namespace Tizen { namespace Ui { namespace Effects { namespace _Renderer
33 const char* const EFFECT_VERTEX_SHADER_STR =
34 "#define SHADER_NAME EffectVertexShader \n"
35 "attribute vec3 "SHADER_IN_POSITION_STR";\n"
36 "attribute vec3 "SHADER_IN_NORMAL_STR";\n"
37 "attribute vec2 "SHADER_IN_TEXCOORDS_STR";\n"
39 "uniform highp mat4 WorldViewProjection;\n"
40 "uniform highp mat4 ModelMtr; \n"
41 "uniform mediump mat4 NormalMtr; \n"
43 "varying highp vec3 Position; \n"
44 "varying mediump vec3 Normal; \n"
45 "varying mediump vec2 TexCoords;\n"
49 " highp vec4 WorldPos = ModelMtr * vec4(in_Position, 1.0); \n"
50 " gl_Position = WorldViewProjection * WorldPos;\n"
51 " Position = WorldPos.xyz; \n"
52 " Normal = (NormalMtr * vec4(in_Normal, 0.0)).xyz; \n"
53 " TexCoords = in_TexCoords;\n"
56 const char* const EFFECT_FRAGMENT_SHADER_STR =
57 "#define SHADER_NAME EffectFragmentShader \n"
58 "//precision highp float;\n"
59 "//precision highp vec3;\n"
60 "//precision highp vec4;\n"
61 "varying highp vec3 Position; \n"
62 "varying mediump vec3 Normal;\n"
63 "varying mediump vec2 TexCoords;\n"
65 "uniform mediump sampler2D "MAIN_TEX_STR";\n"
67 "struct LightingParameters \n"
69 " mediump vec3 ambientColorI; \n"
70 " mediump float attenuationR2; \n"
73 "struct PointLight \n"
75 " highp vec3 position; \n"
76 " mediump vec3 colorI; \n"
77 " mediump float Rk; \n"
82 " highp vec3 position; \n"
83 " mediump vec3 direction; \n"
84 " mediump float k1; \n"
85 " mediump float k2; \n"
86 " mediump vec3 colorI; \n"
87 " mediump float Rk; \n"
90 "struct DirectionalLight \n"
92 " mediump vec3 direction; \n"
93 " mediump vec3 colorI; \n"
96 "uniform LightingParameters lightingParameters; \n"
99 DIRECTIOALLIGHT_DEFPOS_STR
100 "uniform lowp float opacity; \n"
104 " mediump vec3 normal = normalize(Normal); \n"
105 " mediump vec3 color = lightingParameters.ambientColorI; \n"
106 " highp vec3 lightdir; \n"
107 " mediump float att; \n"
109 POINTLIGHT_SRCPOS_STR
113 DIRECTIOALLIGHT_SRCPOS_STR
115 " gl_FragColor.rgb = texture2D(TEX_MAIN, TexCoords).bgr * color; \n"
116 " gl_FragColor.a = opacity; \n"
119 const char* const EFFECT_DUMMY_FRAGMENT_SHADER_STR = "void main() { gl_FragColor = vec4(0.5, 0.9, 0.2, 1.0); }";
121 const char* const BLUR_VS =
122 "#define SHADER_NAME BlurVS \n"
123 "attribute vec3 "SHADER_IN_POSITION_STR";\n"
124 "attribute vec2 "SHADER_IN_TEXCOORDS_STR";\n"
126 "varying mediump vec2 TexCoords;\n"
130 " gl_Position = vec4(in_Position, 1.0);\n"
131 " TexCoords = in_TexCoords;\n"
134 const char* const BLUR_HORIZ_FS =
135 "#define SHADER_NAME BlurHorizFS_2 \n"
136 "varying mediump vec2 TexCoords;\n"
138 "uniform mediump sampler2D "MAIN_TEX_STR";\n"
139 "uniform mediump float weights[48]; \n"
140 "uniform mediump float stepx; \n"
141 "uniform mediump float stepy; \n"
142 "uniform mediump float size; \n"
143 "//mediump float weights2[5]; \n"
147 " /////if(int(size) == 4) gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); else gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); \n"
148 " // weights2[0] = 0.3990503; weights2[1] = 0.24203622; weights2[2] = 0.054005586; weights2[3] = 0.0044330484; \n"
149 " mediump vec4 result = vec4(0.0); \n"
150 " mediump vec2 coords1 = TexCoords; \n"
151 " mediump vec2 coords2 = TexCoords; \n"
152 " mediump int sizei = int(size); \n"
153 " mediump vec4 ppp; \n"
155 " for(mediump int i = 1; i < 201; i++){ if(i >= 2) break; ppp = vec4(vec3(weights[i]), 1.0); result = ppp; } \n"
157 " gl_FragColor = result; \n"
160 const char* const BLUR_VERT_FS =
161 "#define SHADER_NAME BlurVertFS_TEST \n"
162 "varying lowp vec2 TexCoords;\n"
163 "void main() { mediump vec4 p = vec4(0.0); gl_FragColor = p; }";
166 void replace(std::string &str, const std::string what, const std::string with)
173 string::size_type start_pos = str.find(what);
175 while (start_pos != string::npos)
177 str.replace(start_pos, what.length(), with);
178 start_pos += with.length();
179 start_pos = str.find(what, start_pos);
185 void printstring(const std::string name, const std::string &str)
187 std::string delim = "\n";
189 string::size_type pos = 0;
190 string::size_type pos2, dlen = delim.length(), slen = str.length();
194 while (pos < slen && i < 10000)
196 sprintf(buffer, "%d", i);
198 pos2 = str.find(delim, pos);
200 string sss = name + buffer + ". " + string(str, pos, pos2);
202 SysLog(0, "%s", sss.length() == 0? "<empty>" : sss.c_str());
204 if (pos2 == string::npos)
216 }}}} //Tizen::Ui::Effects::_Renderer