X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Fpublic-api%2Fshader-effects%2Fsquare-dissolve-effect.h;h=6760f4c46aff9735801b07405deb6ff526ac878c;hp=63e26b14792b3ec102420724cad2be205baec200;hb=4eb683ee97fc0d8a7278b50252a467b843f869df;hpb=306d2f61a1b64179e801fa8a0bb2bd7b4e9dd682 diff --git a/dali-toolkit/public-api/shader-effects/square-dissolve-effect.h b/dali-toolkit/public-api/shader-effects/square-dissolve-effect.h index 63e26b1..6760f4c 100644 --- a/dali-toolkit/public-api/shader-effects/square-dissolve-effect.h +++ b/dali-toolkit/public-api/shader-effects/square-dissolve-effect.h @@ -2,7 +2,7 @@ #define __DALI_TOOLKIT_SHADER_EFFECT_SQUARE_H__ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. @@ -28,86 +28,54 @@ namespace Toolkit { /** + * @brief Creates a new SquareDissolveEffect + * * SquareDissolveEffect is a custom shader effect to achieve square effects in Image actors + * + * Animatable/Constrainable uniforms: + * "uStep" - The step of the square effect + * "uRows" - The rows of the square dissolve effect + * "uColumns" - The columns of the square dissolve effect + * "uTextureSize"- The texture size of the square dissolve + * + * @return A handle to a newly allocated ShaderEffect */ -class DALI_IMPORT_API SquareDissolveEffect : public ShaderEffect +inline ShaderEffect CreateSquareDissolveEffect() { -public: - - /** - * Create an uninitialized SquareDissolveEffect; this can be initialized with BendyEffect::New() - * Calling member functions with an uninitialized Dali::Object is not allowed. - */ - SquareDissolveEffect(); - - /** - * @brief Destructor - * - * This is non-virtual since derived Handle types must not contain data or virtual methods. - */ - ~SquareDissolveEffect(); - - /** - * Create an initialized SquareDissolveEffect. - * @return A handle to a newly allocated Dali resource. - */ - static SquareDissolveEffect New(); - - /** - * Set the step of the square effect. - * @param [in] step the new step. - */ - void SetStep(float step); - - /** - * Set the rows of the square dissolve effect. - * @param [in] rows the new rows value. - */ - void SetRows(float rows); - - /** - * Set the columns of the square dissolve effect. - * @param [in] columns the new columns value. - */ - void SetColumns(float columns); - - /** - * Set the texture size of the square dissolve. - * @param[in] textureSize The texture size in Vector2. - */ - void SetTextureSize(const Vector2& textureSize); - - /** - * Get the name for the step property - * which can be used in Animation API's - * @return A std::string containing the property name - */ - const std::string& GetStepPropertyName() const; - - /** - * Get the name for the rows property - * which can be used in Animation API's - * @return A std::string containing the property name - */ - const std::string& GetRowsPropertyName() const; - - /** - * Get the name for the columns property - * which can be used in Animation API's - * @return A std::string containing the property name - */ - const std::string& GetColumnsPropertyName() const; - - /** - * Get the name for the texSize property - * which can be used in Animation API's - * @return A std::string containing the property name - */ - const std::string& GetTexSizePropertyName() const; - -private: // Not intended for application developers - DALI_INTERNAL SquareDissolveEffect(ShaderEffect handle); -}; + // variable "uStep" range scope : [0.0, 1.0] + std::string fragmentShader( + "uniform mediump vec2 uTextureSize;\n" + "uniform mediump float uStep;\n" + "uniform mediump float uRows;\n" + "uniform mediump float uColumns;\n" + "void main()\n" + "{\n" + " mediump vec2 mosaicSize = vec2(1.0 / uRows, 1.0 / uColumns); \n" + " mediump vec2 intXY = vec2(vTexCoord.x * uTextureSize.x, vTexCoord.y * uTextureSize.y); \n" + " mediump vec2 XYMosaic = vec2(floor(intXY.x / mosaicSize.x) * mosaicSize.x, floor(intXY.y / mosaicSize.y) * mosaicSize.y); \n" + " mediump vec2 UVMosaic = vec2(XYMosaic.x /uTextureSize.x, XYMosaic.y / uTextureSize.y); \n" + " mediump vec4 noiseVec = texture2D(sEffect, UVMosaic); \n" + " mediump float intensity = (noiseVec[0] + noiseVec[1] + noiseVec[2] + noiseVec[3]) / 4.0; \n" + " if(intensity < uStep) \n" + " gl_FragColor = vec4(0.1, 0.1, 0.1, 1.0); \n" + " else \n" + " gl_FragColor = texture2D(sTexture, vTexCoord); \n" + " gl_FragColor *= uColor; \n" + "} \n" ); + + Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New( + "", + fragmentShader, + GeometryType( GEOMETRY_TYPE_IMAGE ), + ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID )); + + shaderEffect.SetUniform( "uTextureSize", Vector2(1.0f, 1.0f) );//COORDINATE_TYPE_DEFAULT + shaderEffect.SetUniform( "uStep", 0.1f); + shaderEffect.SetUniform( "uRows", 25.0f); + shaderEffect.SetUniform( "uColumns", 25.0f); + + return shaderEffect; +} } // namespace Toolkit