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

Anyone volunteering to make a new UV Unwrapper? #19710

Closed
reduz opened this issue Jun 22, 2018 · 45 comments
Closed

Anyone volunteering to make a new UV Unwrapper? #19710

reduz opened this issue Jun 22, 2018 · 45 comments

Comments

@reduz
Copy link
Member

reduz commented Jun 22, 2018

Godot is currently using Thekla Atlas for unwrapping UVs on mesh import. Unfortunately, this implementation is very slow and quite buggy. We need a replacement, otherwise the current light mapping workflow (which is needed for pretty graphics on low end) will continue to be a hassle.

The only other open source unwrapper is Microsoft's UVAtlas, but it's windows-only so it needs porting. Also, it does not support specifying a texel size, which makes it no so useful.

There are a few papers on implementing this algorithm:

Would anyone be interested in giving a try of implementing one of these algorithms in Godot, make it work with a texel size parameter, and make it as optimal as possible?

@reduz reduz changed the title Anyone volunteering to make a new UV Unwrapper Anyone volunteering to make a new UV Unwrapper? Jun 22, 2018
@AbhimanyuAryan
Copy link

I'll have a week holiday from work. I'll give it a shot. Where can I get any help if needed? Do we have Gitter channel for GodotEngine?

@avril-gh
Copy link
Contributor

avril-gh commented Jun 22, 2018

@AbhimanyuAryan
IRC
chat.freenode.net
#godotengine-devel
#godotengine-doc
#godotengine

@laverneth
Copy link

We can team up, I know the computation of injective maps quite well. I just don't really where to start within godot...

@reduz
Copy link
Member Author

reduz commented Jun 22, 2018

Sorry, should have posted this before. You can check here how thekla atlas is integrated:

https://github.com/godotengine/godot/tree/master/modules/thekla_unwrap

should be pretty much creating another similar module and disabling thekla

@reduz
Copy link
Member Author

reduz commented Jun 22, 2018

and Godot has most of the math types and container types in core:

https://github.com/godotengine/godot/tree/master/core/math

so no need to write your own

@laverneth
Copy link

laverneth commented Jun 22, 2018 via email

@reduz
Copy link
Member Author

reduz commented Jun 22, 2018

yeah, godot only has basic linear algebra types, as sparse matrix/linear solvers are not that common or difficult to make generic. If you want to write your own for this and put it within the unwrapper code, it's fine

@laverneth
Copy link

laverneth commented Jun 22, 2018 via email

@reduz
Copy link
Member Author

reduz commented Jun 22, 2018

@laverneth This is really up to you. If you want to make a standalone library for us to bind and for others to use too, it's fine. This is really lacking in the open source gamedev scene and I'm sure many will really appreciate it. You can write it in your own github repo, and we will just copy it to Godot repo from now and then if you make updates. If you go this way, please make sure to not depend on external libraries (like third party libraries for math), and keep everything as compact as possible, so it doesnt make engines that may include it more fatty.

If you just want to make it within Godot, It's also fine (I did this with CSG) as I can understand it's less work as all the math code is pretty well tested. In this case, if someone wants then she/he can extract it and make it standalone. In this case, then also I guess it will be better if you use Godot container templates instead.

Either case please make sure to use the MIT license, and we will include it in in our license authors files.

@ddiakopoulos
Copy link

For an initiative like this it might make sense to attempt to validate + profile against a large database of potential input models. One possibility is https://ten-thousand-models.appspot.com/ and another here: http://cvgl.stanford.edu/projects/objectnet3d/. The 10k dataset has many degenerate cases so it's very helpful. What these datasets lack is geometry that is more game-specific (like terrain), but likely to be used for target lightmaps.

@ddiakopoulos
Copy link

There are also very recent techniques with permissively-licensed open-source implementations. The APIs might need work to make them integration-friendly, but otherwise might provide promising alternatives to the other libraries mentioned above.

Both come with interactive editing modes to help users create ideal parameterizations, but it's not too much effort to get reasonable results automatically I think.

@rotoglup
Copy link

About UVAtlas,

The only other open source unwrapper is Microsoft's UVAtlas, but it's windows-only so it needs porting. Also, it does not support specifying a texel size, which makes it no so useful.

@reduz Do you need texel size to specify padding/distance between charts ? I saw in UVAtlas.h the gutter argument for this case. I may miss something as I don't use Godot or UVAtlas :}

//  gutter - The minimum distance, in texels between two charts on the atlas.
//           this gets scaled by the width, so if gutter is 2.5, and it is
//           used on a 512x512 texture, then the minimum distance will be
//           2.5 / 512 in u-v space.

@reduz
Copy link
Member Author

reduz commented Jun 22, 2018

@rotoglup No.. unless there is something I misunderstood, texel size is needed to compute the actual texture size. When you call the unwrapper, you have to feed it a mesh and a texel size (in the same units as the mesh). As a result, the unwrapper needs to figure out the final texture size.

In UVAtlas, you have to supply texture size beforehand, so it's not possible. Otherwise, I'm not sure how gutter could be of use for that (without having to call unwrap twice)..

@JFonS
Copy link
Contributor

JFonS commented Jun 23, 2018

The BFF linked by @ddiakopoulos looks very promising and uses the MIT license. So it might be better to try integrating it into godot (just a part of it) instead of reinventing the wheel.

@JFonS
Copy link
Contributor

JFonS commented Jun 23, 2018

@reduz also, the texel size is only used when generating and packing a texture. Thekla seems to be using nvidia-texture-tools for that, so it should be possible to integrate a different UV mapping algorithm with this texture packer.

@laverneth
Copy link

laverneth commented Jun 23, 2018 via email

@reduz
Copy link
Member Author

reduz commented Jun 23, 2018

@laverneth whathever we use needs to be MIT compatible, else it forces the whole engine to use a more restrictive license. It may seem that BFF is also restricted to manifold with no holes, which is likely a problem. From what I understand, the only two algorithms I know that actually work well are LSCM and SLIM.

@reduz
Copy link
Member Author

reduz commented Jun 23, 2018

Slim example is under GPLv3.. I wish people would stop using this license for academic stuf.. :(
https://github.com/MichaelRabinovich/Scalable-Locally-Injective-Mappings

@laverneth
Copy link

laverneth commented Jun 23, 2018 via email

@reduz
Copy link
Member Author

reduz commented Jun 23, 2018

Do we have access somewhere to a svd decomposition, line eigen? I need it
for decomposing the jacobian. Otherwise I will include the TNT but it will
make the module fatter...

No, in general these are implemented per each algorithm depending on the needs. Bullet has code for this, but it's meant mostly for solving physics constraint for a 3D physics engine. Here I imagine you need it for 2D to relax the edge constraints, so i don't think it can be reused. Worst case, does not seem like it should be too much code to copy from an existing MIT licensed library, if you need that.

@laverneth
Copy link

laverneth commented Jun 23, 2018 via email

@Calinou
Copy link
Member

Calinou commented Jun 23, 2018

The TNT has no particular license, they juste want to be credited. I will.

When no license is attached, no permissions are granted.

If any code is copied, it should be permissively-licensed without ambiguity; please contact its author(s) to ask for permission to use the code under the MIT license.

@hpvb
Copy link
Member

hpvb commented Jun 23, 2018

* This software was developed at the National Institute of Standards and
* Technology (NIST) by employees of the Federal Government in the course
* of their official duties. Pursuant to title 17 Section 105 of the
* United States Code, this software is not subject to copyright protection
* and is in the public domain. NIST assumes no responsibility whatsoever for
* its use by other parties, and makes no guarantees, expressed or implied,
* about its quality, reliability, or any other characteristic.

according to the header files. I don't think anyone needs to be contacted, or legally speaking credited.

@razcore-rad
Copy link
Contributor

That looks like a license to me, remember a license is just some text, it doesn't actually have to be one of the know ones, eg. MIT or whatever, it just needs to be some text compatible with whatever you're using. The above seems pretty compatible

@laverneth
Copy link

laverneth commented Jun 24, 2018 via email

@reduz
Copy link
Member Author

reduz commented Jun 24, 2018

Here in the documentation of light mapping you can see the two use cases (manual and on import), basically the most common use case is as an import flag, but the manual method allows you to debug it more easily

@reduz
Copy link
Member Author

reduz commented Jun 24, 2018

@reduz
Copy link
Member Author

reduz commented Jun 24, 2018

If you want to iterate faster, remember you can run Godot editor from the command line with a test scene like:

godot -e test_unwrap.scn

@lassade
Copy link
Contributor

lassade commented Jun 27, 2018

What about this implementation http://alice.loria.fr/index.php/software/4-library/23-opennl.html it's under the 3-Clause BSD License, is very compact (4 files) and static linked.

@jamesdolan
Copy link

I had pretty much have been facing the same dilemma for my own project. Thekla was way too crashy for my liking but UVAtlas seemed to be pretty robust but being Windows only was a bit of a downer.

UVAtlas allows you to run Partitioning and Packing as different steps. The partitioner is resolution independent and I am quite happy with its output, its the packer that needs work. As you point out it doesn't let you set a target density, but its pretty easy to compute surface area before packing and calculate your own scale to target a specific density.

The bigger problem IMHO is that the tetris-style packer does a rather poor job compared to Thekla in my experience. Leaves lots of dead space, specially when there is a large ratio between the biggest charts and smallest charts.

The other nice thing about UVAtlas is its actually under active development and tested in production.

My recommendation after taking a quick glance at feasibility is instead of forking it and porting it, someone should build a compatibility layer that re-defines the macros and types it uses so that its easy to take updates from the mainline and push changes upstream (guessing MS wouldn't take a pull request that de-microsofts it). That is my long-term plan, but not sure when I would get to it... so if someone else does it, even better! :p

@AbhimanyuAryan
Copy link

@reduz may I ask what bugs are you facing with Thekla Atlas? Are you getting charts with too much distortion, or worse, that self-overlap?

@reduz
Copy link
Member Author

reduz commented Jul 10, 2018

@AbhimanyuAryan No, Thekla works more or less well, the problem is that it's huge, depends on unmaintained third party libraries, it's crashy (code has no checks for geometry it does not like), and the main problem above all, it's really really slow. It's simply unusable on complex scenes.

@jpcy
Copy link

jpcy commented Jul 11, 2018

I did some work removing unused code from thekla_atlas a while back here. Got it down from about 18kloc to 8kloc.

Some easy performance fixes:

Testing with dabrovnic sponza (~66k triangles):

  • packing quality 0 - 60 seconds
  • packing quality 1 - 25 seconds
  • packing quality 1, printing disabled - 4 seconds

@reduz
Copy link
Member Author

reduz commented Jul 13, 2018

@jpcy oh wow, amazing work! definitely need to give it a check. Are you up for merging fixes? ( think i did a few to thekla that resulted in crashes in bad input geometry )

@jpcy
Copy link

jpcy commented Jul 14, 2018

@reduz After looking through the Godot changes, I added checks for zero length edges and zero area triangles. Zero length edges were definitely causing crashes.

@laverneth
Copy link

laverneth commented Jul 16, 2018 via email

@Calinou
Copy link
Member

Calinou commented Jul 16, 2018

@laverneth Have you tried triangulating faces while exporting in Blender, either by adding a Triangulate modifier and checking Apply Modifiers in the OBJ export dialog, or by checking Triangulate Faces in the same dialog?

In general, it's best to perform triangulation in advance — it avoids some quirks that can arise when you let an engine triangulate meshes for you.

@laverneth
Copy link

laverneth commented Jul 16, 2018 via email

@huxingyi
Copy link

Hi, how is the progress on this? I used Thekla Atlas for unwrapping UVs also, but cannot bear it with the crash on bad meshes. Actually, I looked this issue about two months ago when I was trying to find an alternative, finally I decided write it on my own, I use the MPL2 licensed libigl’s parameterization implementation (ARAP and LSCM). It works well on my project.
Here is my UV unwrapping library, here is how it’s been used,
And here is the screen shoot of unwrapping:
screen shot 2018-12-22 at 21 08 26

If you are interested, I’d like to integrate it into godot.

BTW, I saw you @reduz request an alternative for cork, currently, I use CGAL, it works quite well on mesh boolean operations, but I have decided try to write it on my own also, because I cannot go with the CGAL license, here is the project, although, empty yet, because I just start it by today :-)

@laverneth
Copy link

laverneth commented Feb 5, 2019

Wow that looks good! On my side I tried to have a look into godot' code to see what was needed to do it inside. My conclusion is the following: we need a proper mesh boundary description to initialize the mapping with the Tutte method and a proper linear solver. Both of those represent a big amount of code (in particular a good linear solver) and I doubt that the godot' community would like to see its codebase grow so much for parametrization code. However, we should ask to @reduz , maybe?

@fire
Copy link
Member

fire commented Apr 20, 2019

Has anything changed? What is the status of this?

@huxingyi
Copy link

Thanks @laverneth for the update. And I didn't got any reply from godot since I posted here, so I don't know what's the status of this, and I am quite busy at the moment, so I am out on this issue.

@KoBeWi
Copy link
Member

KoBeWi commented Apr 20, 2019

Thekla Atlas was replaced by Xatlas, but I don't know any more details.

@Calinou
Copy link
Member

Calinou commented Jan 30, 2020

With Thekla Atlas being replaced by Xatlas and further tweaks made to optimize Xatlas, this issue can be closed.

@Calinou Calinou closed this as completed Jan 30, 2020
@akien-mga akien-mga added this to the 3.2 milestone Jan 30, 2020
@Ben-Mack
Copy link

I've noticed XA_RECOMPUTE_CHARTS enabled in xatlas usually results in a lot of small and unnecessary charts. Both original and Godot's modified version suffers from this problem.
It would be great if someone could take a look and discuss ideas to improve: jpcy/xatlas#84
recompute-charts-on

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