Hello.
I am learning optixTutorial in the sample of optiX.
It is understood that the distance data to the starting point and solid obtained by ray tracing is stored in prd.result.
I want to obtain the distance information in the main function side, but I do not know how.
Would you please tell me.
Please have a look into the OptiX Introduction examples inside the OptiX Advanced Samples on github.
Links here: [url]https://devtalk.nvidia.com/default/topic/998546/optix/optix-advanced-samples-on-github/[/url]
In example 07 it added the distance to the rtPayload structure.
This is it inside the rtPayload structure:
[url]optix_advanced_samples/per_ray_data.h at master · nvpro-samples/optix_advanced_samples · GitHub
This is where it’s returned by the closest hit program:
[url]optix_advanced_samples/closesthit.cu at master · nvpro-samples/optix_advanced_samples · GitHub
This is where it’s initialized and used for the primary ray and next path segments:
[url]optix_advanced_samples/raygeneration.cu at master · nvpro-samples/optix_advanced_samples · GitHub
[url]optix_advanced_samples/raygeneration.cu at master · nvpro-samples/optix_advanced_samples · GitHub
Here the last ray’s returned distance is used for volume absorption calculations:
[url]optix_advanced_samples/raygeneration.cu at master · nvpro-samples/optix_advanced_samples · GitHub
If you want to store that distance information, all output from OptiX is via output or input_output buffers.
You would need to create a buffer of floats which you could write to, similar to the color results of the image.
Thank you for your reply. The information on rtPerload was helpful.
Rewrite tutorial0’s cpp like this:
buffer = sutil::createOutputBuffer(context, RT_FORMAT_FLOAT, width, height, use_pbo);
context[“output_buffer”]->set(buffer);
Rewrite cu like this.
rtBuffer<float,2> output_buffer;
output_buffer[launch_index] = 1.0;
If you do the above process, I think that 1.0 will be stored in all two-dimensional array in the buffer on cpp side.
I do not know how to refer to the stored value (1.0 in this case) using buffer in cpp.
I am sorry for the basic questions.
Reading from OptiX RT_BUFFER_OUTPUT or RT_BUFFER_INPUT_OUTPUT or writing to RT_BUFFER_INPUT or RT_BUFFER_INPUT_OUTPUT buffers on the host always requires these three steps:
map the buffer,
read from or write to the memory via the pointer (which is only valid while the buffer is mapped and could change on every map!),
unmap the buffer before the next launch or validation will fail.
This happens in basically every non-trivial OptiX application because there is no other way to get data out from OptiX than via buffers.
Just search for “unmap” inside the examples’ source code and you’ll find them.
If you’re a beginner with OptiX, please watch my GTC 2018 OptiX introduction presentation and work through the OptiX Introduction examples step by step in the OptiX Advanced Samples on github as linked above.
GTC 2018 S8518 - An Introduction to NVIDIA OptiX [url]http://on-demand-gtc.gputechconf.com/gtc-quicklink/4JAjAp[/url]
Then watch the GTC 2019 presentation from David Hart about new features in OptiX 6.0.0.
GTC 2019 S9768 - New Features in OptiX 6.0 [url]http://on-demand-gtc.gputechconf.com/gtc-quicklink/4FB3l[/url]
Thank you very much.
I got one step closer to the solution.