// Storybook shader I
// by guest(r)
// License: GNU-GPL

uniform vec4 OGL2Param;
uniform vec4 OGL2Size;
uniform sampler2D OGL2Texture;
uniform sampler2D OGL2TMU1;

void main()
{
 vec3 ink   = vec3(0.375,0.365,0.365);
 vec3 paper = texture2D(OGL2TMU1, gl_TexCoord[6].xy).xyz;
 vec3 uy = texture2D(OGL2Texture, gl_TexCoord[1].xy).xyz; 
 vec3 lx = texture2D(OGL2Texture, gl_TexCoord[4].xy).xyz; 
 vec3 ct = texture2D(OGL2Texture, gl_TexCoord[0].xy).xyz; 
 vec3 rx = texture2D(OGL2Texture, gl_TexCoord[5].xy).xyz; 
 vec3 dy = texture2D(OGL2Texture, gl_TexCoord[2].xy).xyz; 

 vec3 dt = vec3(1.0,1.0,1.0); float d;
 d = dot(abs(lx-rx),dt)/(dot(lx+rx,dt)+0.15);
 d+= dot(abs(uy-dy),dt)/(dot(uy+dy,dt)+0.15);
 d*=2.0;
 float t = 0.127; // treshold for drawing
 if (d < t)
 {
   gl_FragColor.xyz = paper;
 }
 else
 {
   gl_FragColor.xyz = ink*(1.0-(d*d));
 }
}
