Some question about save buffer to a file

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) /

	float3 camera_u, camera_v, camera_w;
		camera_eye, camera_lookat, camera_up, vfov, aspect_ratio,
		camera_u, camera_v, camera_w, true);

	camera_rotate = Matrix4x4::identity();

And main

int main(int argc, char** argv)

		glutInitialize(&argc, argv);

#ifndef __APPLE__

		context->launch(0, width, height);
		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);

		return 0;

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

You changed which OptiX example exactly?

The yn calculation looks suspicious. Normally a calculation 2.0f * x - 1.0f is used to scale a value in the range [0, 1] into the range [-1, 1] but your var_n is the linear launch index which is in the range [0, N] in your code

Did you mean to do this:

float var_n = (float)(launch_index.y * screen.x + launch_index.x) / float(N);
float yn = 2.0f * var_n - 1.0f;


float var_n = (float)(launch_index.y*screen.x + launch_index.x); 
float yn = 2.0f * var_n / float(N) - 1.0f;

In any case, the OptiX Introduction examples demonstrate different lens shader implementations which can switched at runtime and one of them is a spherical projection using the standard pinhole camera variables.

All related OptiX Advanced Samples links here:

When trying to build these examples with MSVS 2017, you might want to delete the FindCUDA.cmake file inside the OptiX Advanced Samples and use the one which comes with CMake insead. That will correctly setup the CUDA_HOST_COMPILER path.
Otherwise you need to set it manually:

1 Like

Sorry for not replying to your message in time. I will consider whether the model of the program is correct.When I tried to compile the OptiX Advanced Samples you gave me, the SLN file generated by cmake opened and the program ran with “CMD. Exe exited with code 1”.On Google, some said that the path problem, as well as version of the problem, I did not find a suitable solution for this error.

What is your development system configuration?
OS version, installed GPU(s), VRAM amount, display driver version, OptiX major.minor.micro version, CUDA toolkit version used to generate the input PTX, host compiler version, CMake version?

If you’re using MSVS 2015, OptiX 6.0.0, and CUDA 9.0 that should just work.
If you’re using MSVS 2017, OptiX 6.0.0, and CUDA 10.0 that should also work after following the steps I provided in the last link above.

Also if you can build the OptiX 6.0.0 SDK examples, you should also be able to build the OptiX Advanced Samples.

Thanks for your reply, why I didn’t receive an email reminder from the website, I haven’t seen your reply until now. I successfully ran the advance samples as you last suggested. thanks for your help.

On the e-mail notifications, check if the “Follow” button in the top right of this page is enabled, which is the case when it’s grey and says “Unfollow”.
You might want to subscribe to the RSS feed of this OptiX sub-forum to get all new posts. Read the actual web-site content then to not miss potential edits.