gl-vis / regl-line2d

:part_alternation_mark: Draw 2d polyline with regl
https://gl-vis.github.io/regl-line2d
MIT License
59 stars 15 forks source link

Join type 'rect' missing ab colors #53

Open norbert-gaulia opened 2 years ago

norbert-gaulia commented 2 years ago

When drawing lines with simple shader by using join type rect it's rendering with single color:

{
    color:['red', 'yellow'],
    join:'rect',
    positions: [-0,0,20,10],
    thickness: 10,
    dash: [15, 5]
}

chrome_a4eQCzkobW

Adding aColor, bColor to the rect-vert.glsl will produce correct shading

attribute vec4 aColor, bColor;
...
fragColor = (lineStart * aColor + lineEnd * bColor) / 255.;

also changing regl attributes to

 aColor: {
    buffer: regl.prop('colorBuffer'),
    stride: 4,
    offset: 0,
    divisor: 1
},
bColor: {
    buffer: regl.prop('colorBuffer'),
    stride: 4,
    offset: 4,
    divisor: 1
}

chrome_y5oai14fOa

Thank you.