2024-09-19 21:33:32 +01:00
|
|
|
#version 330 core
|
|
|
|
|
|
|
|
|
|
uniform sampler2D diffuseMap;
|
|
|
|
|
uniform vec2 textureTiling;
|
|
|
|
|
|
|
|
|
|
in vec2 fragTexCoord;
|
2025-04-14 20:29:41 +01:00
|
|
|
in vec3 fragNormal;
|
|
|
|
|
in vec2 fragTileTexCoord;
|
2025-07-03 14:11:35 +01:00
|
|
|
|
|
|
|
|
flat in uvec4 occlusionSides;
|
|
|
|
|
flat in int topLeftObscured;
|
|
|
|
|
flat in int topRightObscured;
|
|
|
|
|
flat in int bottomLeftObscured;
|
|
|
|
|
flat in int bottomRightObscured;
|
2024-12-23 18:45:07 +00:00
|
|
|
flat in int quadHeight;
|
|
|
|
|
flat in int quadWidth;
|
2024-09-19 21:33:32 +01:00
|
|
|
|
|
|
|
|
out vec4 outColor;
|
|
|
|
|
|
2025-04-14 20:29:41 +01:00
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-19 21:33:32 +01:00
|
|
|
void main()
|
|
|
|
|
{
|
2025-04-14 20:29:41 +01:00
|
|
|
vec2 texCoord = (floor(fragTexCoord*textureTiling) + fract(fragTileTexCoord)) / textureTiling;
|
2024-09-19 21:33:32 +01:00
|
|
|
outColor = texture(diffuseMap, texCoord);
|
2024-12-23 18:45:07 +00:00
|
|
|
|
2025-04-14 20:29:41 +01:00
|
|
|
ivec2 floorFragTileTexCoord = ivec2(fragTileTexCoord);
|
|
|
|
|
|
2025-07-03 16:44:17 +01:00
|
|
|
if(floorFragTileTexCoord.x < 1 && ((occlusionSides.x >> floorFragTileTexCoord.x) & uint(1)) == uint(1)) {
|
2025-07-03 14:11:35 +01:00
|
|
|
outColor *= 0.5 + fakeArcsin(fragTileTexCoord.x);
|
|
|
|
|
}
|
2024-12-23 18:45:07 +00:00
|
|
|
|
|
|
|
|
outColor.a = 1;
|
2025-07-03 14:11:35 +01:00
|
|
|
|
|
|
|
|
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);
|
2024-09-19 21:33:32 +01:00
|
|
|
}
|