To developers: What's the threshold for "degenerate" triangles @ Lightmapping?

Hi,

I’ve noticed that Unity assigns lightmap coordinates (0,0) to “degenerate” triangles.
By that, I mean very long/thin triangles. After baking the lightmap, this leads to bad artifacts.
I think it’s OK to do so, because usually this means that something is wrong with the model.

Now I want to alert the modeler early enough that something is not good with his model, before it gets exported to Unity, so that the mistake can be spotted as early as possible!

In order to do that, I need to know exactly how Unity filters out these triangles in the baking process. Does it do it by considering the triangle’s surface area, or the ratio of edge lengths? What are the thresholds for the decision?

Any hint would be extremely useful to us!

Sorry for pushing, but I don’t see any other way :frowning:
Threads disappear so fast that it seems to be almost pure luck to get support.

I am not exactly sure if this it what you mean. But the artifacts normally appear if you have overlapping uv’s and you use this uv’s for lightmapping. In this case the solution would be a second uv set for lightmapping. Unity is doing this for you if check “Generate Lightmap UV” in the import settings of your model.
Like I mentioned, not sure if this is your problem at all.

Don’t use the “Ligthmap Auto” of unity but create the UVW 2 in Blender, 3ds Max, Maya … this is perhaps the best solution ?

Thanks for your feedback.

I’m letting Unity generate the UVs.
And I think it is better at this than 3ds max by default. Unwrapping by hand is not an option for us, we need an automated solution.

However, very long and thin triangles somehow get “lost” in the process. This has been mentioned by a developer in another posting, which I don’t remember, so it is confirmed behavior.

I’m fine with this, since these extremely long and thin triangles usually mean that the model is bad. I just want to know how exactly Unity filters out these triangles so that I can do a check in the modelling tool (3ds max) and show a warning to the modeller even before the model is exported to Unity and baked (because only then you can see that something is wrong).

Just another guess:
If you have intersecting geometry, means there a vertices hidden 10cm into a wall then you can get also artifacts. Because the first 10cm of the polygon doesn’t receive any light.
Do you have a screenshot?

@_rem
just curios, whats the problem with the unity lightmap uv set?

No, my geometry is not “inside the wall”. If it was, I could not see it, and therefore could not see the artifact, right? :wink:

It really is a long thin triangle. And this behavior of Unity has been confirmed in another thread by a developer. So, I know exactly why it happens, and this is OK.

I only want to know the algorithm that Unity applies to identify such triangles, so that I can output a warning before the model is exported to Unity. That’s why I titled this thread “To developers”, because only they can provide me the answer I’m looking for … everything else would just be guessing or reverse engineering.

Here are two screenshots, one with the lightmap and the other one showing the wireframe of the model. In the first image, you see that these long thin triangles have a 100% white lightmap color, because Unity assigns them (0, 0) in the lightmap, which happens to be white.

You got me wrong. I was talking just about one vertice of the geometry.

Anyway good luck.

hey, sorry for not replying earlier (i was poked when there were no replies at all ;-))
currently we use these thresholds:
it checks area for 1e-10
triangle sides for 1e-6
triangle angles for 1e-3
we do have plans to make stuff better (like i was asked long ago to fill degenerates not with (0,0), but with uv info from neighbour triangles), but no eta for now, sorry

Great, Alexey, thank you a lot! :slight_smile:
This information will make my life easier!

Just a side note… I don’t know what 3D software you use, but in Blender adding a second UVmap and unwrapping it for lightmapping is as simple as 3 or 4 clicks. It literally takes about ten seconds and requires no user intervention beyond those clicks. You do not need to completely unwrap the model from scratch, it just makes a bunch of flat shapes and arranges them on the UV so that none of them overlap.

I would imagine your software has a similar feature, since creating UV-maps is a very common problem, and one that’s apparently pretty easy to solve algorithmically. I would be surprised if it did not. Worst case scenario, you might want to consider integrating Blender into your pipeline. Blender itself is free and you could learn the specific workflow to just add a second UV-map in like five minutes.