X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Fdevel-api%2Fshader-effects%2Fbendy-effect.h;h=78f4e6985d77a74e564dcccd96c4ceda9ea73200;hp=0fd13740f8bed87108fdc8238d13a5704008c5ab;hb=c7db41e73819a6e2b79948bd7396d948ac57a96f;hpb=f58b8383147de70affa1e3949cf1c6757d705d3c diff --git a/dali-toolkit/devel-api/shader-effects/bendy-effect.h b/dali-toolkit/devel-api/shader-effects/bendy-effect.h index 0fd1374..78f4e69 100644 --- a/dali-toolkit/devel-api/shader-effects/bendy-effect.h +++ b/dali-toolkit/devel-api/shader-effects/bendy-effect.h @@ -2,7 +2,7 @@ #define __DALI_TOOLKIT_SHADER_EFFECT_BENDY_H__ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -19,7 +19,7 @@ */ // EXTERNAL INCLUDES -#include +#include namespace Dali { @@ -28,73 +28,72 @@ namespace Toolkit { /** + * Creates a new Bendy effect + * * BendyEffect is a custom shader effect to achieve bendy effects in Image actors + * + * Animatable/Constrainable uniforms: + * "uCenter" - The center point of the bendy effect + * "uDirection" - The direction of the bendy effect + * "uRadius" - The radius of the bendy effect + * + * @return A handle to a newly allocated ShaderEffect. */ -class DALI_IMPORT_API BendyEffect : public ShaderEffect +inline ShaderEffect CreateBendyEffect() { -public: - - /** - * Create an uninitialized BendyEffect; this can be initialized with BendyEffect::New() - * Calling member functions with an uninitialized Dali::Object is not allowed. - */ - BendyEffect(); - - /** - * @brief Destructor - * - * This is non-virtual since derived Handle types must not contain data or virtual methods. - */ - ~BendyEffect(); - - /** - * Create an initialized BendyEffect. - * @return A handle to a newly allocated Dali resource. - */ - static BendyEffect New(); - - /** - * Set the center point of the bendy effect. - * @param [in] center The new center point. - */ - void SetCenter(const Vector2& center); - - /** - * Set the direction of the bendy effect. - * @param [in] direction The new direction. - */ - void SetDirection(const Vector2& direction); - - /** - * Set the radius of the bendy effect. - * @param [in] radius The new radius. - */ - 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 direction property - * which can be used in Animation API's - * @return A std::string containing the property name - */ - const std::string& GetDirectionPropertyName() const; - - /** - * Get the name for the radius property - * which can be used in Animation API's - * @return A std::string containing the property name - */ - const std::string& GetRadiusPropertyName() const; - - -private: // Not intended for application developers - DALI_INTERNAL BendyEffect(ShaderEffect handle); -}; + // append the default version + std::string vertextShader( + "uniform mediump vec2 uCenter;\n" + "uniform mediump vec2 uDirection;\n" + "uniform mediump float uRadius;\n" + "\n" + "varying mediump float vShade;\n" + "\n" + "void main()\n" + "{\n" + " mediump float lighting = 0.25;\n" + " mediump vec4 position = uModelView * vec4(aPosition, 1.0);\n" + "\n" + " mediump vec2 d = position.xy - uCenter;\n" + " mediump float dist = max( 0.0, dot(d,uDirection) );\n" + " mediump float radius = max(0.0, uRadius - dist * 0.01);\n" + "\n" + " mediump float cs = cos(dist / radius / 2.0);\n" + " mediump float sn = sin(dist / radius / 2.0);\n" + "\n" + "position.xy = position.xy - uDirection * dist;\n" + "\n" + "position.xy += uDirection * sn * radius;\n" + "position.z += (1.0 - cs) * radius;\n" + "\n" + "gl_Position = uProjection * position;\n" + "\n" + "vShade = 1.0 - abs(sn) * lighting;\n" + "\n" + "vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord );\n" + "}" ); + + std::string fragmentShader( + "varying mediump float vShade;\n" + "\n" + "void main()\n" + "{\n" + " gl_FragColor = texture2D(sTexture, vTexCoord) * uColor * vec4(vShade,vShade,vShade,1.0);\n" + "}" ); + + // Create the implementation, temporarily owned on stack, + Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New( + vertextShader, + fragmentShader, + ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_DEPTH_BUFFER )); + + shaderEffect.SetUniform( "uCenter", Vector2(0.0f, 0.0f), ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION ); + shaderEffect.SetUniform( "uDirection", Vector2(0.0f, 0.0f), ShaderEffect::COORDINATE_TYPE_VIEWPORT_DIRECTION ); + shaderEffect.SetUniform( "uRadius", 0.0f ); + + + return shaderEffect; +} } // namespace Toolkit