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=a3ff4701cb2ae4c8afa51650fa8e7efd21e68392;hb=4eb683ee97fc0d8a7278b50252a467b843f869df;hpb=e2eda444afbe82e9591fe198eef339227f90a616 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 a3ff470..6760f4c 100644 --- a/dali-toolkit/public-api/shader-effects/square-dissolve-effect.h +++ b/dali-toolkit/public-api/shader-effects/square-dissolve-effect.h @@ -1,110 +1,81 @@ #ifndef __DALI_TOOLKIT_SHADER_EFFECT_SQUARE_H__ #define __DALI_TOOLKIT_SHADER_EFFECT_SQUARE_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 +// EXTERNAL INCLUDES +#include -namespace Dali DALI_IMPORT_API +namespace Dali { 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 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(); - - /** - * Virtual destructor. - */ - virtual ~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 - 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