From 6a86368d3a56fca1aa029fc4d9d9cdd35de3e326 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 10 Nov 2018 21:10:03 -0500 Subject: [PATCH] Include the normals in the generated Plane geometry --- Terrain2/ShaderTypes.h | 8 ++++---- Terrain2/Terrain.swift | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Terrain2/ShaderTypes.h b/Terrain2/ShaderTypes.h index 4172884..de53b65 100644 --- a/Terrain2/ShaderTypes.h +++ b/Terrain2/ShaderTypes.h @@ -24,16 +24,16 @@ typedef NS_ENUM(NSInteger, BufferIndex) { BufferIndexMeshPositions = 0, - BufferIndexMeshGenerics = 1, - BufferIndexMeshGridCoords = 2, + BufferIndexNormals = 1, + BufferIndexMeshGenerics = 2, BufferIndexUniforms = 3, }; typedef NS_ENUM(NSInteger, VertexAttribute) { VertexAttributePosition = 0, - VertexAttributeTexcoord = 1, - VertexAttributeGridCoord = 2, + VertexAttributeNormal = 1, + VertexAttributeTexcoord = 2, }; typedef NS_ENUM(NSInteger, TextureIndex) diff --git a/Terrain2/Terrain.swift b/Terrain2/Terrain.swift index ae2f5da..f917e6f 100644 --- a/Terrain2/Terrain.swift +++ b/Terrain2/Terrain.swift @@ -19,26 +19,26 @@ class Terrain: NSObject { desc.attributes[VertexAttribute.position.rawValue].offset = 0 desc.attributes[VertexAttribute.position.rawValue].bufferIndex = BufferIndex.meshPositions.rawValue + desc.attributes[VertexAttribute.normal.rawValue].format = .float3 + desc.attributes[VertexAttribute.normal.rawValue].offset = 0 + desc.attributes[VertexAttribute.normal.rawValue].bufferIndex = BufferIndex.normals.rawValue + desc.attributes[VertexAttribute.texcoord.rawValue].format = .float2 desc.attributes[VertexAttribute.texcoord.rawValue].offset = 0 desc.attributes[VertexAttribute.texcoord.rawValue].bufferIndex = BufferIndex.meshGenerics.rawValue - desc.attributes[VertexAttribute.gridCoord.rawValue].format = .uint2 - desc.attributes[VertexAttribute.gridCoord.rawValue].offset = 0 - desc.attributes[VertexAttribute.gridCoord.rawValue].bufferIndex = BufferIndex.meshGridCoords.rawValue - desc.layouts[BufferIndex.meshPositions.rawValue].stride = 12 desc.layouts[BufferIndex.meshPositions.rawValue].stepRate = 1 desc.layouts[BufferIndex.meshPositions.rawValue].stepFunction = .perVertex + desc.layouts[BufferIndex.normals.rawValue].stride = 12 + desc.layouts[BufferIndex.normals.rawValue].stepRate = 1 + desc.layouts[BufferIndex.normals.rawValue].stepFunction = .perVertex + desc.layouts[BufferIndex.meshGenerics.rawValue].stride = 8 desc.layouts[BufferIndex.meshGenerics.rawValue].stepRate = 1 desc.layouts[BufferIndex.meshGenerics.rawValue].stepFunction = .perVertex - desc.layouts[BufferIndex.meshGridCoords.rawValue].stride = MemoryLayout.stride - desc.layouts[BufferIndex.meshGridCoords.rawValue].stepRate = 1 - desc.layouts[BufferIndex.meshGridCoords.rawValue].stepFunction = .perVertex - return desc } @@ -62,8 +62,8 @@ class Terrain: NSObject { throw RendererError.badVertexDescriptor } attributes[VertexAttribute.position.rawValue].name = MDLVertexAttributePosition + attributes[VertexAttribute.normal.rawValue].name = MDLVertexAttributeNormal attributes[VertexAttribute.texcoord.rawValue].name = MDLVertexAttributeTextureCoordinate - attributes[VertexAttribute.gridCoord.rawValue].name = "Grid Coordinate" plane.vertexDescriptor = mdlVertexDescriptor