Hi all,

I’m writing a renderer in optix 7 originally based on the Siggraph Course from Ingo Wald. I want to implement a transparency setting which makes a ray skip the first hit on a geometry if the geometry is set to be transparent.

I think a good option is to use an anyhit program and a payload on the ray which counts how many times the ray has hit a transparent geometry. I’ve implemented it like this (all geometry that is not transparent has the OPTIX_GEOMETRY_FLAG_DISABLE_ANYHIT flag):

```
extern "C" __global__ void __anyhit__radiance()
{
unsigned int hitcount = getPayloadWindow();
if (hitcount < 1)
{
setPayloadWindow(hitcount + 1);
optixIgnoreIntersection();
}
else
optixTerminateRay();
}
```

But this gives me artifacts on the transparent faces:

Here’s a render without transparency:

Also here is my current workaround in the closest hit program where I instead retrace the ray on the other side of the face (Adds about 50% computetime compared to anyhit in my usecase):

```
if (sbtData.transparent && getPayloadWindow() < 1)
{
const float u = optixGetTriangleBarycentrics().x;
const float v = optixGetTriangleBarycentrics().y;
const vec3f surfPos
= (1.f - u - v) * sbtData.vertex[index.x]
+ u * sbtData.vertex[index.y]
+ v * sbtData.vertex[index.z];
vec3f pixelColorPRD = vec3f(0.f);
uint32_t u0, u1, u2,
packPointer(&pixelColorPRD, u0, u1);
u2 = getPayloadWindow() + 1;
optixTrace(optixLaunchParams.traversable,
surfPos + 1e-3f * rayDir,
rayDir,
0.f, // tmin
1e20f, // tmax
0.0f, // rayTime
OptixVisibilityMask( 255 ),
OPTIX_RAY_FLAG_DISABLE_ANYHIT,//OPTIX_RAY_FLAG_NONE,
SURFACE_RAY_TYPE, // SBT offset
RAY_TYPE_COUNT, // SBT stride
SURFACE_RAY_TYPE, // missSBTIndex
u0, u1, u2);
prd = pixelColorPRD;
}
```

But gives the output I’m looking for:

Any help would be much appreciated!