HackerTrans
TopNewTrendsCommentsPastAskShowJobs

mindbrix

no profile record

Submissions

Rasterizer: A GPU-accelerated 2D vector graphics engine in ~4k LOC

github.com
169 points·by mindbrix·11 bulan yang lalu·56 comments

comments

mindbrix
·10 bulan yang lalu·discuss
Ruffle is cool. From pixel inspecting the demo, it looks like they are using triangle fans with stencil & cover + MSAA, which was how I started!
mindbrix
·10 bulan yang lalu·discuss
The depth buffer is used for opaque path interiors.
mindbrix
·10 bulan yang lalu·discuss
My original target was iOS, so this was unavailable. I did experiment with their algorithm, but 4x MSAA was slow and had poor quality compared to Core Graphics, which was my reference.
mindbrix
·10 bulan yang lalu·discuss
My email address is in every file ;-)
mindbrix
·10 bulan yang lalu·discuss
Drawing cached renders in quads is how Core Animation works, but they do not scale well. You are ultimately limited by the CPU. Rasterizer enables a fully-animated canvas @ 60fps.
mindbrix
·10 bulan yang lalu·discuss
The longer answer is that using straight-edged geometry to represent curves is a resolution-dependent operation, e.g. a full screen circle may need to be flattened to an 80-sided polygon.

Rasterizer can solve quadratic curves in the fragment shaders, which massively reduces the geometry needed for a scene.

Also, the native rasterizer only supports MSAA, which is inferior to reference analytic area AA.
mindbrix
·10 bulan yang lalu·discuss
Good question and answer ;-)
mindbrix
·10 bulan yang lalu·discuss
My reference renderer has been Core Graphics. If it looks like CG I assume it's OK - and if it's not OK I'm in good company ;-)

You can switch between CG and Rasterizer in the demo app using the 0 key to see the difference for yourself.
mindbrix
·10 bulan yang lalu·discuss
Thanks, you imagine correctly ;-)

The current version uses Metal. I haven't even considered GPU ports yet, as my methodology is to get it working well on one platform first.

For single-pass SVG --> texture, a CPU approach would probably offer the lowest latency. For repeat passes, the GPU would probably win.
mindbrix
·10 bulan yang lalu·discuss
Thanks. I couldn't really say without doing proper research.
mindbrix
·10 bulan yang lalu·discuss
Rasterizer excels at animation and complex scenes, e.g. 2D CAD documents. The original inspiration was Flash, as I love innovative design tools. Flash 1.0 could easily be used by designers, but ultimately lost its way became a coder's toy after the Adobe acquisition and ActionScript 2.0.

Fleshing out the spec is planned, but I cannot provide a timeline as this has all been done at my own considerable expense. Maybe if my tips grow: https://paypal.me/mindbrix
mindbrix
·10 bulan yang lalu·discuss
The Rasterizer algorithm handles self-intersecting paths without issue. Removing them requires expensive and complex computation geometry.
mindbrix
·10 bulan yang lalu·discuss
I can't really answer that in detail yet. I suspect Rasterizer will be faster for complex scenes.
mindbrix
·10 bulan yang lalu·discuss
No magic, just 10+ years of experimentation and optimisation.
mindbrix
·10 bulan yang lalu·discuss
Linear at present.
mindbrix
·10 bulan yang lalu·discuss
The "traditional graphics pipeline" approach was chosen to maximise the platforms Rasterizer could run on, as GPU compute support at the time was patchy. Compute is now more universal, so Rasterizer could move that way.

SDFs are expensive to calculate, and have too many limitations to be practical for a general-purpose vector engine.
mindbrix
·10 bulan yang lalu·discuss
Winding numbers are easy to explain, but hard to compute efficiently: https://en.wikipedia.org/wiki/Winding_number
mindbrix
·10 bulan yang lalu·discuss
The core problem is path winding: https://en.wikipedia.org/wiki/Winding_number

Paths can be any size, and the problem is hard to parallelize. GPUs like stuff broken into small regular chunks.

TestFiles/Manchester_Union_Democrat_office_1877.svg is composed of a single huge path, which was a great torture test.
mindbrix
·10 bulan yang lalu·discuss
Slug is primarily designed for text rendering.

Vello is general purpose, like Rasterizer, but is based on GPU compute. Rasterizer uses the 'traditional' GPU pipeline. Performance numbers for both look very competitive, although Vello seems to have issues with GPU lock up at certain zoom scales. Rasterizer has been heavily tested with huge scenes at any scale.
mindbrix
·10 bulan yang lalu·discuss
No. I'm hoping someone else will do that ;-)