Giwayume / godot-svg

SVG Rendering Plugin for Godot
MIT License
73 stars 3 forks source link

Any plan to port this to godot 4? #3

Closed Tigriz closed 2 weeks ago

Tigriz commented 1 year ago

I tried to manually fix some of the things by using the "migration" tool offered by godot and replacing manually some of the things that changed, to no avail.

Giwayume commented 1 year ago

I had plans to do that when I had most of the functionality complete in 3.5, so there wasn't dual maintenance. But life has had other plans, as you can see I haven't had a chance to focus on this library for a few months now.

https://github.com/godotengine/godot-proposals/issues/3422

There is this proposal in Godot 4 to be able to load SVG assets at whatever resolution you like to a texture on the fly. That would be a smart way to solve the variable scalability problem in-engine, as most use cases for SVG are just people wanting to adapt the their art assets to the resolution of the currently used device. But that also appears to have not been coded yet.

I can look at porting and see if it is significantly difficult, since it doesn't appear at the moment I will be able to achieve my original goal of having a feature complete package any time soon.

Giwayume commented 1 year ago

Believe it or not, Godot 4 is more restrictive than Godot 3 in the 2D shader department. I am unable to port at this time because they forced vertex colors to be compressed to 8 bits.

Giwayume commented 1 year ago

I put a PR into Godot to support custom vertex shader attributes for canvas items. Maybe it will be merged by Godot 4.1 so this plugin can work then.

SimplyBLGDev commented 1 year ago

I think this plugin would still be pretty useful even with Godot's own realtime svg to png rendering, having a shader do the work instead of a one time conversion could allow for dynamic modification and even animation of the paths in realtime, making for a true fully fledged vector engine, fantastic project

Reuzi3 commented 1 year ago

I think this plugin would still be pretty useful even with Godot's own realtime svg to png rendering, having a shader do the work instead of a one time conversion could allow for dynamic modification and even animation of the paths in realtime, making for a true fully fledged vector engine, fantastic project

I thought about this. When I have time I will try something like this. The Svg scale method doesn't work at runtime... but it's not hard to do. And by still keeping it in raster it really makes it very light and the end result is amazing.

Giwayume commented 1 year ago

@SimplyBLGDev @ky000

You may be more interested in this: https://github.com/godotengine/godot/pull/75278

It is a PR to implement a draw_filled_curve command (CanvasItem/2D context only) that draws a vector shape by passing the entire shape definition to the GPU and calculating it in the shader.

My plugin uses a hybrid of creating meshes + extremely simple linear algebra in shader that should be much more performant, but it takes time to construct the shape on the CPU probably making it worse for animating paths.

IceflowRE commented 1 year ago

You might be interested in https://github.com/merovi-labs/svgtexture2d

Giwayume commented 1 year ago

You might be interested in https://github.com/merovi-labs/svgtexture2d

This basically makes it easier convert SVGs to the fixed resolution you want them in at runtime, instead of the out of the box method of you needing to specify when you import it. It's what most people should use to have an efficient game, but not what all the people who have been asking for a "vector based engine" want.

@IceflowRE I suggest to make this more practically useful, allow specifying the scale as a percentage of the screen resolution. (width, height, or max[width,height]). Most people who want to use vector graphics are trying to make their assets work at any scale, without having to worry about configuring it.

Also, allowing to set a fixed width/height the image will scale to makes it easier to use. As opposed to adjusting the SVG scale causing the image to increase/decrease in size. e.g. treat "scale" as "detail level" instead of a size adjustment.

Giwayume commented 11 months ago

I implemented something similar to your idea, but I noticed that even when doing this, depending on the project settings in Stretch, the viewport still seems to slightly distort the SVG, making the quality not as good as it should be 😥

It's all working with textures at that point, so yeah whatever texture filtering / mip-mapping algorithms have the same quirks. Personally I'd like to see SlugFilter's code integrated into the engine for rendering, so all the addons have to do is SVG parsing.

Giwayume commented 3 months ago

I was able to get proper custom shader vertex attributes merged and targeted for Godot 4.3. https://github.com/godotengine/godot/pull/86564

This opens a pathway for this plugin to work in Godot 4. I did some testing in a 4.3 branch and it seems there's quite a few things that broke in the porting process from Godot 3.5 to 4.3. Some very basic SVG files are working.

I'll see if I can get it in a decent working state, but I'm not all mentally gung ho about this project right now.

Giwayume commented 2 weeks ago

4.3 has the necessary support for rendering. You can try the 4.3 branch. It generally works the same, but I have noticed there are a few places where it's broken compared to the 3.5 version.

https://github.com/Giwayume/godot-svg/tree/4.3

I've been having the most difficulty this whole time with path intersection solving, but I'm focused on other projects at the moment. Try disabling path solving if an SVG doesn't render. Especially if your SVG doesn't use itersecting paths.

I'll close this issue since the general problem of "get it to work in godot 4" is solved.