Merge "Fix for font validation." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / shader-effects / square-dissolve-effect.h
1 #ifndef __DALI_TOOLKIT_SHADER_EFFECT_SQUARE_H__
2 #define __DALI_TOOLKIT_SHADER_EFFECT_SQUARE_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/shader-effects/shader-effect.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 /**
31  * @brief Creates a new SquareDissolveEffect
32  *
33  * SquareDissolveEffect is a custom shader effect to achieve square effects in Image actors
34  *
35  * Animatable/Constrainable uniforms:
36  *  "uStep"       - The step of the square effect
37  *  "uRows"       - The rows of the square dissolve effect
38  *  "uColumns"    - The columns of the square dissolve effect
39  *  "uTextureSize"- The texture size of the square dissolve
40  *
41  * @return A handle to a newly allocated ShaderEffect
42  */
43 inline ShaderEffect CreateSquareDissolveEffect()
44 {
45   // variable "uStep" range scope : [0.0, 1.0]
46   std::string fragmentShader(
47       "uniform  mediump vec2   uTextureSize;\n"
48       "uniform  mediump float  uStep;\n"
49       "uniform  mediump float  uRows;\n"
50       "uniform  mediump float  uColumns;\n"
51       "void main()\n"
52       "{\n"
53       "  mediump vec2 mosaicSize = vec2(1.0 / uRows, 1.0 / uColumns);                               \n"
54       "  mediump vec2 intXY = vec2(vTexCoord.x * uTextureSize.x, vTexCoord.y * uTextureSize.y);               \n"
55       "  mediump vec2 XYMosaic = vec2(floor(intXY.x / mosaicSize.x) * mosaicSize.x, floor(intXY.y / mosaicSize.y) * mosaicSize.y); \n"
56       "  mediump vec2 UVMosaic = vec2(XYMosaic.x /uTextureSize.x, XYMosaic.y / uTextureSize.y);               \n"
57       "  mediump vec4 noiseVec = texture2D(sEffect, UVMosaic);                                      \n"
58       "  mediump float intensity = (noiseVec[0] + noiseVec[1] + noiseVec[2] + noiseVec[3]) / 4.0;   \n"
59       "  if(intensity < uStep)                                                              \n"
60       "    gl_FragColor = vec4(0.1, 0.1, 0.1, 1.0);                                         \n"
61       "  else                                                                               \n"
62       "    gl_FragColor = texture2D(sTexture, vTexCoord);                                   \n"
63       "  gl_FragColor *= uColor;                                                            \n"
64       "}                                                                                    \n" );
65
66   Dali::ShaderEffect shaderEffect =  Dali::ShaderEffect::New(
67       "",
68       fragmentShader,
69       ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
70
71   shaderEffect.SetUniform( "uTextureSize", Vector2(1.0f, 1.0f) );//COORDINATE_TYPE_DEFAULT
72   shaderEffect.SetUniform( "uStep", 0.1f);
73   shaderEffect.SetUniform( "uRows", 25.0f);
74   shaderEffect.SetUniform( "uColumns", 25.0f);
75
76   return shaderEffect;
77 }
78
79 } // namespace Toolkit
80
81 } // namespace Dali
82
83 #endif // __DALI_TOOLKIT_SHADER_EFFECT_SQUARE_H__