FrankTheBoxMonster / LoL-MAPGEO-Converter

GNU Affero General Public License v3.0
30 stars 5 forks source link

Normals are flipped on some models. #3

Closed TheKillerey closed 4 years ago

TheKillerey commented 4 years ago

image Tested the base map in map21 for Nexus Blitz

FrankTheBoxMonster commented 4 years ago

image

The only flipped normals on that map in Maya are on these trees at the front, and some similar ones on the back, which is a Riot issue.

image

This looks like the area you are looking at with the map in Maya. Whatever is going wrong with your normals is probably an Unreal issue.

TheKillerey commented 4 years ago

image This is how it looks like when I use Maya. I first saw that in unreal. By setting to 2 sided you will see the same objects. I never had any issues with Unreal Models yet.

TheKillerey commented 4 years ago

image If we add backface culling only the bugged models are showed again. This is witout 2 sided lighting

FrankTheBoxMonster commented 4 years ago

Well like I said, it's not happening to me, so I have no way to try fixing it.

I did look at those specific models and it seems that they all have their vertex normals pointing one way but their face normals pointing another way. Most model file formats (including all of Riot's as well as .OBJ) use vertex normals, and for my Maya, that's good enough. Your programs' renderers seem to only care about face normals.

If that's truly the only thing causing this issue, then I don't even have the opportunity to fix it. There is no way to specify face normals in the .OBJ format, only vertex normals. I'm providing your programs as much information as I can, and all of it is correct for what Riot intends, but your programs are ignoring the part of it that would fix this issue, and there's nothing I can do about that.

It does seem like this is mostly an all or nothing thing though for each model, so you should be able to just flip the normals of the affected models without having to spend too much time flipping individual faces.

FrankTheBoxMonster commented 4 years ago

I ended up thinking of a way to ensure that the face normals should always match the vertex normals, but it's pretty messy.

Face normals are based on the draw order of the vertices. In most renderers, the face normal is considered as pointing in the direction where the vertices move in a clockwise or counter-clockwise direction around the face's center, depending on the renderer. Maya specifically uses counter-clockwise.

What I did is have each face manually calculate its face normal based on what the vertex normals claim, then translate the face's vertices from world coordinates to the face's local coordinates, then converted those local coordinates into an angle rotation about the face's center. From there, I can manually rearrange the face's vertex order so that the vertex angles always move counter-clockwise (just sort the vertices by their angle value in increasing order). This results in the face normal always pointing in the direction intended by the vertex normals.

All of this ended up turning something that was previously three lines of code into over 400 lines of code. I'm not 100% sure that it will work in every single situation (there were a few edge cases I ran into while testing, and likely a couple more that I didn't catch), however it seems to be good enough.

On a related note, there's some models in the Ionia Nexus Blitz map that are not fixed by this change. This is because they really do have their normals backwards, however their materials also have a cullEnable = false property that corrects for this in-game by disabling their backface culling.

FrankTheBoxMonster commented 4 years ago

Release is here