Skip to content

Normal mapping without tangents: negate the derivative bitangent for glTF - #200

Merged
proggeramlug merged 1 commit into
mainfrom
fix/derivative-tbn-bitangent
Nov 11, 2026
Merged

proggeramlug merged 1 commit into
mainfrom
fix/derivative-tbn-bitangent

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What

compute_tbn, the screen-space tangent frame used when a mesh has no TANGENT attribute, returned the bitangent along increasing v. glTF's v runs down the image while its normal maps keep +Y up, so the glTF bitangent (cross(normal, tangent) * w, what the vertex-tangent branch builds) points along decreasing v. The fallback therefore inverted the normal map's green channel on every tangent-less mesh.

Why it matters

On a low-poly mesh whose normal map carries the smoothing (every generated character and prop in The Deep), the inverted channel doubles the faceting instead of cancelling it: each triangle shows as a facet under a directional light. Found by rendering the same GLB in three.js and in Bloom at the same camera: three.js is smooth, Bloom was faceted, and with this change Bloom matches.

Checks

  • cargo test --release in native/shared: 501 unit tests and all 86 golden renders pass with no golden changes. visibility_shading_matches_forward_reference fails, as it does on main.
  • The vertex-tangent branch is unchanged. Negating its bitangent as an experiment made a tangent-carrying copy of the model visibly worse, so that branch was already right.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected the fallback bitangent direction used in rendering. This may resolve visual inconsistencies in affected surfaces.

…glTF

The screen-space tangent frame returns the direction of increasing v, but
glTF's v runs down the image while its normal maps keep +Y up, so the frame
inverted the normal map's green channel on every mesh without a TANGENT
attribute. On low-poly meshes whose normal map carries the smoothing, each
triangle showed as a facet. The vertex-tangent branch was already correct.
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The fallback frame in compute_tbn now uses a negated bitangent. Its tangent and normal axes are unchanged.

Changes: Fallback TBN frame

Layer / File(s) Summary
Update fallback bitangent
native/shared/src/renderer/shaders/core.rs
compute_tbn now returns the fallback bitangent with the opposite direction. The tangent and normal axes are unchanged.

Estimated code review effort: 1 (Trivial) | ~4 minutes

Change: Bug fix

Possibly related PRs

  • Bloom-Engine/engine#118: Refactors compute_tbn for the no-tangent path, which is also affected by this fallback bitangent change.
  • Bloom-Engine/engine#119: Changes derivative computation in compute_tbn for the same no-tangent fallback path.
Merge Risk: Minimal · up to 20541

This fixes the inverted green channel for glTF meshes without tangents. The fallback bitangent now matches glTF's UV convention and the existing vertex-tangent path, and no concrete merge-blocking risk remains.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: negating the derivative bitangent for glTF normal mapping without tangents.
Description check Passed The description explains what changed, why it matters, and how it was tested. It uses different headings from the template and omits a separate Notes for reviewers section, but it contains the require…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains what changed, why it matters, and how it was tested. It uses different headings from the template and omits a separate Notes for reviewers section, but it contains the required information and is mostly complete.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6b828f7e-ce3e-4319-9950-cd8d80e57487
Commits

Reviewing files that changed from the base of the PR and between 39ccc64 and 205413f.

Files selected for processing: 1

  • native/shared/src/renderer/shaders/core.rs

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@proggeramlug
proggeramlug merged commit 5da16ca into main Nov 11, 2026
55 of 70 checks passed
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