I would like to use some non-PPM textures in my OptiX program.
In the SDK I’ve only found a Texture Sampler for PPM formatted textures.
In the documentation I found how to assign a texture sampler a buffer (or how to use optix bindless textures), but I find myself stuck at step 1: how do I get my non-PPM textures loaded in the first place?
(I might lack some basic understanding of implementing textures, since I have not worked with them on such a low level before.)
Thanks in advance for any help.
Loading an uncompressed TGA image is rather simple. You’ll find code on the web doing that.
Here’s the first hit when searching for that. (There’s no need for the GL types in the code if you’re not using OpenGL.)
If you know how to load a TGA image into host memory, this post explains how to fill an OptiX buffer with that data and how to create an OptiX TextureSampler using that buffer.
TGA is often RGB data only, actually BGR. CUDA doesn’t support three channel textures natively, so doesn’t OptiX. You would need to append an alpha channel in that case and upload that to an uchar4 typed buffer.
If you want to load other image format types, it’s more convenient if you use some image library which already handles the loading for you. I’m using DevIL in my applications.
Thanks. Those are helpful links and tips.
I’ve come across DevIL before and I’m looking into it now because of your advise. Their versions seem a bit messy. I’m currently using their SDK 1.7.8 from 2009, but noticed that it actually contains less (and different) files than the default download. Also there is ResIL and the 2014 GitHub DevIL (don’t know which version that is). Is there a specific one you could recommend?
I’m simply using the DevIL libraries which get installed inside the 3rdparty folder of our open source nvpro-pipeline.
I don’t actually know what DevIL version that downloads.
The nvpro-pipeline also contains C++ code which loads textures using DevIL, obviously. :-)
The function ILTexLoader::onLoad() starting in line 250 here:
contains all DevIL calls required to load an image.
You would just need to port those calls to your application and replace the code which puts the image data into a TextureHost class of our scene graph with code which puts it into OptiX buffers instead.
If you only load 2D images and no mipmaps or cubemaps, the two loops over numImages and numFaces collapse to one iteration each.
Don’t forget to call ilInit() at program start and and ilShutDown() at program end.
I’ve created a new image loader based on the PPMLoader and the DevIL SDK 1.7.8. I’ve named it ILLoader, and it works just like PPMLoader but it can be fed any file supported by DevIL (which is basically all major image formats).
Detlef, thanks again for your help.
If my ILLoader can be of use to any other beginners, I’d be happy to share it.