#version 330 core uniform sampler2D diffuseMap; uniform vec2 textureTiling; in vec2 fragTexCoord; in vec3 fragNormal; in vec2 fragTileTexCoord; flat in uvec4 occlusionSides; flat in int topLeftObscured; flat in int topRightObscured; flat in int bottomLeftObscured; flat in int bottomRightObscured; flat in int quadHeight; flat in int quadWidth; out vec4 outColor; // this is a shitty approximation of arcsin(x)/pi that gets the tails right and is reasonably close to the actual arcsin(x)/pi curve. float fakeArcsin(float x) { x = clamp(x, -1.0, 1.0); float ax = abs(x); float sqrtPart = sqrt(1.0 - ax); float result = 0.5 - sqrtPart * (0.5 - 0.06667 * ax); return x < 0.0 ? -result : result; } void main() { vec2 texCoord = (floor(fragTexCoord*textureTiling) + fract(fragTileTexCoord)) / textureTiling; outColor = texture(diffuseMap, texCoord); ivec2 floorFragTileTexCoord = ivec2(fragTileTexCoord); if(floorFragTileTexCoord.x < 1 && ((occlusionSides.x >> floorFragTileTexCoord.x) & uint(1)) == uint(1)) { outColor *= 0.5 + fakeArcsin(fragTileTexCoord.x); } outColor.a = 1; uint bit = uint(fragTileTexCoord * 32); outColor.g = (((occlusionSides.x >> bit) & uint(1)) == uint(1)) ? ((bit % uint(2) == uint(0)) ? 1.0 : 0.8): ((bit % uint(2) == uint(0)) ? 0.0 : 0.2); }