Hello Caroline, I notice a detail in page 123 of the book (I got the book from Amazon not PDF version).
I wanna know how to let me make sure whether .obj file does contain surface normal. And if it does contain surface normal, whether using " mdlVertexDescriptor.attributes[ i ] = MDLVertexAttribute(name:,format:offset:bufferIndex:) " can pass normal to MSL function.
1 Like
You make sure that obj files you use have normals.
If you know that they won’t, you can recreate them. I don’t have the printed book, but just above the section “Add normals to vertex descriptor”, it tells you that you can generate normals using MDLMesh
’s addNormals(withAttributeNamed:creaseThreshold:)
.
If a model is built correctly by the 3d app which created it, then it should have normals.
When you have normals, that same section “Add normals to vertex descriptor” tells you that you add them to the vertex descriptor attributes. The next section tells you how to add the normal attribute to the shader.
1 Like