1 #ifndef __DALI_TOOLKIT_MIRROR_EFFECT_H__
2 #define __DALI_TOOLKIT_MIRROR_EFFECT_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 MirrorEffect
33 * MirrorEffect is a custom shader effect to achieve square effects in Image actors
35 * Animatable/Constrainable uniforms:
36 * "uDepth" - The depth of the mirror effect. Default value 0.5
37 * "uAlpha" - The alpha of the mirror effect. Default value 1.0
39 * @return A handle to a newly allocated ShaderEffect
41 inline ShaderEffect CreateMirrorEffect()
43 std::string vertexShader(
46 " mediump vec3 pos = vec3(aPosition, 0.0)*uSize; \n"
47 " pos.y = pos.y * 3.0; \n"
48 " mediump vec4 world = uModelView * vec4(pos,1.0); \n"
49 " gl_Position = uProjection * world; \n"
50 " vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5) ); \n"
53 std::string fragmentShader(
54 "uniform mediump float uDepth; \n"
55 "uniform mediump float uAlpha; \n"
58 " if(vTexCoord.y < 1.0 / 3.0) \n"
60 " gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n"
62 " else if(vTexCoord.y < 2.0 / 3.0) \n"
64 " gl_FragColor = texture2D(sTexture, vec2(vTexCoord.x, vTexCoord.y * 3.0 - 1.0)) * uColor; \n"
65 " gl_FragColor.a *= uAlpha; \n"
69 " highp float darkness = 3.0 - vTexCoord.y * 3.0; \n"
70 " darkness = (1.0 - 1.0 / uDepth + darkness * 1.0/ uDepth) * 0.65; \n"
71 " highp vec4 color = texture2D(sTexture, vec2(vTexCoord.x, -vTexCoord.y *3.0 + 3.0)) * uColor; \n"
72 " color.a *= uAlpha; \n"
73 " gl_FragColor = color * vec4(darkness, darkness, darkness, darkness); \n"
77 Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
80 ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ));
82 shaderEffect.SetUniform("uAlpha", 1.0f);
83 shaderEffect.SetUniform("uDepth", 0.5f);
89 } // namespace Toolkit
93 #endif // __DALI_TOOLKIT_MIRROR_EFFECT_H__