Advertisement

Normal map issues, I think the tangents are wrong

Started by February 20, 2020 07:45 PM
7 comments, last by fleabay 4Β years, 10Β months ago

I have a model made in blender, which I've exported as a collada file. When loading it in my game engine, I get the result as shown in picture A. The code used to calculate the tangents are shown in picture B. If I set the tangents to something like (1,1,1) I get a much more smooth result but it gets very blocky in the places where there's supposed to be fine details (on high poly models). If I export the model to obj-format and load it in my engine through another pipeline, which uses the same code for calculating the tangents, the result is perfect. Does collada order the vertices in a strange order? I'm confused here and pretty much stuck. any tips would be appreciated.

I'll start by showing what happens when I load a simple box with 8 vertices, a texture and a normal map, this is collada format as well.

Here's two boxes, the exact same model, using the exact same shader and textures, the only difference is that the faulty one is imported as a collada and the correct one is imported as .obj

left is faulty

Here's another strange thing, the vertex positions in the collada file and .obj file doesn't match at all, there's not even any mention in the collada file of the vertices that are supposed to be at -0.004383! perhaps this discrepancy can be a part of the problem? Do anyone know why this is the case?

picture A
picture B

Check your export options. It kinda looks like an untriangulated mesh on the Collada.

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

Advertisement

Nope, it's triangulated. I even tried to triangulate the model manually, same result (and same values in the exported file, so the triangulation is working) :(

ChimDev said:
Nope, it's triangulated.

If you upload the model(s) I will do an analysis of the issues. I'm experienced in repairing extracted game models.

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

We can start with the simple box-models, I'm sure that if I can get them to work the rest will fall into place. Though I suspect that the problem isn't with the models, collada seems to order vertices and texture UV's in a very different way than .obj-files, and this could possibly mess up my calculations (though I have no idea on how to fix it).

The .obj-model is working, the .dae (collada) model is not. They are using the exact same base model in blender.

.obj: https://minfil.com/V5X4Q1bcoc/testbox_obj (Swedish site, just press β€˜ladda ner’, means download)

.dae: https://minfil.com/LaX2Q7b1o9/boxmodel_dae

The OBJ ISN'T triangulated, is 1x1 units, has smooth shaded vertex normals. All UV edges are unsewn.

The DAE IS triangulated, is bound to a joint/bone, is scaled to 100X and has smooth shaded vertex normals.. All UV edges are unsewn.

I believe that the game engine is sewing the triangulated edges of the OBJ faces together when it does the triangulation. The DAE is already triangulated and the face edges are never sewn together and that causes the shading issues.

Also, smooth shaded vertex normals on a cube isn't ideal for all uses.

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

Advertisement

Thanks a bunch for the help, I hope that this is the actual issue, and I will investigate it more tomorrow now that I have some clues. Though I'm not sure what you mean by sewn and unsewn UV-edges, if you have any resources I could sift through to learn about it that would be great (otherwise I'll just google about it, no worries).

Thanks again for the help and I will report back if I can (or can't) solve it tomorrow (it's getting late here).

I'm stumped. Here's what information I could gather, throwing it out there in case someone can solve this, because I sure can't.

I made a model that is fully triangulated, a box. In the .dae/collada file I get 72 uv values (s and t values), which would correspond to 36 vertices (3 for every triangle face in the cube). In the .obj file I get 48 uv values (s and t values), which would correspond to 24 vertices (2 for every triangle in the cube, or 4 for every face).

When manually printing out the vertex positions, uv-values, normals and tangents I get these results (numbering added to some value lists):

.obj file: https://minfil.com/ZbU7Y5b5oa/obj_rtf

.dae file: https://minfil.com/l9V4Y1b9oa/collada_rtf

As can be seen the result here as well, after being loaded by the engine, contains a different amount of vertices and uv-positions as could be expected.

The tangent calculations are based on the .obj file format, and applied without any other consideration to the .dae based model (the code can be seen in my first post). This is probably wrong, and there's probably some modifications that needs to be done here, but I have no clue as to how to proceed here). I'll restate that the normal mapping is working for the .obj files, and not working for the .dae files, so the basis of the tangent calculations should be correct.

@ChimDev

So you've solved the problem of all UV edges getting cut/not getting sewn?

Can you try to use the DAE untriangulated and see if the game engine does a proper job of triangulation?

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

This topic is closed to new replies.

Advertisement