UNPKG

fabric

Version:

Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.

31 lines (30 loc) 1.04 kB
export const fragmentSource = ` precision highp float; uniform sampler2D uTexture; uniform vec2 uDelta; varying vec2 vTexCoord; const float nSamples = 15.0; vec3 v3offset = vec3(12.9898, 78.233, 151.7182); float random(vec3 scale) { /* use the fragment position for a different seed per-pixel */ return fract(sin(dot(gl_FragCoord.xyz, scale)) * 43758.5453); } void main() { vec4 color = vec4(0.0); float totalC = 0.0; float totalA = 0.0; float offset = random(v3offset); for (float t = -nSamples; t <= nSamples; t++) { float percent = (t + offset - 0.5) / nSamples; vec4 sample = texture2D(uTexture, vTexCoord + uDelta * percent); float weight = 1.0 - abs(percent); float alpha = weight * sample.a; color.rgb += sample.rgb * alpha; color.a += alpha; totalA += weight; totalC += alpha; } gl_FragColor.rgb = color.rgb / totalC; gl_FragColor.a = color.a / totalA; } ` as const;