Skip to content

Fix normals under nonuniform scale - #54

Merged
Lemiort merged 1 commit into
masterfrom
bugfix/28-normal-matrix
Oct 24, 2026
Merged

Lemiort merged 1 commit into
masterfrom
bugfix/28-normal-matrix

Conversation

@Lemiort

@Lemiort Lemiort commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Closes #28.

Problem

Normals were transformed by rotation only, while vertex positions used rotation plus nonuniform scale. This makes the resulting normals non-perpendicular to the transformed surface and produces incorrect diffuse/specular lighting.

Summary

  • compute the inverse-scale/rotation normal matrix for each transform
  • upload the normal matrix for both individual and instanced mesh draws
  • use it in both forward and deferred geometry vertex shaders
  • use a finite rotation-only fallback for collapsed (near-zero scale) geometry
  • add regression tests proving transformed normals remain perpendicular and singular scales remain finite

Verification

  • cmake --build build/build/Release --target NEE math_migration_tests opengl_render_tests
  • ctest --test-dir build/build/Release -R "ObjectTransform|OpenGLRender" --output-on-failure (14/14 passed)
  • ctest --test-dir build/build/Release --output-on-failure --no-tests=error (36/36 passed)

@Lemiort
Lemiort merged commit 8da18a5 into master Oct 24, 2026
10 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.

[P2] Transform normals correctly under nonuniform scale

1 participant