kram icon indicating copy to clipboard operation
kram copied to clipboard

Fragment tangents/basis generates incorrect tangents.

Open alecazam opened this issue 3 years ago • 5 comments

  1. Hit 8 to switch to sphere shape
  2. Hit 6 switch to viewing tangent shape channel
  3. Hit T to toggle between vertex tangents/basis and fragment tangents/basis

Vertex Tangents - are nice and smooth with a seam down the middle Fragment Tangents - no seam, and only the same in the middle of the sphere

I had to negate T in the shader to generate right-handed tangents. It looks like the z slope and the vertical falloff throw off the calculations Interpolated world pos, world vertex normal, and uv are passed into the call

Original shader passed -V = (worldPos - cameraPos), but with deltas the cameraPos drops out. So passing worldPos should be the same. The bitangents are almost identical with small banding at the top/bottom.

Vertex Tangents image

Fragment Tangents image

alecazam avatar Jun 19 '21 20:06 alecazam

The tangents are flipping sign on each triangle in the upper/lower hemispheres causing the discontinuity. The peak of the triangle seems to throw off the calculations, since he wide edges are smooth.

alecazam avatar Jun 19 '21 21:06 alecazam

I made a change to compute B, and then do an orthogonal cross of that with the Normal. So now tangents and bitangents have ridges, but the result is more continuous around the sphere

image

alecazam avatar Jun 19 '21 21:06 alecazam

I think the issue is that dpx/y are the flat planar polygon uses along with the interpolated vertex normal. dNx/y would be the interpolated plane, but could be zero if all normals point the same direction.

alecazam avatar Jun 20 '21 17:06 alecazam

Not totally sure if it's relevant, but have you seen the mikktspace algorithm? It seems to be the standard way of generating vertex tangents.

superdump avatar Apr 27 '22 12:04 superdump

I do, and that’s what most dcc apps use on the cpu side to generate a basis. This was more about looking at ways to compress and reconstruct the vertex data fed to the gpu. The original algorithm didn’t deal with any edge cases, and I consider normal + du/dv too costly.

I could also reconstruct normals from tan/bitan which supports uv skew. Emil Perrson recommended that for JC3.

alecazam avatar Apr 27 '22 13:04 alecazam