1 #ifndef __DALI_TOOLKIT_SHADER_EFFECT_IRIS_H__
2 #define __DALI_TOOLKIT_SHADER_EFFECT_IRIS_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 IrisEffect
33 * IrisEffect is a custom shader effect to achieve iris effects in Image actors
35 * Animatable/Constrainable uniforms:
37 * "uRadius" - The radius of the iris effect in texture coordinate distance,
38 * i.e. 0.0 (no circle) to 1.0 (complete circle), to > 1.0 (extending outside of texture).
39 * @note For Atlas Textures results may be unpredictable.
41 * "uBlendFactor" - The blend factor of the iris effect. The lower the value, the larger the blending portion
42 * (between Opaque & Transparent). Blending will account for 1 / blendFactor of the radius
45 * "uCenter" - The center point of the iris (in texture coordinates)
47 * @return A handle to a newly allocated ShaderEffect
49 inline ShaderEffect CreateIrisEffect()
51 // append the default version
52 std::string vertexShader(
53 "uniform mediump vec2 uCenter;\n"
54 "varying mediump vec2 vRelativePosition;\n"
58 " mediump vec4 world = uModelView * vec4(aPosition, 1.0);\n"
59 " gl_Position = uProjection * world;\n"
61 " vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord );\n"
62 " vRelativePosition = vTexCoord - uCenter;\n"
65 std::string fragmentShader(
66 "uniform mediump float uRadius; \n"
67 "uniform mediump float uBlendFactor; \n"
68 "varying mediump vec2 vRelativePosition; \n"
71 " mediump float delta = (length(vRelativePosition) - uRadius); \n"
72 " delta = clamp(0.0 - delta * uBlendFactor, 0.0, 1.0); \n"
73 " gl_FragColor = texture2D(sTexture, vTexCoord) * uColor; \n"
74 " gl_FragColor.a *= delta; \n"
78 Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
81 ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ));
83 shaderEffect.SetUniform( "uRadius", 0.0f );
84 shaderEffect.SetUniform( "uBlendFactor", 100.0f );
85 shaderEffect.SetUniform( "uCenter", Vector2(0.5f, 0.5f) );