#version 330 core

uniform sampler2D diffuseMap;
uniform vec2 textureTiling;

in vec2 fragTexCoord;
in vec2 fragTexCoord2;
in vec4 fragColor;
flat in int ambientOcclusionSide1;
flat in int ambientOcclusionSide2;
flat in int ambientOcclusionCorner1;
flat in int ambientOcclusionCorner2;
flat in int ambientOcclusionCorner3;
flat in int quadHeight;
flat in int quadWidth;

out vec4 outColor;

void main()
{
    vec2 texCoord = (floor(fragTexCoord*textureTiling) + fract(fragTexCoord2)) / textureTiling;
    outColor = texture(diffuseMap, texCoord);

    ivec2 floorFragTexCoord2 = ivec2(fragTexCoord2);
    if     ((fragTexCoord2.x < 0.05 || fragTexCoord2.x >  quadWidth-0.05) && (((ambientOcclusionSide1 >> floorFragTexCoord2.y) & 1) == 1)) outColor *= 0.5;
    else if((fragTexCoord2.y < 0.05 || fragTexCoord2.y > quadHeight-0.05) && (((ambientOcclusionSide2 >> floorFragTexCoord2.y) & 1) == 1)) outColor *= 0.5;

    outColor.a = 1;
}
