Jmages with alpha channel

Hi,

can someone give me advice to implement in OptiX Images with alpha-channel, for example PNG-images?

Are you asking for code how to load these images into textures or how to handle the alpha information inside the textures in the CUDA programs?

If you’re asking for cutout opacity (alpha test) that would be a simple check in the any_hit and any_hit_shadow programs of the material to call rtIgnoreIntersection() when the material opacity is below some threshold. Pseudo code:

RT_PROGRAM void anyhit()
{
  if (getOpacity() < 1.0f)
  {
    rtIgnoreIntersection();
  }
}

If you’re asking for something similar to alpha blending you could use the opacity as weight between reflective and transmissive rays.

If you want to capture that information inside the output buffer for following compositing (will look incorrect with refractive materials) you would need to track an alpha value along purely transparent ray paths and write the result into the output buffer.

Thank you for answer.
I see the examples and try to undestand. I see in PPMLoader.cpp (in sutil), that optix::Buffer has format RT_FORMAT_UNSIGNED_BYTE4. So it will be possible to load also image with alpha channel.
But how to get information about alpha channel value in this buffer in closest_hit_radiance()?

The easiest way would be to upload it as a texture and just read it at the coordinates you like.

Please read the OptiX Programming Guide chapter 3 on Buffers and Textures.
It contains code describing the upload and the access.
The alpha value would be the w-component of your data.

Thank you very much!
I will try.