4 ms·
If you add a `uniform vec3 mousePrevFrame` that tracks the previous mouse position, you can get smoother drawing in main() by replacing your distance function i
by heyitsguay 6y ago
If you add a `uniform vec3 mousePrevFrame` that tracks the previous mouse position, you can get smoother drawing in main() by replacing your distance function in the line `float dist = distance(mouse.xy, gl_FragCoord.xy)` with a custom
distanceToLine(mousePrevFrame.xy, mouse.xy, gl_FragCoord.xy)
defined as
float distanceToLine(vec2 p1, vec2 p2, vec2 p0) {
float d12 = distance(p1, p2);
if (d12 == 0) {
return distance(p1, p0);
}
return abs((p2.y - p1.y) * p0.x - (p2.x - p1.x) * p0.y + p2.x * p1.y - p2.y * p1.x) / d12;
}