Chapter 11 Tessellation - load 32 bits displacement

Hello Metal authors,

I am trying to load a 32 bits displacement TIFF or EXR into asset catalog, using the technique described on section 6.7.

The problem is the asset catalog won’t accept the TIFF or EXR.

How can I make a 32 bits displacement on this chapter?

Thanks,
Alex

You should be able to load a 16 bit TIFF using an MTKTextureLoader?

https://developer.apple.com/documentation/metalkit/mtktextureloader

I can’t show you an EXR, but Apple have a recent sample of loading an HDR and using it as an equirectangular skydome:

https://developer.apple.com/documentation/metal/drawable_objects/displaying_hdr_content_in_a_metal_layer

It’s in Objective C. If you have a preference for Swift, I can have a go at extracting just the sky dome code and use it in the Environment chapter code instead of the cube map skybox.

Also, I’m not sure why you’d want to use a 32-bit texture for displacement here. The displacement value is grayscale from 0 to 1, and you displace on the y axis. So that only needs one channel.

1 Like

Thanks for the inputs! : )

“Also, I’m not sure why you’d want to use a 32-bit texture for displacement here. The displacement value is grayscale from 0 to 1, and you displace on the y axis. So that only needs one channel.”

My goal is to do displacement with all channels, and for that need 32-bit texture. Would it be possible to enable all channels on your code?

The current tessellation code only uses r for the height displacement.

Shaders.metal vertex_main:

  float height = (color.r * 2 - 1) * terrain.height;
  position.y = height;

If you filled g and b, you could use those for other directions. This doesn’t need a 32-bit texture.

But if you do want a 32-bit texture, you can create an empty MTLTexture from an MTLTextureDescriptor with a pixelFormat of rgba16Float. You can then copy a CGImage into the new texture. That’s what Apple’s HDR code link does.

1 Like

I just came across this forum post for loading EXR:

https://developer.apple.com/forums/thread/97186

Also:

https://developer.apple.com/forums/thread/97119

1 Like