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.
21 #define DALI_COMPOSE_SHADER(STR) #STR
33 * @brief Creates a new PageTurnBookSpineEffect
34 * This is an assisting effect of PageTurnEffect to display a book spine on _static_ pages, and also to flip the image horizontally when needed.
36 * When the page is turned over in landscape, call
37 * SetIsBackImageVisible(true), this effect can display the back image
38 * correctly after the page been rotated 180 degrees. To
39 * display the pages visually consistent with its turning state,
40 * please set the uniforms with the same values as the PageTurnEffect.
42 * Animatable/Constrainable uniforms:
43 * "uSpineShadowParameter" - The two parameters are the major&minor radius (in pixels) to form an ellipse shape. The top-left
44 * quarter of this ellipse is used to calculate spine normal for simulating shadow *
45 * "uTextureWidth" - 1.0 for single sided page,
46 * 2.0 for double sided image which has left half part as page front side and right half part as page back side.
48 * @return The newly created Property::Map with the page turn book spine effect
50 inline Property::Map CreatePageTurnBookSpineEffect()
52 const char* vertexSource = DALI_COMPOSE_SHADER(
53 precision mediump float;\n
54 attribute mediump vec2 aPosition;\n
55 uniform mediump mat4 uMvpMatrix;\n
57 uniform float uTextureWidth;\n
58 varying vec2 vTexCoord;\n
61 mediump vec4 vertexPosition = vec4(aPosition*uSize.xy, 0.0, 1.0);\n
62 gl_Position = uMvpMatrix * vertexPosition;\n
63 vTexCoord = aPosition + vec2(0.5);\n
64 vTexCoord.x /= uTextureWidth;
67 // the simplified version of the fragment shader of page turn effect
68 const char* fragmentSource = DALI_COMPOSE_SHADER(
69 precision mediump float;\n
70 varying mediump vec2 vTexCoord;\n
72 uniform vec2 uSpineShadowParameter;\n
73 uniform sampler2D sTexture;\n
74 uniform lowp vec4 uColor;\n
78 if( gl_FrontFacing )\n // display front side
80 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
82 else\n // display back side, flip the image horizontally by changing the x component of the texture coordinate
84 gl_FragColor = texture2D( sTexture, vec2( 1.0 - vTexCoord.x, vTexCoord.y ) ) * uColor;\n
86 // display book spine, a stripe of shadowed texture
87 float pixelPos = vTexCoord.x * uSize.x;\n
88 if( pixelPos < uSpineShadowParameter.x )\n
90 float x = pixelPos - uSpineShadowParameter.x;\n
91 float y = sqrt( uSpineShadowParameter.x*uSpineShadowParameter.x - x*x );\n
92 vec2 spineNormal = normalize(vec2(uSpineShadowParameter.y*x/uSpineShadowParameter.x, y));\n
93 gl_FragColor.rgb *= spineNormal.y; \n
99 Property::Map customShader;
101 customShader[ "vertexShader" ] = vertexSource;
102 customShader[ "fragmentShader" ] = fragmentSource;
104 map[ "shader" ] = customShader;
108 } //namespace Internal
110 } // namespace Toolkit
114 #endif /* __DALI_PAGE_TURN_BOOK_SPINE_EFFECT_H__ */