Shader compilation tool for dali-toolkit
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / graphics / shaders / page-turn-book-spine-effect.frag
1 precision mediump float;
2 varying mediump vec2 vTexCoord;
3 uniform vec3 uSize;
4 uniform vec2 uSpineShadowParameter;
5 uniform sampler2D sTexture;
6 uniform lowp vec4 uColor;
7
8 void main()
9 {
10   if( gl_FrontFacing ) // display front side
11   {
12     gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;
13   }
14   else // display back side, flip the image horizontally by changing the x component of the texture coordinate
15   {
16     gl_FragColor = texture2D( sTexture, vec2( 1.0 - vTexCoord.x, vTexCoord.y ) ) * uColor;
17   }
18   // display book spine, a stripe of shadowed texture
19   float pixelPos = vTexCoord.x * uSize.x;
20   if( pixelPos < uSpineShadowParameter.x )
21   {
22     float x = pixelPos - uSpineShadowParameter.x;
23     float y = sqrt( uSpineShadowParameter.x*uSpineShadowParameter.x - x*x );
24     vec2 spineNormal = normalize(vec2(uSpineShadowParameter.y*x/uSpineShadowParameter.x, y));
25     gl_FragColor.rgb *= spineNormal.y;
26   }
27 }