Add normalMatrix uniform

This commit is contained in:
Eryn Wells 2018-11-20 11:01:46 -07:00
parent 55f7c6fe78
commit 97c31c7548
2 changed files with 6 additions and 1 deletions

View file

@ -206,9 +206,13 @@ class Renderer: NSObject, MTKViewDelegate {
let rotationAxis = float3(0, 1, 0)
let modelMatrix = matrix4x4_rotation(radians: rotation, axis: rotationAxis)
let viewMatrix = matrix4x4_translation(0.0, -2.0, -8.0)
uniforms[0].modelViewMatrix = simd_mul(viewMatrix, modelMatrix)
let modelViewMatrix = simd_mul(viewMatrix, modelMatrix)
uniforms[0].modelViewMatrix = modelViewMatrix
rotation += 0.003
let rotSclModelViewMatrix = float3x3(modelViewMatrix.columns.0.xyz, modelViewMatrix.columns.1.xyz, modelViewMatrix.columns.2.xyz)
uniforms[0].normalMatrix = rotSclModelViewMatrix.inverse.transpose
uniforms[0].terrainDimensions = terrain.dimensions
uniforms[0].terrainSegments = terrain.segments
}

View file

@ -58,6 +58,7 @@ typedef NS_ENUM(NSInteger, GeneratorTextureIndex) {
typedef struct {
matrix_float4x4 projectionMatrix;
matrix_float4x4 modelViewMatrix;
matrix_float3x3 normalMatrix;
packed_float2 terrainDimensions;
packed_uint2 terrainSegments;
} Uniforms;