Color format and color space issue in sample projects

Hello, I’ve noticed in most of the samples the MTKView default pixel format of .bgra8Unorm is used with the colorspace of nil (which means no color matching by the compositor). In contrast The official Metal examples from all set MKTView colorPixelFormat to .bgraunorm8_srgb

This results is that the samples render darker than I believe is intended because most displays are natively an sRGB format and the lack of color matching means the linear color space used in the samples is being treated as sRGB values by the display. E.g. a value of .5 is relatively bright in linear space but darker in sRGB space.

I recommend one of two things to improve how the samples look:

  1. set MTKView colorPixelFormat to .bgraunorm8_srgb like Apple does in their examples, or
  2. set MTKView colorspace to CGColorSpace(name: CGColorSpace.linearSRGB) so that the compositor know what space your output is in and can handle converting it to whatever the display expected.

(1) works well enough in most cases, but I believe (2) is technically more correct and can also pair well with (1) in more advanced use cases.

Compare these screenshots from the deferred rendering chapter. the left is from the default sample and the right is with colorspace set to linear:

Viewing the train model in the Xcode editor makes me think it is not intended to be so dark:

Thoughts?

1 Like

I’ll certainly review it. I can’t remember why I went with Data not Color for the baseColor textures in the asset catalog, which meant I used .bgraunorm8, but I do remember going back and forth on using .bgraunorm8_srgb in the early chapters, and then I stuck with it perhaps for longer than I should when doing the shadows etc.

Thank you for the suggestions. I do like the look of the brighter render better.