2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali-toolkit/public-api/shader-effects/iris-effect.h>
27 const std::string RADIUS_PROPERTY_NAME( "uRadius" );
28 const std::string CENTER_PROPERTY_NAME( "uCenter" );
29 const std::string BLEND_FACTOR_PROPERTY_NAME( "uBlendFactor" );
32 IrisEffect::IrisEffect()
36 //Call the Parent copy constructor to add reference to the implementation for this object
37 IrisEffect::IrisEffect(ShaderEffect handle)
42 IrisEffect::~IrisEffect()
46 IrisEffect IrisEffect::New()
48 // append the default version
49 std::string vertexShader(
50 "uniform mediump vec2 uCenter;\n"
51 "varying mediump vec2 vRelativePosition;\n"
55 " mediump vec4 world = uModelView * vec4(aPosition,1.0);\n"
56 " gl_Position = uProjection * world;\n"
58 " vTexCoord = aTexCoord;\n"
59 " vRelativePosition = aTexCoord - uCenter;\n"
62 std::string fragmentShader(
63 "uniform mediump float uRadius; \n"
64 "uniform mediump float uBlendFactor; \n"
65 "varying mediump vec2 vRelativePosition; \n"
68 " mediump float delta = (length(vRelativePosition) - uRadius); \n"
69 " delta = clamp(0.0 - delta * uBlendFactor, 0.0, 1.0); \n"
70 " gl_FragColor = texture2D(sTexture, vTexCoord) * uColor; \n"
71 " gl_FragColor.a *= delta; \n"
75 Dali::ShaderEffect shaderEffectCustom = Dali::ShaderEffect::New(
78 GeometryType( GEOMETRY_TYPE_IMAGE ),
79 ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ));
81 Dali::Toolkit::IrisEffect handle( shaderEffectCustom );
82 handle.SetUniform( RADIUS_PROPERTY_NAME, 0.0f );
83 handle.SetUniform( BLEND_FACTOR_PROPERTY_NAME, 100.0f );
84 handle.SetUniform( CENTER_PROPERTY_NAME, Vector2(0.5f, 0.5f) );
88 void IrisEffect::SetRadius( float radius )
90 SetUniform( RADIUS_PROPERTY_NAME, radius );
93 void IrisEffect::SetBlendFactor(float value )
95 SetUniform( BLEND_FACTOR_PROPERTY_NAME, value );
98 void IrisEffect::SetCenter( const Vector2& center )
100 SetUniform( CENTER_PROPERTY_NAME, center );
103 const std::string& IrisEffect::GetRadiusPropertyName() const
105 return RADIUS_PROPERTY_NAME;
108 const std::string& IrisEffect::GetBlendFactorPropertyName() const
110 return BLEND_FACTOR_PROPERTY_NAME;
113 const std::string& IrisEffect::GetCenterPropertyName() const
115 return CENTER_PROPERTY_NAME;