samizdatco / skia-canvas

A GPU-accelerated 2D graphics environment for Node.js
MIT License
1.73k stars 69 forks source link

Fixed scaling issues with shadow blur when applied to a canvas transformed with rotation and/or skew matrices. #174

Closed mpaperno closed 1 month ago

mpaperno commented 1 month ago

To illustrate the issue...

tx-shadow-issue

Scaling the shadow blur worked fine until there were other elements, besides scale, in the canvas' transform matrix, like rotation. In the first example there's no actual scaling even applied to the canvas, only rotation (and translation, but that doesn't affect the matrix scale terms).

Luckily SkMatrix already had a way to get just the scaling value out of it, so I didn't even have to do any math... :)

After fix: tx-shadow-fix

Added more visual tests. Probably should do an auto test as well, just need to sample some relevant part of the result I suppose (I think I saw a similar test in there already somewhere).

Breaking out the render_shadow() helper at the top was just because I couldn't help myself... there are no actual differences in there. All the meat is at the bottom of context/mod.rs.

Thanks, -Max

Related to: #172