diff --git a/src/shaders/sprite.frag b/src/shaders/sprite.frag index ec78365..a98a39e 100644 --- a/src/shaders/sprite.frag +++ b/src/shaders/sprite.frag @@ -234,7 +234,8 @@ void main() // Avoid division by zero float baDot = dot(ba, ba); - baDot = (abs(baDot) < epsilon) ? epsilon : baDot; + // the dot product of a vector and itself is always positive + baDot = max(baDot, epsilon); // Magnitude of vector projection of this fragment onto the line (both relative to the line's start point). // This results in a "linear gradient" which goes from 0.0 at the start point to 1.0 at the end point. diff --git a/src/shaders/sprite.vert b/src/shaders/sprite.vert index 646acaf..b7b1615 100644 --- a/src/shaders/sprite.vert +++ b/src/shaders/sprite.vert @@ -42,7 +42,10 @@ void main() { // Rotate quad to line angle vec2 pointDiff = u_penPoints.zw - u_penPoints.xy; // Ensure line has a nonzero length so it's rendered properly + // As long as either component is nonzero, the line length will be nonzero pointDiff.x = abs(pointDiff.x) < epsilon ? epsilon : pointDiff.x; + // The `normalized` vector holds rotational values equivalent to sine/cosine + // We're applying the standard rotation matrix formula to the position to rotate the quad to the line angle vec2 normalized = pointDiff / max(lineLength, epsilon); position = mat2(normalized.x, normalized.y, -normalized.y, normalized.x) * position; // Translate quad