Load an OBJ in the PathTracer example

In the path tracer example in the SDK I want to add an OBJ file to trace, so I went over to the loadGeometry() function, and right after the last parallelogram creation, I added this code block

OptiXMesh mesh;
mesh.context = context;
loadMesh(mesh_file, mesh);
gis.push_back(mesh.geom_instance);
//setMaterial(gis.back(), diffuse, "diffuse_color", white);

note that “gis” is a “GeometryInstance” vector.

When I run it, the display window opens, and immediately closes and I get the following exceptions:

Exception thrown at 0x00007FFA2856A388 in optixPathTracer.exe: Microsoft C++ exception: optix::TypeMismatch at memory location 0x0000000E29EFF030.
Exception thrown at 0x00007FFA2856A388 in optixPathTracer.exe: Microsoft C++ exception: optix::Exception at memory location 0x0000000E29EFF5C0.

If I comment out the modified code block, it works fine.

How can I load an OBJ file to the tracer? Do I need to add something in the shaders / RT_PROGRAMs side?
Thank in advance!

P.S. I know that the loadMesh function takes care of the material, but since the program doesn’t work, I tried to set a material just like it’s shown for all the other GeometryInstances, as demonstrated in the code block above.

These host-side exceptions should come with descriptive error messages that should tell you more about what’s going on. Maybe try running the app from a cmd shell if you can’t find it in VS.

Found what you were asking for, the error description is:

OptiX Error: ‘Type mismatch (Details: Function “_rtContextLaunch2D” caught exception: Variable “lights” assigned type Buffer(1d, 60 byte element). Should be Buffer(1d, 32 byte element).)’

Not quite sure what it means by that…

the “lights” variable is added to the context in the following way:

// Light buffer
ParallelogramLight light;
light.corner = make_float3(343.0f, 448.6f, 227.0f);
light.v1 = make_float3(-130.0f, 0.0f, 0.0f);
light.v2 = make_float3(0.0f, 0.0f, 105.0f);
light.normal = normalize(cross(light.v1, light.v2));
light.emission = make_float3(1.0f, .5, 0);

Buffer light_buffer = context->createBuffer(RT_BUFFER_INPUT);
light_buffer->setFormat(RT_FORMAT_USER);
light_buffer->setElementSize(sizeof(ParallelogramLight));
light_buffer->setSize(1u);
memcpy(light_buffer->map(), &light, sizeof(light));
light_buffer->unmap();
context["lights"]->setBuffer(light_buffer);

And the “ParallelogramLight” struct is as follows

struct ParallelogramLight                                                        
{                                                                                
    optix::float3 corner;                                                          
    optix::float3 v1, v2;                                                          
    optix::float3 normal;                                                          
    optix::float3 emission;                                                        
};

Mixing and matching code from multiple OptiX SDK examples is not that easy because many of them have different material implementations which need to be adjusted.

In this case the “lights” on device side from the Phong shader used inside the optixMeshViewer is a BasicLight, but the “lights” variable in the optixPathTracer is a ParallelogramLight, which results in this validation error because the element size of the buffer is not matching the rtBuffer declarations in all your device code.

If you’re new to OptiX, I’d recommend you watch the OptiX introduction presentation and work through the open source examples.
Links here: [url]https://devtalk.nvidia.com/default/topic/998546/optix/optix-advanced-samples-on-github/[/url]

That explains how to setup triangle geometries step-by-step which helps to get arbitrary models loaded into some OptiX application.
It also explains how to implement an elegant architecture for a uni-directional path tracer with OptiX which supports more BSDFs which can be easily extended.
It’s probably more rewarding to add a custom OBJ geometry loader to that than to the optixPathTracer example.

1 Like

And now that you know what the error is, the message from the exception in retrospect is pretty descriptive, right?

OptiX Error: 'Type mismatch (Details: Function "_rtContextLaunch2D" caught exception: Variable "lights" assigned type Buffer(1d, 60 byte element). Should be Buffer(1d, 32 byte element).)'

Yeah thank you for that! Although I understand the error, still don’t know how to fix it just from looking at it :D

I’ll take Detlef Roettger’s advice and go through the advanced tutorials!

Thank you

So I see the examples use Optix 5, which is built on CUDA 9.
I have a GTX 1060 on my laptop, and I when I tried to install CUDA 9, my computer crashed bad to the point where I had to format it and reinstall windows… So I reverted back to CUDA 8, and therefore using OptiX 4.1.1

My question being, is there any way I can compile OptiX 5 apps with my GPU? Or maybe I made a mistake while installing CUDA 9 last time? It’s just too much of a risk to try to install it again

This is getting off topic, but my advice on installing CUDA is to NOT install the driver that comes with the toolkit. Install and manage the driver separately. That makes the problem a little more separable.

OptiX 5 versions require a display driver with CUDA 9.0 support.

If you install the CUDA 9.0 toolkit via the custom option where you should disable all display driver components first, and afterwards install the newest available display driver for your system, you should be fine.
(That there is a display driver inside the CUDA toolkit at all is one of my pet peeves. It’s outdated as soon as there is a released public driver with support for that CUDA version.)

You do not necessarily need to use the CUDA 9.0 toolkit to compile CUDA to PTX source code for OptiX 5.1.0, but I would highly recommend that.
Using CUDA 8.0 for that would be fine as well.
Have a look into the OptiX release notes document which lists multiple CUDA toolkit versions.

It’s more a matter of which host compiler is compatible to what CUDA toolkit for that choice and that in turn is listed inside the CUDA toolkit CUDA_Installation_Guide_.pdf documents in the resp. installation.
But it’s not always obvious what works together: [url]https://devtalk.nvidia.com/default/topic/1036401/?comment=5265110[/url]