Lachei / VulkanPBRT

Vulkan physically based raytracer including denoising
MIT License
28 stars 11 forks source link

OpenEXR image IO #10

Closed Lachei closed 2 years ago

Lachei commented 2 years ago

This PR adds the ability to import and export openEXR images. Integration was done by expanding the vsgXChange class to also support an openexr reader writer. The integration is in line with other vsgXchange classes.

Reading an exr file can be done by auto exrOptions = vsg::Options::create(vsgXchange::openexr::create()); auto exrImage = vsg::read(filename, exrOptions); // alternative: vsg::read_cast<vsg::Class>(filename) . To write a file use the exrOptions object from above with bool exported = vsg::write(exrImage, "test.exr", exrOptions); , where exported holds if the export was successful.

Single channel images are read into single channel vsg::2dArrays, while multi channel images with a maximum of 4 channels are always stored in 4 component 2d Arrays. This is done to avoid problems with 3 channel images which do not map automatically to any vulkan buffer format (only 4 component formats are available, except a special 3 component 32 bit format). The conversion to a vulkan buffer then always has to be done by hand. Half precision images are read into an uint16_t type array, as no generic half precision floating point type exists. If the data is copied as is to half precision vulkan buffers this should result in a correct half precision vulkan buffer. For processing on the cpu care has to be taken. Float precision and uint32_t precision are imported correctly and the resulting array has the correct type.

This PR adds the OpenEXR Required constraint to cmake, so the OpenEXR library has to be installed and found in order for this PR to build.

This PR is only tested currently on Linux, Windows test is required before merging.