1// Copyright (c) 2015 Sergio Gonzalez. All rights reserved. 2// License: https://github.com/serge-rgb/milton#license 3 4in vec3 v_pointa; 5in vec3 v_pointb; 6 7uniform sampler2D u_canvas; 8 9void 10main() 11{ 12 vec2 screen_point = vec2(gl_FragCoord.x, u_screen_size.y - gl_FragCoord.y); 13 14 vec2 canvas_point = raster_to_canvas_gl(screen_point); 15 vec2 a = v_pointa.xy; 16 vec2 b = v_pointb.xy; 17 18 vec2 ab = b - a; 19 float len_ab = length(ab); 20 21 float t = clamp(dot((canvas_point - a)/len_ab, ab / len_ab), 0.0, 1.0); 22 23 vec2 stroke_point = mix(a, b, t); 24 25 float pressure = mix(v_pointa.z, v_pointb.z, t); 26 27 // Distance between fragment and stroke 28 float dist = distance(stroke_point, canvas_point) - u_radius*pressure; 29 30 if ( dist < 0 ) { 31 vec2 coord = gl_FragCoord.xy / u_screen_size; 32 vec4 eraser_color = texture(u_canvas, coord); 33 out_color = eraser_color; 34 } else { 35 discard; 36 } 37}//END 38