Pass the normal matrix through and multiply the normal by it

This commit is contained in:
Eryn Wells 2018-11-20 11:24:28 -07:00
parent e99cd03446
commit 952204a5b6
2 changed files with 6 additions and 9 deletions

View file

@ -210,8 +210,11 @@ class Renderer: NSObject, MTKViewDelegate {
uniforms[0].modelViewMatrix = modelViewMatrix
rotation += 0.003
// Remove the fourth row and column from our model-view matrix and find its inverse-transpose, if it exists.
let rotSclModelViewMatrix = float3x3(modelViewMatrix.columns.0.xyz, modelViewMatrix.columns.1.xyz, modelViewMatrix.columns.2.xyz)
uniforms[0].normalMatrix = rotSclModelViewMatrix.inverse.transpose
if rotSclModelViewMatrix.determinant != 0 {
uniforms[0].normalMatrix = rotSclModelViewMatrix.inverse.transpose
}
uniforms[0].terrainDimensions = terrain.dimensions
uniforms[0].terrainSegments = terrain.segments