selfIntersectionAvoidance works perfect on triangle, so I’d like to also use it on curve and sphere.
For sphere, I am using a minor adjusted objPos, while objErr is derived from center and radius. Is that correct?
float c0 = 5.9604644775390625E-8f;
float c1 = 1.788139769587360206060111522674560546875E-7f;
float c2 = 1.19209317972490680404007434844970703125E-7f;
float4 q;
// sphere center (q.x, q.y, q.z), sphere radius q.w
optixGetSphereData( gas, primIdx, sbtGASIndex, 0.0f, &q );
float3& sphere_center = *(float3*)&q;
objPos = optixTransformPointFromWorldToObjectSpace(P);
objNorm = normalize( ( objPos - sphere_center ) / q.w );
objPos = sphere_center + objNorm * q.w;
float3 objErr = FMA( float3( c0 ), abs( sphere_center ), float3( c1 * q.w ) );
objOffset = dot( objErr, abs( objNorm ) );
SelfIntersectionAvoidance::transformSafeSpawnOffset( wldPos, wldNorm, wldOffset, objPos, objNorm, objOffset );
For curve, I found use curve center pos at u=optixGetCurveParameter() actually works in most case.
auto curveAttr = CurveAttributes( optixGetPrimitiveType(), primIdx );
objPos = curveAttr.center;
objNorm = curveAttr.normal;
float3 objErr = FMA( float3( c0 ), abs( curveAttr.center ), float3( c1 * curveAttr.radius ) );
objOffset = dot( objErr, abs( objNorm ) );
SelfIntersectionAvoidance::transformSafeSpawnOffset( wldPos, wldNorm, wldOffset, objPos, objNorm, objOffset );
Here is the confusing part, do we use objPos at hit surface or center for sphere / curve?


