News for hackers. Stuff that matters.
Re:WebGPU Fundamentals by dist-epoch on Saturday April 15, 2023 @09:22AM (#35580410)
> Do I vectorize it and draw millions of tiny triangles to approximate those vectors

That is becoming feasible, using something called mesh shaders. The millions of tiny triangles will only be created on the fly inside the GPU, you will just send the vector geometry.

Re:WebGPU Fundamentals by raphlinus on Saturday April 15, 2023 @09:31AM (#35580485)
This is true, but there is a lot more to the story. For one, WebGPU does not (yet) support mesh shaders, though it may later as an extension. For two, consider a glyph such as "o" that has two contours. Real triangulation generates a mesh that only generates triangles between the outer and inner contours, and mesh shaders aren't good at that. There are techniques compatible with mesh shaders (cover and stencil) that draw twice, incrementing and decrementing a winding number stored in the stencil buffer (see contrast renderer[1] for a clean modern implementation), but it does require nontrivial tracking on the CPU side, and can result in lots of draw calls to switch between the cover and stencil stages unless sophisticated batching is done. (The outer contour is drawn as a disc with winding number +1, and the inner contour is drawn as a smaller disc with winding number -1, so the inner part ends up as 0)

Compute shaders avoid all these problems and work on WebGPU 1.0 today.

[1]: https://github.com/Lichtso/contrast_renderer

Re:WebGPU Fundamentals by dist-epoch on Saturday April 15, 2023 @09:34AM (#35580507)
> Real triangulation generates a mesh that only generates triangles between the outer and inner contours, and mesh shaders aren't good at that.

I'm a bit confused. Can't you send the shape of O as a low res rough band (a closed wide loop) and enhance it in the mesh shader? This is how previous generation tessellation shaders and sub-division surfaces worked.

Re:WebGPU Fundamentals by raphlinus on Saturday April 15, 2023 @10:12AM (#35580783)
You might be able to do something along those lines, but I know of no font / vector 2D renderer that does so. There is a lot of literature[1] on this, so I suspect if doing things similar to subdivision surfaces were viable for font rendering, it would have been explored by now.

[1]: https://2d.graphics/book/gpu_rendering.html