

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:
Modelio alternitave code#
These various property values are used by renderers such as SceneKit and the renderer in this article’s sample code to determine how each point on a surface should be shaded. On the other hand, if roughness varies over the surface, the value of the roughness material property could be a file URL that refers to a texture map containing a different roughness value for each pixel. For example, if a material should have uniform roughness, its value could be a single float.


In ModelIO, many of these properties can take on different types of values. Many of these may be familiar from the so-called Disney BRDF, popularized by Brent Burley: The parameters of the Burley PBR model enable intuitive authoring of a significant variety of realistic materials. Take a look at the MDLMaterialSemantic enum to get acquainted with some of the properties a material can have. Each property also has a semantic, which indicates how it should be used. Each material property contains a value, which can be a float, a vector of floats, a color, a string or file URL, a texture, etc. A ModelIO material contains a list of material properties (each an instance of MDLMaterialProperty). The main class we’ll use from ModelIO is MDLMaterial.

Each of these formats represents materials differently, so ModelIO provides an abstraction that generalizes over all of them. ModelIO is a remarkably flexible framework that allows us to easily load 3D models in a variety of formats, including Alembic (.abc), USD (.usd. An example asset rendered by SceneKit, from the 2016 WWDC Session, Advances in SceneKit Rendering () For this reason, the shaders for this article are a pared-down version of Apple’s LOD with Function Specialization sample, which is worth studying. The focus here is on how ModelIO represents materials, deemphasizing how a shader might render them. For more theoretical background, consult the following papers and resources: Also consider taking a look at the documentation for Google’s brand-new mobile-first rendering engine Filament.
Modelio alternitave 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.
Modelio alternitave 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.
