Skip to content

Instantly share code, notes, and snippets.

View JaapWijnen's full-sized avatar

Jaap Wijnen JaapWijnen

View GitHub Profile
@JaapWijnen
JaapWijnen / normals.swift
Created June 23, 2019 21:37
recalculating normals
// I'm rendering a subdivided quad of resolution x resolution vertices
let vertex = Vertex(position: position, normal: float3(0,0,0), texture: float2(0,0))
vertices.append(vertex)
// vertices are stored in a vertices array, same for indices
// for every vertex but the last row and column we want to create two triangles
if x != resolution-1 && y != resolution-1 {
self.indices.append(contentsOf: [
UInt16(i), UInt16(i + resolution), UInt16(i + resolution + 1), // triangle 1
UInt16(i), UInt16(i + resolution + 1), UInt16(i + 1) // triangle 2