double-hit-balls/assets/ms_fragment.txt
2018-04-11 16:40:22 +03:00

48 lines
1.0 KiB
Plaintext
Executable File

precision mediump float;
varying vec4 color;
varying vec3 position;
uniform vec4 lineParams;
uniform vec4 startPointEndPoint;
void main()
{
float a = lineParams.x;
float b = lineParams.y;
float c = lineParams.z;
float Xa = startPointEndPoint.r;
float Ya = startPointEndPoint.g;
float Xb = startPointEndPoint.b;
float Yb = startPointEndPoint.a;
float distance;
float distanceToA = (Xa - position.x)*(Xb - Xa) + (Ya - position.y)*(Yb - Ya);
float distanceToB = (Xb - position.x)*(Xb - Xa) + (Yb - position.y)*(Yb - Ya);
if (distanceToA * distanceToB > 0)
{
float len = sqrt((Xb - Xa)*(Xb - Xa) + (Yb - Ya)*(Yb - Ya));
distance = max(abs(distanceToA/len), abs(distanceToB/len));
}
else
{
distance = abs(a*position.x + b*position.y + c);
}
float t = clamp(1.2 / (distance + 1.0) - 0.5, 0.0, 1.0);
gl_FragColor = vec4(color.rgb, color.a*t);
//gl_FragColor = vec4(color.rgb*clamp(1.2 / (distance + 1.0) - 0.5, 0.0, 1.0), 1.0);
}