vec2 celshadeoffset[12] = vec2[12](vec2(-2.0,2.0),vec2(-1.0,2.0),vec2(0.0,2.0),vec2(1.0,2.0),vec2(2.0,2.0),vec2(-2.0,1.0),vec2(-1.0,1.0),vec2(0.0,1.0),vec2(1.0,1.0),vec2(2.0,1.0),vec2(1.0,0.0),vec2(2.0,0.0));

float celshade(sampler2D depth, float forcefull){
	float ph = INTENSITE_CELSHADING/1080.0;
	float pw = ph/aspectRatio;

	float outline = 1.0;
	float z = ld(texture2D(depth,texcoord.xy).r)*far*2.0;
	float minz = far;
	float sampleza = 0.0;
	float samplezb = 0.0;


	float dist = 4096.0;

	for (int i = 0; i < 12; i++){
		sampleza = ld(texture2D(depth,texcoord.xy+vec2(pw,ph)*celshadeoffset[i]).r)*far;
		samplezb = ld(texture2D(depth,texcoord.xy-vec2(pw,ph)*celshadeoffset[i]).r)*far;
		outline *= clamp(1.0-(z-(sampleza+samplezb))*0.5,0.0,1.0);
		minz = min(minz,min(sampleza,samplezb));
	}
	outline = mix(outline,1.0,min(minz/dist,clamp(0.8+0.2*isEyeInWater,0.0,1.0))*(1.0-forcefull));

	return outline;
}

vec2 bordsarrondisoffset[8] = vec2[8](vec2(1.0,0.0),vec2(-1.0,0.0),vec2(0.0,1.0),vec2(0.0,-1.0),vec2(0.7,0.7),vec2(-0.7,0.7),vec2(0.7,-0.7),vec2(-0.7,-0.7));

float bordsarrondis(sampler2D depth){
	float ph = INTENSITE_BORDS_ARRONDIS/1080.0;
	float pw = ph/aspectRatio;

	float outlinec = 1.0;
	float z = ld(texture2D(depth,texcoord.xy).r)*far;
	float totalz = 0.0;
	float maxz = 0.0;
	float sampleza = 0.0;
	float samplezb = 0.0;

	for (int i = 0; i < 12; i++){
		sampleza = ld(texture2D(depth,texcoord.xy+vec2(pw,ph)*bordsarrondisoffset[i]).r)*far;
		maxz = max(sampleza,maxz);

		samplezb = ld(texture2D(depth,texcoord.xy-vec2(pw,ph)*bordsarrondisoffset[i]).r)*far;
		maxz = max(samplezb,maxz);

		outlinec*= clamp(1.0-((sampleza+samplezb)-z*2.0)*32.0/z,0.0,1.0);

		totalz += sampleza+samplezb;
	}
	float outlinea = 1.0-clamp((z*8.0-totalz)*64.0-0.08*z,0.0,1.0)*(clamp(1.0-(z*8.0-totalz)*16.0/z,0.0,1.0));
	float outlineb = clamp(1.0+32.0*(z-maxz)/z,0.0,1.0);
	float outline = (0.25*(outlinea*outlineb)+0.75)*(0.75*(1.0-outlinec)*outlineb+1.0);
	return outline;
}