Giter Site home page Giter Site logo

regl-line2d's Introduction

gl-vis

A modular visualization system for JavaScript.

regl-line2d's People

Contributors

alexcjohnson avatar archmoj avatar bkomboz avatar dependabot[bot] avatar dy avatar fuzhenn avatar jamesscottbrown avatar ruijin avatar seranicio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

regl-line2d's Issues

Mobile miter artifact

image

Something special with adjacent miters happen.
We probably want to disable miters for obtuse angles.

Related to #12

Dash mode

Distance-based dash is more svg-ish but prone to errors on big data, position-based dash is round error proof, but bad on scale.

We can switch that mode by the calculated distance.

Although it seems that we cannot track scale-independent distance.

Losing texture

Too big/small line distances may loose dash texture:
image
Possibly gl_FragCoord approach for texture forming is more promising.

Join type 'rect' missing ab colors

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.

Broken color transition

Now sharp-angle connections render color transition with noticable shift. We have to correct that by miter limit or so.

NaNs round join case

{
    type: 'round',
    positions: [1, -2, 2, -2, 3, NaN, 4, 2, 5, 2],
    width: 20,
    color: 'red'
}

Does not render stuff, unlike rect

Round miters

Modified frag shader presumably tests if fragment is within miter radius, if it exceeds 0 bevel miter limit.

Viewport cutoffs

Mobile version seems to render the same cutoff issue.

line2d error

  • line end is skewed
  • line width consistency is probably wrong (check pixelScale)
  • antialiasing is wrong (as if twice less, check pixelRatio)
  • cutoff is wrong (is it bound to viewport?)
  • skewed joins on shifted viewport - no idea what's the reason

Stencil buffer cutoff?

Now cutoffs use fragment shader strategy, which overcalculates them, esp. for sharp angles or small scales. Engaging stencil buffer would allow to avoid conditions in fragment shader, in theory.

Split sharp angles

For now there are artifacts on too sharp edges where line width gets thinner:
image
We could render that as overlapping separate render passes, since difference between no-miter strategy is insignificant.
Also that potentially creates (sometimes) off-miter artifacts.
image

1.0 TODO

  • precision property
  • duplicated point case
  • demo with randomized line
  • calibrated dash pattern
  • optimize shader code
  • readme and stuff

Feature-complete release

  • Round miters mode with proper normals, antialiasing #5
  • Avoid miterJoin crease for thick lines #15
  • Close path mode #11
  • Distance dash pattern mode #13
  • Rectangular mode with detection #4
  • Demo with updated settings panel
  • Cap mode

Batch rendering

We have to be able to render multiple lines with different colors. There is no such problem for scatter plot, since we can define marker/color/border per-point.

  • we do not really need to support color transitions between points: first it is broken #8, second they break API design of corresponding colors to multiple lines.
  • should we accept array as options [{a}, {b}, {c}] or array as property {x: [a, b, c], y: [a, b, c], z: shared}? We never used array as options before and that is not a pattern [yet], also it does not allow for shared properties or we have to detect them manually.

Unfortunately due to uncertain regl/webgl issue regl-project/regl#432 we can't use offset with instanced draw, hence we have to pick scatter strategy: tracking elements/textures and rendering subset of them.

UPD: Turns out offset/elements in instanced draw affects uninstanced part, which gets repeated, not the instances, ie. line segment lineEnd and lineTop in our case. Therefore we have to rebind attributes or at least their offsets for every polyline instance. And seems that is is not difficult: we can set offset a function. Yay!

Gaps are ignored when in-between flat segments

Consider

let regl = require('regl')({extensions: 'angle_instanced_arrays'})
let line2d = require('./')(regl)

const arr1 = [0, 1, 1, NaN, 2, 1, 3, 2]
const arr2 = [0, 3, 1, NaN, 2, 3, 3, 3]

const rng = [-1, -1, 4, 4]
const vp = [80, 80, 556, 350]

line2d.render({ thickness: 4, points: arr1, color: 'red', viewport: vp, range: rng, join: 'rect', overlay: true })
line2d.render({ thickness: 4, points: arr2, color: 'blue', viewport: vp, range: rng, join: 'rect', overlay: true })

which results in

image

where the gap in the blue trace at the 2nd (x,y) position is missing.


plotly.js example in -> plotly/plotly.js#3551

Rectangular only round join shader

  • faster than miter shader
  • enabled hi-precision
  • no miter clipping artifacts on viewport #23
  • looks good for any colorscales:
    image (compare beginning with end)
  • easier API: no join, no cap, no overlay
  • people usually always opt for round miters as they are nice and natural.

Q: Are there cases when we may want no-overlap joined miter or bevel miter?

A: sharp edges, like
image

Also that is a pattern, to have 3 types of miters.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.