1 #ifndef DALI_PAGE_TURN_BOOK_SPINE_EFFECT_H
2 #define DALI_PAGE_TURN_BOOK_SPINE_EFFECT_H
5 * Copyright (c) 2016 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-toolkit/devel-api/visuals/visual-properties-devel.h>
24 #define DALI_COMPOSE_SHADER(STR) #STR
36 * @brief Creates a new PageTurnBookSpineEffect
37 * This is an assisting effect of PageTurnEffect to display a book spine on _static_ pages, and also to flip the image horizontally when needed.
39 * When the page is turned over in landscape, call
40 * SetIsBackImageVisible(true), this effect can display the back image
41 * correctly after the page been rotated 180 degrees. To
42 * display the pages visually consistent with its turning state,
43 * please set the uniforms with the same values as the PageTurnEffect.
45 * Animatable/Constrainable uniforms:
46 * "uSpineShadowParameter" - The two parameters are the major&minor radius (in pixels) to form an ellipse shape. The top-left
47 * quarter of this ellipse is used to calculate spine normal for simulating shadow *
48 * "uTextureWidth" - 1.0 for single sided page,
49 * 2.0 for double sided image which has left half part as page front side and right half part as page back side.
51 * @return The newly created Property::Map with the page turn book spine effect
53 inline Property::Map CreatePageTurnBookSpineEffect()
55 const char* vertexSource = DALI_COMPOSE_SHADER(
56 precision mediump float;\n
57 attribute mediump vec2 aPosition;\n
58 uniform mediump mat4 uMvpMatrix;\n
60 uniform float uTextureWidth;\n
61 varying vec2 vTexCoord;\n
64 mediump vec4 vertexPosition = vec4(aPosition*uSize.xy, 0.0, 1.0);\n
65 gl_Position = uMvpMatrix * vertexPosition;\n
66 vTexCoord = aPosition + vec2(0.5);\n
67 vTexCoord.x /= uTextureWidth;
70 // the simplified version of the fragment shader of page turn effect
71 const char* fragmentSource = DALI_COMPOSE_SHADER(
72 precision mediump float;\n
73 varying mediump vec2 vTexCoord;\n
75 uniform vec2 uSpineShadowParameter;\n
76 uniform sampler2D sTexture;\n
77 uniform lowp vec4 uColor;\n
81 if( gl_FrontFacing )\n // display front side
83 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
85 else\n // display back side, flip the image horizontally by changing the x component of the texture coordinate
87 gl_FragColor = texture2D( sTexture, vec2( 1.0 - vTexCoord.x, vTexCoord.y ) ) * uColor;\n
89 // display book spine, a stripe of shadowed texture
90 float pixelPos = vTexCoord.x * uSize.x;\n
91 if( pixelPos < uSpineShadowParameter.x )\n
93 float x = pixelPos - uSpineShadowParameter.x;\n
94 float y = sqrt( uSpineShadowParameter.x*uSpineShadowParameter.x - x*x );\n
95 vec2 spineNormal = normalize(vec2(uSpineShadowParameter.y*x/uSpineShadowParameter.x, y));\n
96 gl_FragColor.rgb *= spineNormal.y; \n
102 Property::Map customShader;
104 customShader[ Toolkit::Visual::Shader::Property::VERTEX_SHADER ] = vertexSource;
105 customShader[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = fragmentSource;
107 map[ Toolkit::DevelVisual::Property::SHADER ] = customShader;
111 } //namespace Internal
113 } // namespace Toolkit
117 #endif // DALI_PAGE_TURN_BOOK_SPINE_EFFECT_H