# Jmages with alpha channel

**URL:** <https://forums.developer.nvidia.com/t/jmages-with-alpha-channel/32070>\
**Category:** OptiX\
**Created:** [January 23, 2014, 3:35pm UTC](https://forums.developer.nvidia.com/t/jmages-with-alpha-channel/32070 "2014-01-23T15:35:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![viginz](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@viginz](https://forums.developer.nvidia.com/u/viginz)\
**Post date:** [January 23, 2014, 3:35pm UTC](https://forums.developer.nvidia.com/t/jmages-with-alpha-channel/32070/1 "2014-01-23T15:35:33Z")

</div>

Hi,

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

---

<div class="post-metadata">

**Author:** ![droettger](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/droettger/32/14043_2.png) [@droettger](https://forums.developer.nvidia.com/u/droettger)\
**Post date:** [January 23, 2014, 4:02pm UTC](https://forums.developer.nvidia.com/t/jmages-with-alpha-channel/32070/2 "2014-01-23T16:02:07Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![viginz](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@viginz](https://forums.developer.nvidia.com/u/viginz)\
**Post date:** [January 24, 2014, 2:46pm UTC](https://forums.developer.nvidia.com/t/jmages-with-alpha-channel/32070/3 "2014-01-24T14:46:20Z")

</div>

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()?

---

<div class="post-metadata">

**Author:** ![droettger](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/droettger/32/14043_2.png) [@droettger](https://forums.developer.nvidia.com/u/droettger)\
**Post date:** [January 24, 2014, 3:09pm UTC](https://forums.developer.nvidia.com/t/jmages-with-alpha-channel/32070/4 "2014-01-24T15:09:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![viginz](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@viginz](https://forums.developer.nvidia.com/u/viginz)\
**Post date:** [January 27, 2014, 3:35pm UTC](https://forums.developer.nvidia.com/t/jmages-with-alpha-channel/32070/5 "2014-01-27T15:35:28Z")

</div>

Thank you very much!  
I will try.

---

<div class="post-metadata">

**Author:** ![TomNVIDIA](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/tomnvidia/32/14181_2.png) [@TomNVIDIA](https://forums.developer.nvidia.com/u/TomNVIDIA)\
**Post date:** [June 14, 2022, 9:12pm UTC](https://forums.developer.nvidia.com/t/jmages-with-alpha-channel/32070/6 "2022-06-14T21:12:04Z")

</div>


