double-hit-balls/assets/ms_fragment.txt

52 lines
1.1 KiB
Plaintext
Raw Permalink Normal View History

2018-01-14 00:17:27 +00:00
precision mediump float;
varying vec4 color;
varying vec3 position;
2018-04-11 14:16:37 +00:00
//uniform vec4 lineParams;
//uniform vec4 startPointEndPoint;
varying vec3 lineParams;
varying vec4 startPointEndPoint;
2018-01-14 00:17:27 +00:00
void main()
{
float a = lineParams.x;
float b = lineParams.y;
float c = lineParams.z;
2018-04-11 13:40:22 +00:00
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);
}
2018-01-14 00:17:27 +00:00
2018-04-11 13:40:22 +00:00
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);
2018-01-14 00:17:27 +00:00
}