Files
skygqts/workspace-manager/shaders/globecard.vert
T
2026-10-27 13:30:14 -04:00

47 lines
1.5 KiB
GLSL

#version 440
// Bends a flat workspace card onto the globe. Each point of the card's grid
// is moved from the card's middle along the sphere, then drawn with the same
// simple perspective as the rest of the globe. The item is centered on the
// middle of the globe.
layout(location = 0) in vec4 qt_Vertex;
layout(location = 1) in vec2 qt_MultiTexCoord0;
layout(location = 0) out vec2 qt_TexCoord0;
layout(std140, binding = 0) uniform buf {
mat4 qt_Matrix;
float qt_Opacity;
// Size of the card picture, glow margin included.
vec2 meshSize;
float sphereRadius;
float focalLength;
// Where the card's middle sits on the globe, in radians.
float lat;
float lon;
};
out gl_PerVertex {
vec4 gl_Position;
};
void main()
{
qt_TexCoord0 = qt_MultiTexCoord0;
// Distance of this point from the card's middle, in pixels.
vec2 local = qt_Vertex.xy - meshSize * 0.5;
// Walk that far over the sphere. Sideways steps are measured along the
// card's own line of latitude, which gets shorter toward the poles.
float pointLat = lat + local.y / sphereRadius;
float pointLon = lon + local.x / (sphereRadius * max(cos(lat), 0.2));
float c = cos(pointLat);
float depth = sphereRadius * (1.0 - c * cos(pointLon));
float s = focalLength / (focalLength + depth);
vec2 projected = vec2(sphereRadius * c * sin(pointLon), sphereRadius * sin(pointLat)) * s;
gl_Position = qt_Matrix * vec4(projected + meshSize * 0.5, 0.0, 1.0);
}