Advertisement

PBR tangent issue

Started by June 11, 2020 05:02 PM
5 comments, last by Jman2 4 years, 9 months ago

Hello,

When rendering PBR models there are lots of problems, objects are completely smooth and certain areas being metallic that shouldn't. Additionally tangents are incorrectly generated, below is a print screen of the results. You can see the panel on the top left is discoloured and some metal pieces are as well.

The shader code is here: https://pastebin.com/fsFq8BJJ  https://pastebin.com/b0c6A7MV

Tangent generation is here: https://pastebin.com/TJa2Zz4f​ 

Tangent formula is from Eric Lengyel: https://foundationsofgameenginedev.com/FGED2-sample.pdf​

If anybody can spot what's causing this issue it would be greatly appreciated, i have tried using TBN matrix and passing that from vertex shader. Also passing the calculated tangent from the CPU to GPU instead of calculating from cross product etc. Must be missing something crucial that's broke this.

Thanks.

Any time you have mirrored meshes, you have the same uv, for geometry that points in a different direction. This causes the tangent to be pointing in the wrong 3d direction relative to the triangle. For this you need a w-coordinate for your tangent which will be 1.0 or -1.0. You will multiply your tangent vector by this.
It appears your model is likely to have shared uv space for the left/right door.

NBA2K, Madden, Maneater, Killing Floor, Sims

Advertisement

@dpadam450

Yes i do multiple by w to do the bitangent negation, i think the models uv for the panel is inversed flipped on the V direction. But shouldnt the negation fix it ?

Model is from here: https://3dmodelhaven.com/model/?c=interior%20design&m=GothicCabinet_01

I can load the model and look tomorrow. Why not for debug purposes have the pixel shader output the w component so you can debug if they are correct. My assumption is the half of the model is mirrored. So half should show up black and other half white.

The negation will work if computed properly. Not sure if there is a better way but I cross the tangent/bi-tangent, and if they don't point the same direction as the normal, then I set the w component to -1.0. This way I know they are in a mirrored reference frame.

NBA2K, Madden, Maneater, Killing Floor, Sims

I tried analyising a few debugs but didnt think to do w, not sure if this helps you spot it but shouldnt the panel thats inversed be black? that way it knows to do the flip?

W Debug:

Tangent:

Bitangnet:

Normal whcih looks weird:

FINALLY, think i have solved it, the normal texture was being interpreted as an SRGB which meant it was being converted to linear from linear i.e being pow(v,0.45) etc. which was completely wrong. Will have to add an easy way to detect if an image is a diffuse or data image maybe detecting tags like _Normal etc.

Result looks alot better now:

This topic is closed to new replies.

Advertisement