The complete raygen program:
extern "C" __global__ void __raygen__renderFrame()
{
const int ix = optixGetLaunchIndex().x;
PhotonPRD prd;
uint32_t seed = tea<4>(0,143);
const float r1 = rnd(seed);
const float r2 = rnd(seed);
const float k1 = r1 * 2 * M_PI;
const float k2 = (r2 *2) - 1;
const float theta = k1;
const float phi = acos(k2);
const float X = sin(phi) * cos(theta);
const float Y = sin(phi) * sin(theta);
const float Z = cos(phi);
const vec3f direction = vec3f(X,Y,Z);
vec3f origin = vec3f(1.2f,1.2f,1.2f);
prd.origin = origin;
prd.done = 0;
prd.absorbed = 0;
prd.escaped = 0;
prd.point = vec3f(0.0f,0.0f,0.0f);
prd.probability = 0;
prd.direction = direction;
uint32_t u0,u1;
packPointer( &prd,u0,u1);
optixTrace(optixLaunchParams.traversable, origin, direction,0.0f,1e20f,0.0f,OptixVisibilityMask( 255 ), OPTIX_RAY_FLAG_DISABLE_ANYHIT, SURFACE_RAY_TYPE, RAY_TYPE_COUNT, SURFACE_RAY_TYPE,u0,u1);
const vec3f interPoint = prd.point;
optixLaunchParams.pointBuffer[ix] = direction;
}
The code in the main.cpp:
sample.render();
sample.downloadPoints(points.data());
std::ofstream ofile;
ofile.open("output.csv", std::ios::app);
for(int i =0; i<5000;i++)
{
ofile << points[i].x <<","<<points[i].y<<","<<points[i].z <<std::endl;
}
ofile.close();
The buffers for launchParameters(I am also using the CUDABuffer.h from Ingo Wald’s tutorial code):
LaunchParams launchParams;
CUDABuffer launchParamsBufer;
CUDABuffer pointBuffer;
My LaunchParams.h structure:
struct LaunchParams
{
vec3f *pointBuffer;
uint32_t *events;
vec2i size;
OptixTraversableHandle traversable;
};
The download function(used in main):
void Simulator::downloadPoints(vec3f h_points[])
{
pointBuffer.download(h_points,launchParams.size.x*launchParams.size.y);
}
I don’t think the random function is the problem as when I tried to output (r1,r2,0), the first instance was correct but for the rest, even 0 has been replaced with some value.
My render function(used in main.cpp, above):
void Simulator::render()
{
if (launchParams.size.x == 0) return;
launchParamsBuffer.upload(&launchParams,1);
OPTIX_CHECK(optixLaunch(pipeline,stream,
launchParamsBuffer.d_pointer(),
launchParamsBuffer.sizeInBytes,
&sbt,
launchParams.size.x,
launchParams.size.y,
1
));
CUDA_SYNC_CHECK();
}