2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali-toolkit/public-api/shader-effects/square-dissolve-effect.h>
29 const std::string STEP_PROPERTY_NAME( "uStep" );
30 const std::string ROWS_PROPERTY_NAME( "uRows" );
31 const std::string COLUMNS_PROPERTY_NAME( "uColumns" );
32 const std::string TEXSIZE_PROPERTY_NAME( "texSize" );
36 SquareDissolveEffect::SquareDissolveEffect()
40 //Call the Parent copy constructor to add reference to the implementation for this object
41 SquareDissolveEffect::SquareDissolveEffect(ShaderEffect handle)
46 SquareDissolveEffect::~SquareDissolveEffect()
50 SquareDissolveEffect SquareDissolveEffect::New()
52 // variable "uStep" range scope : [0.0, 1.0]
53 std::string fragmentShader(
54 "uniform mediump vec2 texSize;\n"
55 "uniform mediump float uStep;\n"
56 "uniform mediump float uRows;\n"
57 "uniform mediump float uColumns;\n"
60 " mediump vec2 mosaicSize = vec2(1.0 / uRows, 1.0 / uColumns); \n"
61 " mediump vec2 intXY = vec2(vTexCoord.x * texSize.x, vTexCoord.y * texSize.y); \n"
62 " mediump vec2 XYMosaic = vec2(floor(intXY.x / mosaicSize.x) * mosaicSize.x, floor(intXY.y / mosaicSize.y) * mosaicSize.y); \n"
63 " mediump vec2 UVMosaic = vec2(XYMosaic.x /texSize.x, XYMosaic.y / texSize.y); \n"
64 " mediump vec4 noiseVec = texture2D(sEffect, UVMosaic); \n"
65 " mediump float intensity = (noiseVec[0] + noiseVec[1] + noiseVec[2] + noiseVec[3]) / 4.0; \n"
66 " if(intensity < uStep) \n"
67 " gl_FragColor = vec4(0.1, 0.1, 0.1, 1.0); \n"
69 " gl_FragColor = texture2D(sTexture, vTexCoord); \n"
70 " gl_FragColor *= uColor; \n"
73 // Create the implementation, temporarily owned on stack
74 Dali::ShaderEffect shaderEffectCustom = Dali::ShaderEffect::New(
77 GeometryType( GEOMETRY_TYPE_IMAGE ),
78 ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
80 /* Pass ownership to SquareDissolveEffect through overloaded constructor, So that it now has access to the
81 Dali::ShaderEffect implementation */
82 Dali::Toolkit::SquareDissolveEffect handle( shaderEffectCustom );
84 handle.SetUniform( TEXSIZE_PROPERTY_NAME, Vector2(1.0f, 1.0f) );//COORDINATE_TYPE_DEFAULT
85 handle.SetUniform( STEP_PROPERTY_NAME, 0.1f);
86 handle.SetUniform( ROWS_PROPERTY_NAME, 25.0f);
87 handle.SetUniform( COLUMNS_PROPERTY_NAME, 25.0f);
91 void SquareDissolveEffect::SetStep( float step )
93 SetUniform( STEP_PROPERTY_NAME, step );
96 void SquareDissolveEffect::SetRows(float rows)
98 SetUniform(ROWS_PROPERTY_NAME, rows);
101 void SquareDissolveEffect::SetColumns(float columns)
103 SetUniform(COLUMNS_PROPERTY_NAME, columns);
106 void SquareDissolveEffect::SetTextureSize(const Vector2& textureSize)
108 SetUniform(TEXSIZE_PROPERTY_NAME, textureSize);
111 const std::string& SquareDissolveEffect::GetStepPropertyName() const
113 return STEP_PROPERTY_NAME;
116 const std::string& SquareDissolveEffect::GetRowsPropertyName() const
118 return ROWS_PROPERTY_NAME;
121 const std::string& SquareDissolveEffect::GetColumnsPropertyName() const
123 return COLUMNS_PROPERTY_NAME;
126 const std::string& SquareDissolveEffect::GetTexSizePropertyName() const
128 return TEXSIZE_PROPERTY_NAME;
131 } // namespace Toolkit