Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Godot create an extra vertex? #49322

Open
Torguen opened this issue Jun 4, 2021 · 11 comments
Open

Godot create an extra vertex? #49322

Torguen opened this issue Jun 4, 2021 · 11 comments

Comments

@Torguen
Copy link

Torguen commented Jun 4, 2021

Godot version:

3.3.2 stable mono

OS/device including version:

win10

Issue description:

When I convert a sprite to polygon2D godot creates 5 vertices: 0-1-2-3-4
I think it should create 4 vertices.

gif gif

Steps to reproduce:
Convert a sprite to polygon2d with the default values.

Minimal reproduction project:

@clayjohn
Copy link
Member

clayjohn commented Jun 4, 2021

When you convert a Sprite to a Polygon2D Godot tries to fit the Polygon2D around the opaque parts of the image. Because the corners of the sprite are transparent, the resulting polygon is not simply a quad with 4 corners.

You can see this very clearly in the docs for converting a sprite into a mesh

@Torguen
Copy link
Author

Torguen commented Jun 5, 2021

When you convert a Sprite to a Polygon2D Godot tries to fit the Polygon2D around the opaque parts of the image. Because the corners of the sprite are transparent, the resulting polygon is not simply a quad with 4 corners.

You can see this very clearly in the docs for converting a sprite into a mesh

Ok, now I understand the transparency and leaving that aside I can see the following:
I saw a youtube video and now I was able to get a polygon of 4 vertices correctly but the deformation is not symmetric.
Notice the texture - shouldn't it be the same on both sides?
Captura

@Torguen
Copy link
Author

Torguen commented Jun 5, 2021

gif gif

@Zylann
Copy link
Contributor

Zylann commented Jun 5, 2021

This is a common issue with triangles and interpolation (graphics cards work with triangles). The only way to workaround this is to use a shader that performs quadrilateral interpolation instead https://www.reedbeta.com/blog/quadrilateral-interpolation-part-1/

@Torguen
Copy link
Author

Torguen commented Jun 5, 2021

So there is no way to get this (krita) in godot?
without using that shader.
gif gif

@Zireael07
Copy link
Contributor

Make a square polygon instead of using convert sprite to polygon?

@Torguen
Copy link
Author

Torguen commented Jun 5, 2021

Make a square polygon instead of using convert sprite to polygon?

It does not work, they have the same behavior as the previous case.

This is the image in case anyone wants to try
sprite

@clayjohn
Copy link
Member

clayjohn commented Jun 5, 2021

The only way to workaround this is to use a shader that performs quadrilateral interpolation instead https://www.reedbeta.com/blog/quadrilateral-interpolation-part-1/

The other way to work around it is to subdivide the mesh to use more internal vertices. If your mesh looks like a grid with 4 squares it will also interpolate correctly (for this texture, more detailed textures may need more subdivisions)

@Torguen
Copy link
Author

Torguen commented Jun 5, 2021

Why isn't there a node to 2D (or some kind of polygon) that does the same thing krita does in the gif?
Krita uses four points or vertices and you get the result that (I think) most are looking for when using this.

@Zylann
Copy link
Contributor

Zylann commented Jun 5, 2021

So there is no way to get this (krita) in godot?

There is, what I told you, it's just not the default in realtime rendering.
You can also subdivide it, which doesnt eliminate the issue but makes it way less noticeable, at the cost of polycount.

@Torguen
Copy link
Author

Torguen commented Jun 5, 2021

But I don't know how to create that shader, and I will also have to add the shader to all the nodes that need it, I mean you say there is "there is" but there isn't if you don't create the shader you indicated before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants