Skip to content

Instantly share code, notes, and snippets.

@omorgan7
Last active April 20, 2019 23:16
Show Gist options
  • Save omorgan7/e9e1e9bd0f6bb11fef9a59f2f46b1941 to your computer and use it in GitHub Desktop.
Save omorgan7/e9e1e9bd0f6bb11fef9a59f2f46b1941 to your computer and use it in GitHub Desktop.
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Normalized pixel coordinates (from 0 to 1)
fragCoord = fragCoord / iResolution.xy;
vec2 start = vec2(0.2, 0.2);
vec2 end = iMouse.xy / iResolution.xy;
vec2 direction = normalize(end - start);
// project each frag coordinate into the direction.
float t = dot(fragCoord - start, direction);
float tEnd = dot(end - start, direction);
float radius = 0.01;
// get the distance from this point:
float d = distance(start + t * direction, fragCoord);
float startDist = distance(fragCoord, start);
float endDist = distance(fragCoord, end);
if ((d > radius || t > tEnd || t < 0.0) && (startDist > radius && endDist > radius))
{
fragColor = vec4(0.5, 0.5, 0.5, 1.0);
}
else
{
fragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment