Group Group Group Group Group Group Group Group Group

Material files question

Hi! Was playing around again, and was wondering, in chapter 24 the example project, there are trees and rocks etc as resources to render. These all have .mtl files. The files of the trees have a roughness an metallic property. But these each have three values per property? I only know these as single channel textures normally, so what would these other two values do?

roughness 1.0 1.0 1.0
metallic 1.0 1.0 1.0

What I find even more confusing is that we extract the metallic value from the .mtl file using:

if let metallic = material?.property(with: .metallic),
        metallic.type == .float3 {
        self.metallic = metallic.floatValue
}

So we check if the property is a float3 and then get a float value from it?

Changing the .mtl file to just say metallic 1.0 and setting the type check to .float results in always reading out 0.0 from the property. I have no idea why that is.

The same confusion holds for roughness btw. Help would be greatly appreciated!

Yes - I remember trying to grasp this myself. There isn’t a lot of documentation around this area, and MDLMaterial is quite a complicated structure.
I just accepted this as being part of the requirements of the API. roughness and metallic values are 3 floats and that’s it. Generally I would provide textures for those properties instead.

Allright thanks, I’ll just accept that it’s a little weird and indeed not very much documentation. Thanks! Any updates for the metal book in the pipeline? ^^ I still enjoy it and keep coming back to it.

We updated the book after last WWDC, latest edition is October 2019. If WWDC happens this year, and if there’s enough change and enough interest, we hope to be updating it again :slight_smile:

2 Likes