67 lines
1.3 KiB
GLSL

#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) in vec2 position;
layout(binding = 0) uniform Camera {
mat4 viewProjection;
} camera;
layout(push_constant) uniform Model {
mat4 model;
} model;
struct Province {
uint regionId;
uint color;
};
layout(std430, binding = 1) readonly buffer Data {
Province provinces[];
};
layout(location = 0) out vec3 fragColor;
const float PI = 3.141592653589793;
vec3 unpackColor(uint c) {
return vec3(
c & 0xFFu,
(c >> 8) & 0xFFu,
(c >> 16) & 0xFFu
) / 255.0;
}
vec2 toUV(vec2 pos)
{
vec2 uv = pos / vec2(5632.0, 2048.0);
uv.y = 1.0 - uv.y;
return uv; //TODO: Provide map size
}
vec3 mercatorToSphere(vec2 uv)
{
float lon = uv.x * 2.0 * PI - PI;
lon += PI;
float lat = PI * 0.5 - uv.y * PI;
float cosLat = cos(lat);
return vec3(
cosLat * cos(lon),
sin(lat),
cosLat * sin(lon)
);
}
void main() {
vec2 uv = toUV(position);
vec3 spherePos = mercatorToSphere(uv);
gl_Position = camera.viewProjection
* vec4(spherePos, 1.0);
//gl_Position = camera.viewProjection * vec4(position, 0.0, 1.0);
//fragColor = unpackColor(provinces[gl_InstanceIndex].color);
fragColor = unpackColor(provinces[gl_InstanceIndex].regionId);
}