From f46461e472ad14376c4d3b48074a783742bda11f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CMalcolm?= <“mtoon@atlasprogramming.com”> Date: Sun, 15 Dec 2024 14:11:46 -0500 Subject: [PATCH] Updates to lighting a bit --- platform/darwin/src/gltf/GLTFMath.cpp | 11 +++++++++++ platform/darwin/src/gltf/GLTFMath.hpp | 2 ++ platform/darwin/src/gltf/MetalRenderer+GLTFAsset.mm | 2 ++ 3 files changed, 15 insertions(+) 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);