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/ripple2d-effect.h>
30 const std::string TEXTURE_SIZE_PROPERTY_NAME( "uTextureSize" );
31 const std::string AMPLITUDE_PROPERTY_NAME( "uAmplitude" );
32 const std::string TIME_PROPERTY_NAME( "uTime" );
36 Ripple2DEffect::Ripple2DEffect()
40 //Call the Parent copy constructor to add reference to the implementation for this object
41 Ripple2DEffect::Ripple2DEffect(ShaderEffect handle)
46 Ripple2DEffect::~Ripple2DEffect()
51 Ripple2DEffect Ripple2DEffect::New()
53 // append the default version
54 std::string fragmentShader(
55 "precision mediump float;\n"
56 "uniform float uAmplitude;\n"
57 "uniform float uTime;\n"
60 " highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\n"
61 " highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\n"
62 " highp float len = length(pos);\n"
63 " highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude;\n"
64 " gl_FragColor = texture2D(sTexture, texCoord) * uColor;\n"
67 // Create the implementation, temporarily owned on stack
68 Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New(
70 Dali::GeometryType( GEOMETRY_TYPE_IMAGE ),
71 ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
73 /* Pass ownership to Ripple2DEffect through overloaded constructor, So that it now has access to the
74 Dali::ShaderEffect implementation */
75 Dali::Toolkit::Ripple2DEffect handle( shaderEffect );
77 handle.SetUniform( TEXTURE_SIZE_PROPERTY_NAME, Vector2(0.0f, 0.0f) );
78 handle.SetUniform( AMPLITUDE_PROPERTY_NAME, 0.0f );
79 handle.SetUniform( TIME_PROPERTY_NAME, 0.0f );
85 void Ripple2DEffect::SetAmplitude(float amplitude)
87 SetUniform( AMPLITUDE_PROPERTY_NAME, amplitude );
90 void Ripple2DEffect::SetTime(float time)
92 SetUniform( TIME_PROPERTY_NAME, time );
95 const std::string& Ripple2DEffect::GetAmplitudePropertyName() const
97 return AMPLITUDE_PROPERTY_NAME;
100 const std::string& Ripple2DEffect::GetTimePropertyName() const
102 return TIME_PROPERTY_NAME;
105 } // namespace Toolkit