1 precision mediump float;
2 varying mediump vec2 vTexCoord;
4 uniform vec2 uSpineShadowParameter;
5 uniform sampler2D sTexture;
6 uniform lowp vec4 uColor;
10 if( gl_FrontFacing ) // display front side
12 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;
14 else // display back side, flip the image horizontally by changing the x component of the texture coordinate
16 gl_FragColor = texture2D( sTexture, vec2( 1.0 - vTexCoord.x, vTexCoord.y ) ) * uColor;
18 // display book spine, a stripe of shadowed texture
19 float pixelPos = vTexCoord.x * uSize.x;
20 if( pixelPos < uSpineShadowParameter.x )
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;