4 ms·
I wrote an implementation based on this a few weeks back. It works really nicely and I can render some 2M line segments at 60fps. One thing you should do is tr
by mtsr 5y ago
I wrote an implementation based on this a few weeks back. It works really nicely and I can render some 2M line segments at 60fps.
One thing you should do is try to limit very short and small segments, as GPUs don’t like rendering 1px triangles.
Still, I’ve been lead to understand that the instanced rendering done in this article is suboptimal on most GPUs. A better way to do it is apparently to put the points into a (non-vertex) buffer and do (batched) drawcalls for large numbers of vertices with a kind of manual instancing. Basically looking up what amounts to instance data using gl_VertexInput/6 and vertex data using gl_VertexIndex%6 (or 4 instead of 6 for indexes rendering).
Unfortunately I haven’t had the time to implement and test this yet.
If like me you’re also rendering lines with perspective, you want to also look at Freya Holmer's work. Particularly line thinness fading is important to reduce shimmer/aliasing. This means basically keep the width at a minimum of 1px and adjusting opacity below that instead.
Edit: For those interested, mine is implemented as a plugin to the Bevy game engine, written in Rust. Bevy can be found here https://github.com/bevyengine/bevy https://github.com/bevyengine/bevy. The plugin is https://github.com/ForesightMiningSoftwareCorporation/bevy_polyline https://github.com/ForesightMiningSoftwareCorporation/bevy_p....
- TazeTSchnitzel 5y ago> Still, I’ve been lead to understand that the instanced rendering done in this article is suboptimal on most GPUs. A better way to do it is apparently to put the points into a (non-vertex) buffer and do (batched) drawcalls for large numbers of vertices with a kind of manual instancing. Basically looking up what amounts to instance data using gl_VertexInput/6 and vertex data using gl_VertexIndex%6 (or 4 instead of 6 for indexes rendering). Note that you can't do this in WebGL, at least WebGL 1.0. (Also, be careful about assuming things apply to “most” GPUs!)
- mtsr 5y agoI don't mean to be snarky, but WebGL 1.0 is 10 years old as of March. So yeah, if you need to support that there's a lot of extra work you need to do, for all kinds of things.
- TazeTSchnitzel 5y agoWebGL 2 is still not in non-preview Safari, and of course it took a long while for wide support of WebGL 1. Web graphics moves a lot slower than native graphics.