1 precision mediump float;
3 varying mediump vec2 vTexCoord;
5 uniform sampler2D sTexture;
6 uniform lowp vec4 uColor;
8 uniform vec2 uSpineShadowParameter;
10 varying vec4 vPosition;
14 // need to re-normalize the interpolated normal
15 vec3 normal = normalize( vNormal );
16 // display page content
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 );
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 )
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;
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;