#ifndef SWIFT_SHADER_SOURCE_H
#define SWIFT_SHADER_SOURCE_H

#define bss " \
#version 150 \n \
\
in vec2 position; \n \
in vec2 texCoord; \n \
out vec2 texCoord0; \n \
uniform mat4 transform; \n \
uniform vec4 texcoords; \n \
\
void main() { \n \
	vec2 finaltexcoord = texCoord; \n \
\
	if (texCoord == vec2(0.0, 0.0)) \n \
		finaltexcoord = texcoords.xy; \n \
	if (texCoord == vec2(0.0, 1.0)) \n \
		finaltexcoord = texcoords.xw; \n \
	if (texCoord == vec2(1.0, 0.0)) \n \
		finaltexcoord = texcoords.zy; \n \
	if (texCoord == vec2(1.0, 1.0)) \n \
		finaltexcoord = texcoords.zw; \n \
\
	gl_Position = transform * vec4(position, 0.0, 1.0); \n \
	texCoord0 = finaltexcoord; \n \
}"

#define bfs "\
#version 150 \n \
\
in vec2 texCoord0; \n \
uniform vec4 screensize; \n \
uniform vec4 colour; \n \
out vec4 outColor; \n \
\
void main() { \n \
	vec2 pos = gl_FragCoord.xy; \n \
\
	if ((pos.x < screensize.x || pos.x  > screensize.z) || \
		(pos.y < screensize.y || pos.y  > screensize.w)) \n \
	discard; \n \
\
	vec4 baseColour = colour; \n \
\
	if(baseColour.a < 0.2)discard; \
	outColor = baseColour; \n \
}"

#define bfts " \
#version 150 \n \
\
in vec2 texCoord0; \n \
uniform vec4 screensize; \n \
uniform sampler2D sampler; \n \
uniform vec4 colour; \n \
out vec4 outColor; \n \
\
void main() { \n \
	vec2 pos = gl_FragCoord.xy; \n \
\
	if ((pos.x < screensize.x || pos.x  > screensize.z) || \
		(pos.y < screensize.y || pos.y  > screensize.w)) \n \
	discard; \n \
\
	vec4 baseColour = colour; \n \
	vec4 textureColour = texture(sampler, texCoord0.xy); \n \
\
	if (textureColour != vec4(0.0, 0.0, 0.0, 0.0)) \n \
		baseColour *= textureColour; \n \
	if (baseColour.a != textureColour.a) \n \
		baseColour.a *= textureColour.a; \n \
\
	if(baseColour.a < 0.2)discard; \
	outColor = baseColour; \n \
}"

#define afs " \
#version 150 \n \
\
in vec2 texCoord0; \n \
uniform vec4 screensize; \n \
uniform sampler2D sampler; \n \
uniform vec4 colour; \n \
uniform float light; \n \
out vec4 outColor; \n \
\
void main(){ \n \
	vec2 pos = gl_FragCoord.xy; \n \
\
	if ((pos.x < screensize.x || pos.x  > screensize.z) || \
		(pos.y < screensize.y || pos.y  > screensize.w)) \n \
	discard; \n \
	vec4 baseColour = colour; \n \
	vec4 textureColour = texture(sampler, texCoord0.xy); \n \
	vec4 light = vec4(light, light, light, 1.0); \n \
	if (textureColour != vec4(0.0, 0.0, 0.0, 0.0)) \n \
	baseColour *= textureColour; \n \
	outColor = baseColour * light; \n \
}"

#define lfs " \
#version 150 \n \
\
in vec2 texCoord0; \n \
uniform sampler2D sampler; \n \
uniform vec4 colour; \n \
uniform float ambientLight; \n \
uniform vec2 lightPosition; \n \
uniform float range; \n \
uniform float intensity; \n \
out vec4 outColor; \n \
\
void main(){ \n \
	vec4 baseColour = colour; \n \
	vec4 textureColour = texture(sampler, texCoord0.xy); \n \
\
	if (textureColour != vec4(0.0, 0.0, 0.0, 0.0)) \n \
		baseColour *= textureColour; \n \
\
	float sourceDistance = length(lightPosition - gl_FragCoord.xy) + \
		(range / 2); \n \
	float finalDistance = (1.0 / sourceDistance) * (range / 2); \n \
	float powerDistance = pow(finalDistance, 2); \n \
	vec4 ambient = vec4(1.0 - ambientLight, 1.0 - ambientLight, 1.0 - \
		ambientLight, 1.0 - ambientLight); \n \
	vec4 light = vec4(powerDistance, powerDistance, powerDistance, \
		powerDistance) * ambient; \n \
\
	outColor = light * intensity * baseColour; \n \
}"

#define pfs " \
#version 150 \n \
\
struct pointlight_s{\n \
	vec2 pos; \n \
	vec4 colour; \n \
	float range; \n \
	float intensity; \n \
}; \n \
\
const int MAX_POINT_LIGHTS = 10; \n \
in vec2 texCoord0; \n \
out vec4 outColor; \n \
uniform vec4 screensize; \n \
uniform sampler2D sampler; \n \
uniform vec4 colour; \n \
uniform float ambientlight; \n \
uniform pointlight_s pointlights[MAX_POINT_LIGHTS]; \n \
\
vec4 calcpointlight_s(pointlight_s pointlight){ \n \
	float sourceDistance = length(pointlight.pos - gl_FragCoord.xy) + \
		(pointlight.range * 0.5); \n \
	float finalDistance = (1.0 / sourceDistance) * (pointlight.range * 0.5); \n\
\
	if (finalDistance > pointlight.range * 0.5) \n \
		discard; \n \
\
	float powerDistance = pow(finalDistance, 2); \n \
	vec4 ambient = vec4(1.0 - ambientlight, 1.0 - ambientlight, 1.0 - \
		ambientlight, 1.0 - ambientlight); \n \
	vec4 light = vec4(powerDistance, powerDistance, powerDistance, \
		powerDistance) * ambient; \n \
\
	return pointlight.colour * light * pointlight.intensity; \n \
} \n \
\
void main(){ \n \
	vec2 pos = gl_FragCoord.xy; \n \
\
	if ((pos.x < screensize.x || pos.x  > screensize.z) || \
		(pos.y < screensize.y || pos.y  > screensize.w)) \n \
	discard; \n \
\
	vec4 basecolour = colour; \n \
	vec4 texturecolour = texture(sampler, texCoord0.xy); \n \
	vec4 totallight = vec4(ambientlight, ambientlight, ambientlight, 1.0); \n \
\
	if (texturecolour != vec4(0.0, 0.0, 0.0, 0.0)) \n \
		basecolour *= texturecolour; \n \
\
	for (int i = 0; i < MAX_POINT_LIGHTS; i++) \n \
		if (pointlights[i].range > 0) \n \
			totallight += calcpointlight_s(pointlights[i]); \n \
\
	outColor = basecolour * totallight; \n \
}"

#define tfs " \
#version 150 \n \
\
in vec2 texCoord0; \n \
uniform vec4 screensize; \n \
uniform sampler2D sampler; \n \
uniform vec4 colour; \n \
out vec4 outColor; \n \
\
void main(){ \n \
	vec2 pos = gl_FragCoord.xy; \n \
\
	if ((pos.x < screensize.x || pos.x  > screensize.z) || \
		(pos.y < screensize.y || pos.y  > screensize.w)) \n \
	discard; \n \
\
	vec2 tex = texture(sampler, texCoord0).rg;\
\
	vec3 color = (colour.rgb * tex.r) + (colour.rgb * tex.g);\
\
	tex.r = clamp(tex.r * 1.2, 0.0, 1.0);\
\
	float mainAlpha = tex.r * colour.a;\
	float outlineAlpha = tex.g * colour.a;\
\
	if(mainAlpha + outlineAlpha < 0.1) discard; \
	outColor = vec4(color, mainAlpha + outlineAlpha); \
}"
#endif /* SWIFT_SHADER_SOURCE_H */
