merovi-labs / svgtexture2d

Godot 4.2 Plugin for Realtime SVG Sprites. Adds support for the SVG Extensions File Format.
Apache License 2.0
36 stars 5 forks source link

Allow re-rasterization from Rotation change #8

Open Reuzi3 opened 1 month ago

Reuzi3 commented 1 month ago

Suggestion to enable direct SVG rotation and then rasterization: It could be an option in the inspector to rotate the element of the SVG directly so that it is rasterized with the applied rotation. or Alternatively it could detect the rotation of the SVGSprite2D and then rasterize it with the rotation applied. This would make it possible to turn off the "linear" filter, which currently applies blur to rotated sprites. Using "nearest" (no filter) results in a pixelated rotated texture.

image

My current implementation does this by creating a group for the SVG and ensuring that the group is at the highest hierarchy to include even the SVG's viewport box in the rotation, and then rotating the SVG and rasterizing with the new rotation. I believe my code and implementation might not be the most polished for the plugin. But it works for analysis:

https://github.com/user-attachments/assets/ce1f14ae-ecf4-4f2a-aa62-22d8b91d1d89

raygoe commented 1 month ago

This seems reasonable.

I think your implementation is probably what I'd do too. I'll probably use the XMLParser to place the element after the element and then give the user the option of setting a rotation w/ a default (0.5, 0.5) offset that can be changed if the user doesn't want to rotate on the center.

Obviously for real-time rotations, I think performance would become an issue with complex SVG images. For instance, caching the output bitmap on RGBA8 for 360 degrees on a 512x512 image would be something like 370 MiB for just that image. However, I can still implement it without caching assuming the end user would only want to use it to rotate elements this way non-realtime.

I expect most users would probably just enable bilinear filtering and accept the slight blurriness on the rotation if they wanted realtime rotations (that or supersample the image with resolution > 1.0).