

- CREATING MY OWN MODELIO DATA TYPES HOW TO
- CREATING MY OWN MODELIO DATA TYPES CODE
- CREATING MY OWN MODELIO DATA TYPES SERIES
The MDLTextureSampler type does not contain a texture that can be used by Metal directly rather, it contains image data in a format that can be easily loaded into a MTLTexture for drawing. texture and will have an MDLTextureSampler object as its textureSamplerValue property. The material property will then report its type as. The loadTextures() method iterates all of the materials in the asset and-if they are strings or URLs-loads their associated image data. In order to convert these properties into image data we can actually use in Metal, we need to ask the asset to resolve these references and load the corresponding image data: Each of these properties is initially stored as a string or a URL.
CREATING MY OWN MODELIO DATA TYPES CODE
The sample code uses this extensively: the model in the sample has separate textures for base color, roughness, metalness, and normals. Resolving Texture Properties into Image DataĪs mentioned previously, material properties can contain a texture that supplies a property value on a per-pixel basis. Let asset = MDLAsset(url: url, vertexDescriptor: nil, bufferAllocator: bufferAllocator) The reason for this will be explained below. Note that we provide a buffer allocator (to ensure the mesh data is Metal-compatible), but we don’t provide a vertex descriptor.

Let modelURL = (forResource: "scene", withExtension: "obj") There are numerous ways to create a ModelIO asset ( MDLAsset), but since the sample uses a model that is embedded in the app bundle, we’ll first ask the bundle for the URL of the model:

CREATING MY OWN MODELIO DATA TYPES SERIES
Joey de Vries’ series is probably the most approachable. PBR has been a hot topic for the past several years, and other people have written excellent tutorials on the subject. This is not a tutorial on physically-based rendering. You can find the sample code for this article here.
CREATING MY OWN MODELIO DATA TYPES HOW TO
Here, we’ll take a deep dive into ModelIO materials and learn how to use them to perform basic physically-based rendering (PBR). This ad hoc approach works when we only have a base color map, but quickly grows tedious as materials become more complicated. In previous articles, we’ve used ModelIO to do the heavy lifting of loading 3D geometry, but have loaded and applied textures manually. In this article, we’ll take a look at a portion of the ModelIO framework we haven’t used so far: materials.
