#ifndef __DALI_TOOLKIT_SHADER_EFFECT_SPOT_H__
#define __DALI_TOOLKIT_SHADER_EFFECT_SPOT_H__
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
-// INTERNAL INCLUDES
-#include <dali/dali.h>
+// EXTERNAL INCLUDES
+#include <dali/public-api/shader-effects/shader-effect.h>
-namespace Dali DALI_IMPORT_API
+namespace Dali
{
namespace Toolkit
{
/**
- * SpotEffect2D is a custom shader effect to achieve spot effects on Image actors
+ * @brief Creates a new SpotEffect
+ *
+ * SpotEffect is a custom shader effect to achieve spot effects on Image actors
+ *
+ * Animatable/Constrainable uniforms:
+ * "uCenter" - The center of the spot. Default value (0.0,0.0)
+ * "uRadius" - The radius of the spot. Default value 0.0
+ *
+ * @return A handle to a newly allocated ShaderEffect
*/
-class SpotEffect : public ShaderEffect
+inline ShaderEffect CreateSpotEffect()
{
-public:
-
- /**
- * Create an uninitialized SpotEffect; this can be initialized with SpotEffect::New()
- * Calling member functions with an uninitialized Dali::Object is not allowed.
- */
- SpotEffect();
-
- /**
- * Virtual destructor.
- */
- virtual ~SpotEffect();
-
- /**
- * Create an initialized SpotEffect.
- * @return A handle to a newly allocated Dali resource.
- */
- static SpotEffect New();
-
- /**
- * Set the center of the spot.
- * @param[in] center The center in Vector2.
- */
- void SetCenter(const Vector2& center);
-
- /**
- * Set the radius of the spot.
- * @param[in] radius The radius in float.
- */
- void SetRadius(float radius);
-
- /**
- * Get the name for the center property
- * @return A std::string containing the property name
- */
- const std::string& GetCenterPropertyName() const;
-
- /**
- * Get the name for the radius property
- * @return A std::string containing the property name
- */
- const std::string& GetRadiusPropertyName() const;
-
-private:
- SpotEffect(ShaderEffect handle);
-
-};
+ // append the default version
+ std::string vertexShader(
+ "uniform mediump vec2 uCenter;\n"
+ "uniform mediump float uRadius;\n"
+ "varying mediump float vRange;\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " mediump vec4 world = vec4(aPosition, 1.0);\n"
+ " \n"
+ " mediump vec2 d = vec2(world.xy - uCenter);\n"
+ " mediump float dist = length(d);\n"
+ " \n"
+ " mediump float range = (uRadius - dist) / (uRadius);\n"
+ " vRange = max(0.1, range);\n"
+ " \n"
+ " gl_Position = uMvpMatrix * world;\n"
+ " vTexCoord = aTexCoord;\n"
+ "}");
+
+ std::string fragmentShader(
+ "varying mediump float vRange;\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " gl_FragColor = texture2D(sTexture, vTexCoord) * vec4(vRange, vRange, vRange, 1.0) * uColor;\n"
+ "}" );
+
+ Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
+ vertexShader, fragmentShader,
+ Dali::GeometryType( GEOMETRY_TYPE_IMAGE ),
+ ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID ));
+
+ shaderEffect.SetUniform( "uCenter", Vector2(0.0f, 0.0f) );
+ shaderEffect.SetUniform( "uRadius", 0.0f );
+
+ return shaderEffect;
+}
} // namespace Toolkit