2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 #include <dali-toolkit/public-api/shader-effects/iris-effect.h>
26 const std::string RADIUS_PROPERTY_NAME( "uRadius" );
27 const std::string CENTER_PROPERTY_NAME( "uCenter" );
28 const std::string BLEND_FACTOR_PROPERTY_NAME( "uBlendFactor" );
31 IrisEffect::IrisEffect()
35 //Call the Parent copy constructor to add reference to the implementation for this object
36 IrisEffect::IrisEffect(ShaderEffect handle)
41 IrisEffect::~IrisEffect()
45 IrisEffect IrisEffect::New()
47 // append the default version
48 std::string vertexShader(
49 "uniform mediump vec2 uCenter;\n"
50 "varying vec2 vRelativePosition;\n"
54 " vec4 world = uModelView * vec4(aPosition,1.0);\n"
55 " gl_Position = uProjection * world;\n"
57 " vTexCoord = aTexCoord;\n"
58 " vRelativePosition = aTexCoord - uCenter;\n"
61 std::string fragmentShader(
62 "uniform float uRadius; \n"
63 "uniform float uBlendFactor; \n"
64 "varying vec2 vRelativePosition; \n"
67 " float delta = (length(vRelativePosition) - uRadius); \n"
68 " delta = clamp(0.0 - delta * uBlendFactor, 0.0, 1.0); \n"
69 " gl_FragColor = texture2D(sTexture, vTexCoord) * uColor; \n"
70 " gl_FragColor.a *= delta; \n"
74 Dali::ShaderEffect shaderEffectCustom = Dali::ShaderEffect::New(
77 GeometryType( GEOMETRY_TYPE_IMAGE ),
78 ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ));
80 Dali::Toolkit::IrisEffect handle( shaderEffectCustom );
81 handle.SetUniform( RADIUS_PROPERTY_NAME, 0.0f );
82 handle.SetUniform( BLEND_FACTOR_PROPERTY_NAME, 100.0f );
83 handle.SetUniform( CENTER_PROPERTY_NAME, Vector2(0.5f, 0.5f) );
87 void IrisEffect::SetRadius( float radius )
89 SetUniform( RADIUS_PROPERTY_NAME, radius );
92 void IrisEffect::SetBlendFactor(float value )
94 SetUniform( BLEND_FACTOR_PROPERTY_NAME, value );
97 void IrisEffect::SetCenter( const Vector2& center )
99 SetUniform( CENTER_PROPERTY_NAME, center );
102 const std::string& IrisEffect::GetRadiusPropertyName() const
104 return RADIUS_PROPERTY_NAME;
107 const std::string& IrisEffect::GetBlendFactorPropertyName() const
109 return BLEND_FACTOR_PROPERTY_NAME;
112 const std::string& IrisEffect::GetCenterPropertyName() const
114 return CENTER_PROPERTY_NAME;