Skip to content

Fix MikkTSpace triangle selection and coordinate mapping for 3DS models - #39

Open
moonwho101 wants to merge 3 commits into
DS-mikktspace-allfrom
fix-mikktspace-3ds-tangents-4013187589097524509
Open

Fix MikkTSpace triangle selection and coordinate mapping for 3DS models#39
moonwho101 wants to merge 3 commits into
DS-mikktspace-allfrom
fix-mikktspace-3ds-tangents-4013187589097524509

Conversation

@moonwho101

Copy link
Copy Markdown
Owner

This change fixes the MikkTSpace tangent calculation for 3DS models by ensuring that:

  1. All triangles across sub-objects are counted and selected by setting userData.total_faces = face_i_count / 3.
  2. Vertex positions provided to MikkTSpace swap Y and Z (fvPosOut[1] = v.z, fvPosOut[2] = v.y) to match DirectX 3DS model space.
  3. V texture coordinates in ThreeDSMikk_GetTexCoord are inverted (1.0f - (t.y * sky)) to prevent inverted tangent vectors and shading artifacts.

PR created automatically by Jules for task 4013187589097524509 started by @moonwho101

- Update userData.total_faces = face_i_count / 3 in Compute3DSModelNormals to select all triangles across all sub-objects for MikkTSpace tangent space generation.
- Swap Y and Z coordinates in ThreeDSMikk_GetPosition to match DirectX 3DS model space coordinate layout.
- Invert V texture coordinates in ThreeDSMikk_GetTexCoord to align with 3DS model texture mapping.

Co-authored-by: moonwho101 <90150577+moonwho101@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

google-labs-jules Bot and others added 2 commits August 24, 2026 02:00
… TBN artifacts

- Set userData.total_faces = face_i_count / 3 in Compute3DSModelNormals to select all triangles across all sub-objects for MikkTSpace tangent space generation.
- Swap Y and Z coordinates in ThreeDSMikk_GetPosition and invert V in ThreeDSMikk_GetTexCoord to match DirectX 3DS model space.
- Add degenerate tangent safeguards and TBN fallback vectors in NormalSampleToWorldSpace across HLSL shaders.
- Synchronize T flip when N is inverted for double-sided triangles in ClosestHit.
- Clamp perturbed/interpolated normals at grazing view angles (dot(N, V) >= 0.001f) to eliminate black rim lighting artifacts on 3DS models like coin.3ds.

Co-authored-by: moonwho101 <90150577+moonwho101@users.noreply.github.com>
…artifacts

- Set userData.total_faces = face_i_count / 3 in Compute3DSModelNormals to process all triangles across all sub-objects.
- Negate face normals and tangents in Compute3DSModelNormals to account for 3DS winding order and normalize vertex normals before calling MikkTSpace.
- Swap Y and Z coordinates in ThreeDSMikk_GetPosition and invert V in ThreeDSMikk_GetTexCoord to match DirectX 3DS model space.
- Add degenerate tangent safeguards and TBN fallback vectors in NormalSampleToWorldSpace across HLSL shaders.
- Synchronize T flip when N is inverted for double-sided triangles in ClosestHit.
- Clamp perturbed/interpolated normals at grazing view angles (dot(N, V) >= 0.001f) to eliminate black rim lighting artifacts on 3DS models like coin.3ds.

Co-authored-by: moonwho101 <90150577+moonwho101@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

1 participant