Kelsidavis-WoWee/assets/shaders/minimap_display.frag.glsl
Kelsi 83b576e8d9 Vulcan Nightmare
Experimentally bringing up vulcan support
2026-02-21 22:04:17 -08:00

67 lines
1.7 KiB
GLSL

#version 450
layout(set = 0, binding = 0) uniform sampler2D uComposite;
layout(push_constant) uniform Push {
vec4 rect;
vec2 playerUV;
float rotation;
float arrowRotation;
float zoomRadius;
int squareShape;
} push;
layout(location = 0) in vec2 TexCoord;
layout(location = 0) out vec4 outColor;
float cross2d(vec2 a, vec2 b) {
return a.x * b.y - a.y * b.x;
}
bool pointInTriangle(vec2 p, vec2 a, vec2 b, vec2 c) {
float d1 = cross2d(b - a, p - a);
float d2 = cross2d(c - b, p - b);
float d3 = cross2d(a - c, p - c);
bool hasNeg = (d1 < 0.0) || (d2 < 0.0) || (d3 < 0.0);
bool hasPos = (d1 > 0.0) || (d2 > 0.0) || (d3 > 0.0);
return !(hasNeg && hasPos);
}
void main() {
vec2 center = TexCoord - 0.5;
float dist = length(center);
if (push.squareShape == 0) {
if (dist > 0.5) discard;
}
float cs = cos(push.rotation);
float sn = sin(push.rotation);
vec2 rotated = vec2(center.x * cs - center.y * sn, center.x * sn + center.y * cs);
vec2 mapUV = push.playerUV + rotated * push.zoomRadius * 2.0;
vec4 mapColor = texture(uComposite, mapUV);
// Player arrow
float acs = cos(push.arrowRotation);
float asn = sin(push.arrowRotation);
vec2 ac = center;
vec2 arrowPos = vec2(ac.x * acs - ac.y * asn, ac.x * asn + ac.y * acs);
vec2 tip = vec2(0.0, -0.04);
vec2 left = vec2(-0.02, 0.02);
vec2 right = vec2(0.02, 0.02);
if (pointInTriangle(arrowPos, tip, left, right)) {
mapColor = vec4(1.0, 0.8, 0.0, 1.0);
}
// Dark border ring
float border = smoothstep(0.48, 0.5, dist);
if (push.squareShape == 0) {
mapColor.rgb *= 1.0 - border * 0.7;
}
outColor = mapColor;
}