Shader compilation tool for dali-toolkit
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / graphics / shaders / page-turn-effect.frag
1 precision mediump float;
2
3 varying mediump vec2 vTexCoord;
4
5 uniform sampler2D sTexture;
6 uniform lowp vec4 uColor;
7 uniform vec3 uSize;
8 uniform vec2 uSpineShadowParameter;
9 varying vec3 vNormal;
10 varying vec4 vPosition;
11
12 void main()
13 {
14   // need to re-normalize the interpolated normal
15   vec3 normal = normalize( vNormal );
16   // display page content
17   vec4 texel;
18   // display back image of the page, flip the texture
19   if(  dot(vPosition.xyz, normal) > 0.0 ) texel = texture2D( sTexture, vec2( 1.0 - vTexCoord.x, vTexCoord.y ) );
20   // display front image of the page
21   else texel = texture2D( sTexture, vTexCoord );
22
23   // display book spine, a stripe of shadowed texture
24   float pixelPos = vTexCoord.x * uSize.x;
25   float spineShadowCoef = 1.0;
26   if( pixelPos < uSpineShadowParameter.x )
27   {
28     float x = pixelPos - uSpineShadowParameter.x;
29     float y = sqrt( uSpineShadowParameter.x*uSpineShadowParameter.x - x*x );
30     spineShadowCoef = normalize( vec2( uSpineShadowParameter.y*x/uSpineShadowParameter.x, y ) ).y;
31   }
32   // calculate the lighting
33   // set the ambient color as vec3(0.4);
34   float lightColor = abs( normal.z ) * 0.6 + 0.4;
35   gl_FragColor = vec4( ( spineShadowCoef * lightColor ) * texel.rgb , texel.a ) * uColor;
36 }