Support for svg vector graphics
I came across this command line tool https://github.com/Mazatech/amanithsvg-sdk/tree/master/examples/svg2bitmap, and it seems to be able to generate texture atlas (sprites) by rendering SVG elements and pack them. It's the first time I've seen something like this, i.e. the generation of packed sprites, at runtime, starting from one or more SVG files. Has such an option ever been investigated for Godot?
Godot has had some SVG support for a few years. It uses the ThorVG library in 4.0 (and NanoSVG previously) to render SVG as a bitmap on demand at whatever resolution is needed. They don't guarantee it'll work for every SVG file but if you're making your own SVG icons or sprites and they look right in Godot, great.
What Godot CAN'T do, but browser javascript and some obscure game engines can, is change the color, line thickness, visibility, etc, of individual layers or shapes within an SVG graphic.
- Edited
Game engines rely on hardware acceleration, and modern day GPU architectures are built to deal with either bitmaps or triangles. Anything else must be converted into one of those before it can be used by the hardware. That's the price of insane processing speeds we get out of them.
So any type of "native" support for something like realtime SVG rasterization is out of the question for purely technical reasons.
xyz Yep. I still think there's potential in importing the SVG's into 2D meshes a-la blenders grease pencil(which is 3D but gives an idea of what I mean). So that would be cool to see.
xyz So any type of "native" support for something like realtime SVG rasterization is out of the question for purely technical reasons.
No, it's been done, using triangles like 3D and a neat trick with the stencil buffer. It's just little-used because everyone makes 3D and bitmap-2D games. Web browsers have been using a similar acceleration technique for about 10 years though.
synthnostate No, it's been done
I'd like to see it. Note that what I meant by "native realtime rasterization" would include adaptive triangulation of beziers on the gpu.
xyz Note that what I meant by "native realtime rasterization" would include adaptive triangulation of beziers on the gpu.
Which would still just leave an approximation of the limit surface. But since the output is itself limited it would suffice.
Megalomaniak I must admit that I don't see a way to do this via gpu's vertex/pixel pipeline in an efficient manner.
xyz That's the key thing: "in an efficient manner".
Using vector art as a texture could be done with a shader without too much trouble, but it won't be as efficient. I've done basic ones like pass line segment data to a pixel shader that then renders roads (with lanes) and train lines onto the surface using signed distance fields, but it was fairly simplistic. A full on SVG implementation would be pretty heavy on the gpu.
https://shadertoy.com has examples of SVG rendering with pixel shaders, but so far all of the examples I've looked at require the SVG to be rewritten into GLSL (not surprising, shadertoy doesn't allow custom data from outside of the shader itself) and don't cover the full feature set.
xyz I don't know about a complete and totally efficient SVG implementation. What I remember was good enough for realtime SVG filled-polygon rendering with some GPU acceleration. Curves were rendered as segmented polygons. It was useful if you wanted to make an approximation of a true vector graphics game (a pretty accurate approximation with modern high resolution monitors) using art drawn in Illustrator, Inkscape, etc.
Now I remember the real reason hardly anyone uses it: except for primitive arcade-style games, 2D vector graphics look terrible, like "CalArts" "art".
- Edited
I do use Inkscape for importing my hand-drawn art as pngs (I scan in black and white drawings as png, convert to vector, then back to png), It's advantageous in this regard because you can resize svgs to a proper size for export without distortion. I don't see the advantage of having a third axis in 3d though. I will say this - I love making UI elements in Inkscape then exporting to PNG because the export quality is high and allows for better clarity when resizing.
If your SVG is mono-colored and not overlapping itself, consider converting your library of svg's into a single font file and import that into Godot as a "Multichanneled Sigend Distance Field" (SDF) by enabling the checkbox during font import. Then assign the font on a Label node. Especially useful for UI icons of course.
This allows for crisp resolution, custom colors and shadows.