1 #ifndef __DALI_TOOLKIT_SHADER_EFFECT_SQUARE_H__
2 #define __DALI_TOOLKIT_SHADER_EFFECT_SQUARE_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/shader-effects/shader-effect.h>
31 * @brief Creates a new SquareDissolveEffect
33 * SquareDissolveEffect is a custom shader effect to achieve square effects in Image actors
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
41 * @return A handle to a newly allocated ShaderEffect
43 inline ShaderEffect CreateSquareDissolveEffect()
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"
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"
62 " gl_FragColor = texture2D(sTexture, vTexCoord); \n"
63 " gl_FragColor *= uColor; \n"
66 Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
69 ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
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);
79 } // namespace Toolkit
83 #endif // __DALI_TOOLKIT_SHADER_EFFECT_SQUARE_H__