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?
You should be able to load a 16 bit TIFF using an 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:
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.
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.
float height = (color.r * 2 - 1) * terrain.height;
position.y = height;
If you filled
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
rgba16Float. You can then copy a
CGImage into the new texture. That’s what Apple’s HDR code link does.