I modified the example program to map all the colors in the scene to a sphere centered on a camera using ray tracing.
After calculation I hope it can be saved in the file as a panorama.
I used the Fibonacci sphere to generate points on the sphere, and I only modified three places in the example program, but in the result, the box and the ground in the example program are gone, but I don’t know what went wrong with the three changes.
RT_PROGRAM void pinhole_camera()
{
size_t2 screen = output_buffer.size();
int N = screen.x*screen.y;
float var_n = (float)(launch_index.y*screen.x + launch_index.x);
float phi_point = (sqrt(5.0f) - 1.0f) / 2.0f;
float yn = (2.0f * var_n - 1.0f) / (float)N - 1.0f;
float zn = sqrt(1.0f - yn * yn)*cos(2.0f * M_PI*var_n*phi_point);
float xn = sqrt(1.0f - yn * yn)*sin(2.0f * M_PI*var_n*phi_point);
float3 ray_origin = eye;
float3 ray_target = xn * U + yn * V + zn * W;
float3 ray_direction = normalize(ray_target);
optix::Ray ray(ray_origin, ray_direction, RADIANCE_RAY_TYPE, scene_epsilon);
PerRayData_radiance prd;
prd.importance = 1.f;
prd.depth = 0;
rtTrace(top_object, ray, prd);
output_buffer[launch_index] = make_color(prd.result);
}
And I modified the setup camera.
void setupCamera()
{
camera_eye = make_float3(7.0f, 9.2f, -6.0f);
camera_lookat = make_float3(0.0f, 4.0f, 0.0f);
camera_up = make_float3(0.0f, 1.0f, 0.0f);
const float vfov = 60.0f;
const float aspect_ratio = static_cast<float>(width) /
static_cast<float>(height);
float3 camera_u, camera_v, camera_w;
sutil::calculateCameraVariables(
camera_eye, camera_lookat, camera_up, vfov, aspect_ratio,
camera_u, camera_v, camera_w, true);
camera_rotate = Matrix4x4::identity();
context["eye"]->setFloat(camera_eye);
context["U"]->setFloat(camera_u);
context["V"]->setFloat(camera_v);
context["W"]->setFloat(camera_w);
}
And main
int main(int argc, char** argv)
{
try
{
glutInitialize(&argc, argv);
#ifndef __APPLE__
glewInit();
#endif
createContext();
createGeometry();
setupCamera();
setupLights();
context->validate();
context->launch(0, width, height);
glutRun();
Buffer b_c = context["output_buffer"]->getBuffer();
uchar4* p_c = static_cast<uchar4*>(b_c->map());
FILE* filerec = fopen("D:\\Outputbuffer\\output3.txt", "w+");
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
fprintf(filerec, "%u %u %u %u\n", p_c[i*width + j].x, p_c[i*width + j].y, p_c[i*width + j].z, p_c[i*width + j].w);
}
}
fclose(filerec);
b_c->unmap();
return 0;
}
SUTIL_CATCH(context->get())
}
I deleted the series of operations of glut in main, is some parts here related to ray tracing, and did my deletion cause miss of all the rays?
Or did my cu file have a problem calculating the direction of the light?
Look forward to your reply