-#ifndef __DALI_PAGE_TURN_BOOK_SPINE_EFFECT_H__
-#define __DALI_PAGE_TURN_BOOK_SPINE_EFFECT_H__
+#ifndef DALI_PAGE_TURN_BOOK_SPINE_EFFECT_H
+#define DALI_PAGE_TURN_BOOK_SPINE_EFFECT_H
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
*/
-// EXTERNAL INCLUDES
-#include <dali/public-api/shader-effects/shader-effect.h>
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+
+#define DALI_COMPOSE_SHADER(STR) #STR
namespace Dali
{
*
* When the page is turned over in landscape, call
* SetIsBackImageVisible(true), this effect can display the back image
- * correctly after the imageActor been rotated 180 degrees. To
+ * correctly after the page been rotated 180 degrees. To
* display the pages visually consistent with its turning state,
* please set the uniforms with the same values as the PageTurnEffect.
*
* Animatable/Constrainable uniforms:
- * "uShadowWidth" - The width of shadow to be pageSize * shadowWidth. This shadow appears at the edges of the actor
- * which is not visible on static pages
* "uSpineShadowParameter" - The two parameters are the major&minor radius (in pixels) to form an ellipse shape. The top-left
- * quarter of this ellipse is used to calculate spine normal for simulating shadow
- * "uIsBackImageVisible" - Set whether the current page is with its backside visible. Need to pass the parameter as true for
- * the page which is turned over but still visible in Landscape
- * "uPageWidth" - The page width of the PageTurnBookSpineEffect
+ * quarter of this ellipse is used to calculate spine normal for simulating shadow *
+ * "uTextureWidth" - 1.0 for single sided page,
+ * 2.0 for double sided image which has left half part as page front side and right half part as page back side.
*
- * @return A handle to a newly allocated ShaderEffect
+ * @return The newly created Property::Map with the page turn book spine effect
**/
-inline ShaderEffect CreatePageTurnBookSpineEffect()
+inline Property::Map CreatePageTurnBookSpineEffect()
{
- std::string vertexSource(
- "precision mediump float;\n"
- "uniform float uShadowWidth;\n"
- " void main()\n"
- " {\n"
- " gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n"
- " vTexCoord.x = (aTexCoord.x-sTextureRect.s) /( 1.0 - uShadowWidth ) + sTextureRect.s;\n"
- " vTexCoord.y = ( aTexCoord.y-sTextureRect.t-0.5*uShadowWidth*(sTextureRect.q-sTextureRect.t) )/( 1.0 - uShadowWidth ) + sTextureRect.t;\n"
- " }");
+ const char* vertexSource = DALI_COMPOSE_SHADER(
+ precision mediump float;\n
+ attribute mediump vec2 aPosition;\n
+ uniform mediump mat4 uMvpMatrix;\n
+ uniform vec3 uSize;\n
+ uniform float uTextureWidth;\n
+ varying vec2 vTexCoord;\n
+ void main()\n
+ {\n
+ mediump vec4 vertexPosition = vec4(aPosition*uSize.xy, 0.0, 1.0);\n
+ gl_Position = uMvpMatrix * vertexPosition;\n
+ vTexCoord = aPosition + vec2(0.5);\n
+ vTexCoord.x /= uTextureWidth;
+ }\n);
// the simplified version of the fragment shader of page turn effect
- std::string fragmentSource(
- "precision mediump float;\n"
- "uniform float uIsBackImageVisible;\n"
- "uniform float uPageWidth;\n"
- "uniform vec2 uSpineShadowParameter;\n"
- " void main()\n"
- " {\n"
- // leave the border for display shadow, not visible( out of the screen ) when the page is static
- " if( vTexCoord.y > sTextureRect.q || vTexCoord.y < sTextureRect.t || vTexCoord.x > sTextureRect.p )\n"
- " {\n"
- " gl_FragColor = vec4( 0.0 );\n"
- " }\n"
- " else \n"
- " { \n"
- // flip the image horizontally by changing the x component of the texture coordinate
- " if( uIsBackImageVisible == 1.0 ) gl_FragColor = texture2D( sTexture, vec2( sTextureRect.p+sTextureRect.s-vTexCoord.x, vTexCoord.y ) ) * uColor; \n"
- " else gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n"
- " \n"
- // display book spine, a stripe of shadowed texture
- " float pixelPos = (vTexCoord.x-sTextureRect.s)*uPageWidth; \n"
- " if(pixelPos < uSpineShadowParameter.x) \n"
- " {\n"
- " float x = pixelPos - uSpineShadowParameter.x;\n"
- " float y = sqrt( uSpineShadowParameter.x*uSpineShadowParameter.x - x*x );\n"
- " vec2 spineNormal = normalize(vec2(uSpineShadowParameter.y*x/uSpineShadowParameter.x, y));\n"
- " gl_FragColor.rgb *= spineNormal.y; \n"
- " }"
- " }\n"
- " }" );
-
- const float DEFAULT_SHADOW_WIDTH(0.15f);
- const Vector2 DEFAULT_SPINE_SHADOW_PARAMETER(50.0f, 20.0f);
-
- ShaderEffect shaderEffect = ShaderEffect::New( vertexSource, fragmentSource );
-
- shaderEffect.SetUniform( "uIsBackImageVisible", -1.f );
- shaderEffect.SetUniform( "uShadowWidth", DEFAULT_SHADOW_WIDTH );
- shaderEffect.SetUniform( "uSpineShadowParameter", DEFAULT_SPINE_SHADOW_PARAMETER );
-
- float defaultPageWidth = Dali::Stage::GetCurrent().GetSize().x;
- shaderEffect.SetUniform( "uPageWidth", defaultPageWidth/(1.f-DEFAULT_SHADOW_WIDTH) );
-
- return shaderEffect;
+ const char* fragmentSource = DALI_COMPOSE_SHADER(
+ precision mediump float;\n
+ varying mediump vec2 vTexCoord;\n
+ uniform vec3 uSize;\n
+ uniform vec2 uSpineShadowParameter;\n
+ uniform sampler2D sTexture;\n
+ uniform lowp vec4 uColor;\n
+
+ void main()\n
+ {\n
+ if( gl_FrontFacing )\n // display front side
+ {\n
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
+ }\n
+ else\n // display back side, flip the image horizontally by changing the x component of the texture coordinate
+ {\n
+ gl_FragColor = texture2D( sTexture, vec2( 1.0 - vTexCoord.x, vTexCoord.y ) ) * uColor;\n
+ }\n
+ // display book spine, a stripe of shadowed texture
+ float pixelPos = vTexCoord.x * uSize.x;\n
+ if( pixelPos < uSpineShadowParameter.x )\n
+ {\n
+ float x = pixelPos - uSpineShadowParameter.x;\n
+ float y = sqrt( uSpineShadowParameter.x*uSpineShadowParameter.x - x*x );\n
+ vec2 spineNormal = normalize(vec2(uSpineShadowParameter.y*x/uSpineShadowParameter.x, y));\n
+ gl_FragColor.rgb *= spineNormal.y; \n
+ }\n
+ } );
+
+ Property::Map map;
+
+ Property::Map customShader;
+
+ customShader[ Toolkit::Visual::Shader::Property::VERTEX_SHADER ] = vertexSource;
+ customShader[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = fragmentSource;
+
+ map[ Toolkit::Visual::Property::SHADER ] = customShader;
+ return map;
}
} //namespace Internal
} // namespace Dali
-#endif /* __DALI_PAGE_TURN_BOOK_SPINE_EFFECT_H__ */
+#endif // DALI_PAGE_TURN_BOOK_SPINE_EFFECT_H