2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 #include <dali-toolkit/public-api/shader-effects/square-dissolve-effect.h>
28 const std::string STEP_PROPERTY_NAME( "uStep" );
29 const std::string ROWS_PROPERTY_NAME( "uRows" );
30 const std::string COLUMNS_PROPERTY_NAME( "uColumns" );
31 const std::string TEXSIZE_PROPERTY_NAME( "texSize" );
35 SquareDissolveEffect::SquareDissolveEffect()
39 //Call the Parent copy constructor to add reference to the implementation for this object
40 SquareDissolveEffect::SquareDissolveEffect(ShaderEffect handle)
45 SquareDissolveEffect::~SquareDissolveEffect()
49 SquareDissolveEffect SquareDissolveEffect::New()
51 // variable "uStep" range scope : [0.0, 1.0]
52 std::string fragmentShader(
53 "uniform vec2 texSize; \n"
54 "uniform float uStep; \n"
55 "uniform float uRows; \n"
56 "uniform float uColumns; \n"
59 " vec2 mosaicSize = vec2(1.0 / uRows, 1.0 / uColumns); \n"
60 " vec2 intXY = vec2(vTexCoord.x * texSize.x, vTexCoord.y * texSize.y); \n"
61 " vec2 XYMosaic = vec2(floor(intXY.x / mosaicSize.x) * mosaicSize.x, floor(intXY.y / mosaicSize.y) * mosaicSize.y); \n"
62 " vec2 UVMosaic = vec2(XYMosaic.x /texSize.x, XYMosaic.y / texSize.y); \n"
63 " vec4 noiseVec = texture2D(sEffect, UVMosaic); \n"
64 " float intensity = (noiseVec[0] + noiseVec[1] + noiseVec[2] + noiseVec[3]) / 4.0; \n"
65 " if(intensity < uStep) \n"
66 " gl_FragColor = vec4(0.1, 0.1, 0.1, 1.0); \n"
68 " gl_FragColor = texture2D(sTexture, vTexCoord); \n"
69 " gl_FragColor *= uColor; \n"
72 // Create the implementation, temporarily owned on stack
73 Dali::ShaderEffect shaderEffectCustom = Dali::ShaderEffect::New(
76 GeometryType( GEOMETRY_TYPE_IMAGE ),
77 ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
79 /* Pass ownership to SquareDissolveEffect through overloaded constructor, So that it now has access to the
80 Dali::ShaderEffect implementation */
81 Dali::Toolkit::SquareDissolveEffect handle( shaderEffectCustom );
83 handle.SetUniform( TEXSIZE_PROPERTY_NAME, Vector2(1.0f, 1.0f) );//COORDINATE_TYPE_DEFAULT
84 handle.SetUniform( STEP_PROPERTY_NAME, 0.1f);
85 handle.SetUniform( ROWS_PROPERTY_NAME, 25.0f);
86 handle.SetUniform( COLUMNS_PROPERTY_NAME, 25.0f);
90 void SquareDissolveEffect::SetStep( float step )
92 SetUniform( STEP_PROPERTY_NAME, step );
95 void SquareDissolveEffect::SetRows(float rows)
97 SetUniform(ROWS_PROPERTY_NAME, rows);
100 void SquareDissolveEffect::SetColumns(float columns)
102 SetUniform(COLUMNS_PROPERTY_NAME, columns);
105 void SquareDissolveEffect::SetTextureSize(const Vector2& textureSize)
107 SetUniform(TEXSIZE_PROPERTY_NAME, textureSize);
110 const std::string& SquareDissolveEffect::GetStepPropertyName() const
112 return STEP_PROPERTY_NAME;
115 const std::string& SquareDissolveEffect::GetRowsPropertyName() const
117 return ROWS_PROPERTY_NAME;
120 const std::string& SquareDissolveEffect::GetColumnsPropertyName() const
122 return COLUMNS_PROPERTY_NAME;
125 const std::string& SquareDissolveEffect::GetTexSizePropertyName() const
127 return TEXSIZE_PROPERTY_NAME;
130 } // namespace Toolkit