1 #ifndef __DALI_PAGE_TURN_BOOK_SPINE_EFFECT_H__
2 #define __DALI_PAGE_TURN_BOOK_SPINE_EFFECT_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/shader-effects/shader-effect.h>
34 * @brief Creates a new PageTurnBookSpineEffect
35 * This is an assisting effect of PageTurnEffect to display a book spine on _static_ pages, and also to flip the image horizontally when needed.
37 * When the page is turned over in landscape, call
38 * SetIsBackImageVisible(true), this effect can display the back image
39 * correctly after the imageActor been rotated 180 degrees. To
40 * display the pages visually consistent with its turning state,
41 * please set the uniforms with the same values as the PageTurnEffect.
43 * Animatable/Constrainable uniforms:
44 * "uSpineShadowParameter" - The two parameters are the major&minor radius (in pixels) to form an ellipse shape. The top-left
45 * quarter of this ellipse is used to calculate spine normal for simulating shadow
46 * "uIsBackImageVisible" - Set whether the current page is with its backside visible. Need to pass the parameter as true for
47 * the page which is turned over but still visible in Landscape
48 * "uPageWidth" - The page width of the PageTurnBookSpineEffect
50 * @return A handle to a newly allocated ShaderEffect
52 inline ShaderEffect CreatePageTurnBookSpineEffect()
54 std::string vertexSource = DALI_COMPOSE_SHADER(
55 precision mediump float;\n
58 gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n
59 vTexCoord = aTexCoord;\n
62 // the simplified version of the fragment shader of page turn effect
63 std::string fragmentSource = DALI_COMPOSE_SHADER(
64 precision mediump float;\n
65 uniform float uIsBackImageVisible;\n
66 uniform float uPageWidth;\n
67 uniform vec2 uSpineShadowParameter;\n
70 // flip the image horizontally by changing the x component of the texture coordinate
71 if( uIsBackImageVisible == 1.0 )\n
72 gl_FragColor = texture2D( sTexture, vec2( sTextureRect.p+sTextureRect.s-vTexCoord.x, vTexCoord.y ) ) * uColor; \n
74 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
75 // display book spine, a stripe of shadowed texture
76 float pixelPos = (vTexCoord.x-sTextureRect.s)*uPageWidth; \n
77 if(pixelPos < uSpineShadowParameter.x) \n
79 float x = pixelPos - uSpineShadowParameter.x;\n
80 float y = sqrt( uSpineShadowParameter.x*uSpineShadowParameter.x - x*x );\n
81 vec2 spineNormal = normalize(vec2(uSpineShadowParameter.y*x/uSpineShadowParameter.x, y));\n
82 gl_FragColor.rgb *= spineNormal.y; \n
86 const Vector2 DEFAULT_SPINE_SHADOW_PARAMETER(50.0f, 20.0f);
88 ShaderEffect shaderEffect = ShaderEffect::New( vertexSource, fragmentSource );
90 shaderEffect.SetUniform( "uIsBackImageVisible", -1.f );
91 shaderEffect.SetUniform( "uSpineShadowParameter", DEFAULT_SPINE_SHADOW_PARAMETER );
93 float defaultPageWidth = Dali::Stage::GetCurrent().GetSize().x;
94 shaderEffect.SetUniform( "uPageWidth", defaultPageWidth );
99 } //namespace Internal
101 } // namespace Toolkit
105 #endif /* __DALI_PAGE_TURN_BOOK_SPINE_EFFECT_H__ */