Created
September 25, 2019 18:26
-
-
Save Hurleyworks/a5798887b4e679fb8f0943615e8ed331 to your computer and use it in GitHub Desktop.
Optix7 pick ray programs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct PickParams | |
{ | |
int picking; | |
float3 rayOrigin; | |
float3 rayDir; | |
int32_t pickData[2]; | |
OptixTraversableHandle sceneAccel; | |
}; | |
enum RayType | |
{ | |
RAY_TYPE_PICK, | |
RAY_TYPE_COUNT, | |
}; | |
struct PickingPayload | |
{ | |
int32_t meshID; | |
int32_t primitiveID; | |
}; | |
//======================================================= | |
extern "C" { | |
__constant__ PickParams params; | |
} | |
static __forceinline__ __device__ void pick( | |
OptixTraversableHandle handle, | |
float3 ray_origin, | |
float3 ray_direction, | |
float tmin, | |
float tmax, | |
PickingPayload* payload | |
) | |
{ | |
uint32_t u0=0, u1=0; | |
optixTrace( | |
handle, | |
ray_origin, ray_direction, | |
tmin, | |
tmax, | |
0.0f, // rayTime | |
OptixVisibilityMask( 1 ), | |
OPTIX_RAY_FLAG_NONE, | |
RAY_TYPE_PICK, // SBT offset | |
RAY_TYPE_COUNT, // SBT stride | |
RAY_TYPE_PICK, // missSBTIndex | |
u0, u1); | |
payload->meshID = u0; | |
payload->primitiveID = u1; | |
} | |
extern "C" __global__ void __raygen__pickRay() | |
{ | |
if(!params.picking) {return;} | |
// trace pick ray | |
PickingPayload payload; | |
payload.meshID = -1; | |
payload.primitiveID = -1; | |
pick( | |
params.sceneAccel, | |
params.rayOrigin, | |
params.rayDir, | |
0.01f, // tmin // TODO: smarter offset | |
1e16f, // tmax | |
&payload ); | |
printf("Picked mesh: %i\n", payload.meshID ); | |
printf("Picked triangle: %i\n", payload.primitiveID); | |
params.pickData[0]= payload.meshID; | |
params.pickData[1]= payload.primitiveID; | |
} | |
extern "C" __global__ void __closesthit__pickHit() | |
{ | |
int primID = optixGetPrimitiveIndex(); | |
int instID = optixGetInstanceId(); | |
optixSetPayload_0( static_cast<uint32_t>( instID ) ); | |
optixSetPayload_1( static_cast<uint32_t>( primID ) ); | |
} | |
extern "C" __global__ void __miss__pickMiss() | |
{ | |
optixSetPayload_0( static_cast<uint32_t>( -1 ) ); | |
optixSetPayload_1( static_cast<uint32_t>( -1 ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment