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/mirror-effect.h>
28 const std::string DEPTH_PROPERTY_NAME( "uDepth" );
29 const std::string ALPHA_PROPERTY_NAME( "uAlpha" );
33 MirrorEffect::MirrorEffect()
37 //Call the Parent copy constructor to add reference to the implementation for this object
38 MirrorEffect::MirrorEffect(ShaderEffect handle)
43 MirrorEffect::~MirrorEffect()
47 MirrorEffect MirrorEffect::New()
50 std::string vertextShader(
51 "precision mediump float; \n"
54 " vec3 pos = aPosition; \n"
55 " pos.y = pos.y * 3.0; \n"
56 " vec4 world = uModelView * vec4(pos,1.0); \n"
57 " gl_Position = uProjection * world; \n"
58 " vTexCoord = aTexCoord; \n"
61 std::string fragmentShader(
62 "uniform float uDepth; \n"
63 "uniform float uAlpha; \n"
66 " if(vTexCoord.y < 1.0 / 3.0) \n"
68 " gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n"
70 " else if(vTexCoord.y < 2.0 / 3.0) \n"
72 " gl_FragColor = texture2D(sTexture, vec2(vTexCoord.x, vTexCoord.y * 3.0 - 1.0)) * uColor; \n"
73 " gl_FragColor.a *= uAlpha; \n"
77 " float darkness = 3.0 - vTexCoord.y * 3.0; \n"
78 " darkness = (1.0 - 1.0 / uDepth + darkness * 1.0/ uDepth) * 0.65; \n"
79 " vec4 color = texture2D(sTexture, vec2(vTexCoord.x, -vTexCoord.y *3.0 + 3.0)) * uColor; \n"
80 " color.a *= uAlpha; \n"
81 " gl_FragColor = color * vec4(darkness, darkness, darkness, darkness); \n"
85 // Create the implementation, temporarily owned on stack,
86 Dali::ShaderEffect shaderEffectCustom = Dali::ShaderEffect::New(
89 GeometryType( GEOMETRY_TYPE_IMAGE ),
90 ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ));
92 /* Pass ownership to MirrorEffect through overloaded constructor, So that it now has access to the
93 Dali::ShaderEffect implementation */
94 Dali::Toolkit::MirrorEffect handle( shaderEffectCustom );
95 handle.SetUniform(ALPHA_PROPERTY_NAME, 1.0f);
96 handle.SetUniform(DEPTH_PROPERTY_NAME, 0.5f);
100 void MirrorEffect::SetDepth( float depth )
102 SetUniform( DEPTH_PROPERTY_NAME, depth );
105 void MirrorEffect::SetAlpha( float alpha )
107 SetUniform( ALPHA_PROPERTY_NAME, alpha );
110 const std::string& MirrorEffect::GetDepthPropertyName() const
112 return DEPTH_PROPERTY_NAME;
115 const std::string& MirrorEffect::GetAlphaPropertyName() const
117 return ALPHA_PROPERTY_NAME;
120 } // namespace Toolkit