Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fragment tangents/basis generates incorrect tangents. #4

Open
alecazam opened this issue Jun 19, 2021 · 5 comments
Open

Fragment tangents/basis generates incorrect tangents. #4

alecazam opened this issue Jun 19, 2021 · 5 comments

Comments

@alecazam
Copy link
Owner

  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
Copy link
Owner Author

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
Copy link
Owner Author

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
Copy link
Owner Author

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.

@superdump
Copy link

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.

@alecazam
Copy link
Owner Author

alecazam commented Apr 27, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants