diff --git a/platform/darwin/src/gltf/GLTFMath.cpp b/platform/darwin/src/gltf/GLTFMath.cpp index d7055a0360..97f5821e90 100644 --- a/platform/darwin/src/gltf/GLTFMath.cpp +++ b/platform/darwin/src/gltf/GLTFMath.cpp @@ -202,3 +202,14 @@ simd_float4x4 GLTFNormalMatrixFromModelMatrix(simd_float4x4 m) { } }; return mout; } + +simd_double4x4 GLTFNormalMatrixFromModelMatrixD(simd_double4x4 m) { + simd_double3x3 nm = simd_inverse(simd_transpose(GLTFMatrixUpperLeft3x3D(m))); + simd_double4x4 mout = { { + { nm.columns[0][0], nm.columns[0][1], nm.columns[0][2], 0 }, + { nm.columns[1][0], nm.columns[1][1], nm.columns[1][2], 0 }, + { nm.columns[2][0], nm.columns[2][1], nm.columns[2][2], 0 }, + { 0, 0, 0, 1 } + } }; + return mout; +} diff --git a/platform/darwin/src/gltf/GLTFMath.hpp b/platform/darwin/src/gltf/GLTFMath.hpp index af29606989..2882174795 100644 --- a/platform/darwin/src/gltf/GLTFMath.hpp +++ b/platform/darwin/src/gltf/GLTFMath.hpp @@ -130,6 +130,8 @@ simd_float3x3 GLTFTextureMatrixFromTransform(GLTFTextureTransform transform); simd_float4x4 GLTFNormalMatrixFromModelMatrix(simd_float4x4 m); +simd_double4x4 GLTFNormalMatrixFromModelMatrixD(simd_double4x4 m); + #ifdef __cplusplus } diff --git a/platform/darwin/src/gltf/MetalRenderer+GLTFAsset.mm b/platform/darwin/src/gltf/MetalRenderer+GLTFAsset.mm index c16c4f4c75..5695f386a3 100644 --- a/platform/darwin/src/gltf/MetalRenderer+GLTFAsset.mm +++ b/platform/darwin/src/gltf/MetalRenderer+GLTFAsset.mm @@ -372,6 +372,8 @@ simd_float3 double3_to_float3(simd_double3 input) { auto mvp = matrix_multiply(_projectionMatrix, model->_modelViewMatrix); auto mvpF = matrix_double_to_float(mvp); vertexUniforms.modelViewProjectionMatrix = mvpF; + auto normalMatrix = GLTFNormalMatrixFromModelMatrixD( model->_modelViewMatrix); + vertexUniforms.normalMatrix = matrix_double_to_float(normalMatrix);