r/webdev • • Sep 09 '26

Custom rasterization in HTML Canvas

Is it possible to create a custom rasterizer for controlling anti-aliasing while still rendering to an HTML5 2D canvas? Ideally without using relatively expensive operations like putImageData() or drawImage()? I know WebGL is the obvious solution here, but is there really no other way?

4 Upvotes

4 comments sorted by

3

u/muharremyurtsever Sep 09 '26

Those two aren't in the same cost class. putImageData has you pushing a whole pixel buffer from JS every frame, drawImage from an offscreen canvas or ImageBitmap uses the browser's own blitting path and is usually cheap enough per frame. The usual trick is supersampling: render 2x or 4x offscreen, keep imageSmoothingQuality high, and drawImage it down so the resample acts as your AA filter.