50 lines
1.3 KiB
GLSL
50 lines
1.3 KiB
GLSL
#version 330
|
|
|
|
in vec2 fragTexCoord;
|
|
in vec4 fragColor;
|
|
|
|
uniform vec2 resolution;
|
|
uniform vec2 mouse_pos;
|
|
uniform float ball_radius;
|
|
uniform vec2 polygon_points[6];
|
|
uniform float polygon_influence;
|
|
|
|
out vec4 finalColor;
|
|
|
|
float distanceToPolygon(vec2 point, vec2 polyPoints[6]) {
|
|
float minDist = 100000.0;
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
int j = (i + 1) % 6;
|
|
vec2 a = polyPoints[i];
|
|
vec2 b = polyPoints[j];
|
|
|
|
vec2 pa = point - a;
|
|
vec2 ba = b - a;
|
|
float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);
|
|
float dist = length(pa - ba * h);
|
|
minDist = min(minDist, dist);
|
|
}
|
|
|
|
return minDist;
|
|
}
|
|
|
|
void main()
|
|
{
|
|
vec2 pixel_pos = fragTexCoord * resolution;
|
|
|
|
vec2 ball_pixel_pos = mouse_pos;
|
|
float ball_dist = distance(pixel_pos, ball_pixel_pos);
|
|
float ball_value = (ball_radius * ball_radius) / (ball_dist * ball_dist + 1.0);
|
|
|
|
float poly_dist = distanceToPolygon(pixel_pos, polygon_points);
|
|
float poly_value = polygon_influence / (poly_dist * poly_dist + 1.0);
|
|
|
|
float total_value = ball_value + poly_value;
|
|
|
|
if (total_value > 0.7) {
|
|
finalColor = vec4(1.0, 1.0, 1.0, 1.0); // White
|
|
} else {
|
|
finalColor = vec4(0.0, 0.0, 0.0, 1.0); // Black
|
|
}
|
|
} |