// Cartoon shader I
// by guest(r)
// license: GNU-GPL

const float th = 0.15;      // outlines sensitivity, recommended from 0.00...0.50
const float bb = 2.00;      // outlines strength,    recommended from 0.50...4.00
const float pp = 1.50;      // outlines blackening,  recommended from 0.25...2.00

uniform sampler2D OGL2Texture;

void main()

{

 vec3 uy = texture2D(OGL2Texture, gl_TexCoord[1].xy).xyz; 
 vec3 lx = texture2D(OGL2Texture, gl_TexCoord[4].xy).xyz; 
 vec3 rx = texture2D(OGL2Texture, gl_TexCoord[5].xy).xyz; 
 vec3 dy = texture2D(OGL2Texture, gl_TexCoord[2].xy).xyz; 
 vec3 ct = texture2D(OGL2Texture, gl_TexCoord[0].xy).xyz; 
 vec3 dt = vec3(1.0,1.0,1.0);

 float d1 = 2.5*dot(abs(lx-rx),dt)/(dot(lx+rx,dt)+0.50);
 float d2 = 2.5*dot(abs(uy-dy),dt)/(dot(uy+dy,dt)+0.50);
 float d  = d1 + d2;

 gl_FragColor.xyz = (1.15-bb*pow(max(d-th,0.0),pp))*ct;

}
