Skip to content

Commit

Permalink
Encapsulate perRayData.
Browse files Browse the repository at this point in the history
  • Loading branch information
gonsolo committed Oct 12, 2023
1 parent a641183 commit 39154e2
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions Sources/cudaBridge/devicePrograms.cu
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,16 @@ namespace osc {
// one group of them to set up the SBT)
//------------------------------------------------------------------------------

struct PerRayData {
vec3f pixelColor;
};

extern "C" __global__ void __closesthit__radiance()
{
const int primID = optixGetPrimitiveIndex();
vec3f &prd = *(vec3f*)getPRD<vec3f>();
prd = gdt::randomColor(primID);
//vec3f &prd = *(vec3f*)getPRD<vec3f>();
PerRayData &prd = *(PerRayData*)getPRD<PerRayData>();
prd.pixelColor = gdt::randomColor(primID);
}

extern "C" __global__ void __anyhit__radiance()
Expand All @@ -86,9 +91,10 @@ namespace osc {

extern "C" __global__ void __miss__radiance()
{
vec3f &prd = *(vec3f*)getPRD<vec3f>();
//vec3f &prd = *(vec3f*)getPRD<vec3f>();
PerRayData &prd = *(PerRayData*)getPRD<PerRayData>();
// set to constant white as background color
prd = vec3f(1.f);
prd.pixelColor = vec3f(1.f);
}

//------------------------------------------------------------------------------
Expand All @@ -105,11 +111,13 @@ namespace osc {
// our per-ray data for this example. what we initialize it to
// won't matter, since this value will be overwritten by either
// the miss or hit program, anyway
vec3f pixelColorPRD = vec3f(0.f);
//vec3f pixelColorPRD = vec3f(0.f);
PerRayData perRaydata = { vec3f(0.f) };

// the values we store the PRD pointer in:
uint32_t u0, u1;
packPointer( &pixelColorPRD, u0, u1 );
//packPointer( &pixelColorPRD, u0, u1 );
packPointer( &perRaydata, u0, u1 );

// normalized screen plane position, in [0,1]^2
const vec2f screen(vec2f(ix+.5f,iy+.5f)
Expand Down Expand Up @@ -137,9 +145,12 @@ namespace osc {
SURFACE_RAY_TYPE, // missSBTIndex
u0, u1 );

const int r = int(255.99f*pixelColorPRD.x);
const int g = int(255.99f*pixelColorPRD.y);
const int b = int(255.99f*pixelColorPRD.z);
//const int r = int(255.99f*pixelColorPRD.x);
//const int g = int(255.99f*pixelColorPRD.y);
//const int b = int(255.99f*pixelColorPRD.z);
const int r = int(255.99f*perRaydata.pixelColor.x);
const int g = int(255.99f*perRaydata.pixelColor.y);
const int b = int(255.99f*perRaydata.pixelColor.z);

// convert to 32-bit rgba value (we explicitly set alpha to 0xff
// to make stb_image_write happy ...
Expand Down

0 comments on commit 39154e2

Please sign in to comment.