1 #ifndef __DALI_TOOLKIT_SHADER_EFFECT_SPOT_H__
2 #define __DALI_TOOLKIT_SHADER_EFFECT_SPOT_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 SpotEffect
33 * SpotEffect is a custom shader effect to achieve spot effects on Image actors
35 * Animatable/Constrainable uniforms:
36 * "uCenter" - The center of the spot. Default value (0.0,0.0)
37 * "uRadius" - The radius of the spot. Default value 0.0
39 * @return A handle to a newly allocated ShaderEffect
41 inline ShaderEffect CreateSpotEffect()
43 // append the default version
44 std::string vertexShader(
45 "uniform mediump vec2 uCenter;\n"
46 "uniform mediump float uRadius;\n"
47 "varying mediump float vRange;\n"
51 " mediump vec4 world = vec4(aPosition, 1.0);\n"
53 " mediump vec2 d = vec2(world.xy - uCenter);\n"
54 " mediump float dist = length(d);\n"
56 " mediump float range = (uRadius - dist) / (uRadius);\n"
57 " vRange = max(0.1, range);\n"
59 " gl_Position = uMvpMatrix * world;\n"
60 " vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord );\n"
63 std::string fragmentShader(
64 "varying mediump float vRange;\n"
68 " gl_FragColor = texture2D(sTexture, vTexCoord) * vec4(vRange, vRange, vRange, 1.0) * uColor;\n"
71 Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
72 vertexShader, fragmentShader,
73 ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID ));
75 shaderEffect.SetUniform( "uCenter", Vector2(0.0f, 0.0f) );
76 shaderEffect.SetUniform( "uRadius", 0.0f );
81 } // namespace Toolkit
85 #endif // __DALI_TOOLKIT_SHADER_EFFECT_SPOT_H__