Defining position of camera and geometry in Prime

Hello,

I am having issues with placing the geometries and defining the camera in OptiX Prime.
In OptiX I can place objects over a transformation matrix with the command mesh.setLoadingTransform() and I can set the camera with e.g. context[“eye”]->setFloat(1.2)
In prime the command examples shown above are not supported so I was wondering if there are any similar commands which makes it possible to change the position of the camera and the objects?

Thank You!

In OptiX Prime you fill query buffers with a number of rays. How to generate these rays is completely the developer’s responsibility!
Actually it’s also your responsibility in OptiX because you need to define the ray generation program.

For the primary rays you could for example write a routine for the host CPU or as CUDA kernel which does that for any kind of camera projection you need., including any camera parameters you’d like.

Code how to do that can be found inside the OptiX SDK examples with “prime” in the name.
For example look for “createRaysOrthoOnDevice” or “createRaysPerspOnDevice” inside OptiX SDK 3.9.1\SDK\primeSimple\primeKernels.cu

In OptiX Prime you normally pre-transform all geometry into world coordinates because it basically only understands triangle soups and no complex scene hierarchy like the high-level OptiX API, except for a single level transform hierarchy which can be used for instancing identical objects. Look at the OptiX Prime instancing example “primeInstancing”.

Thank you for your quick response! I could solve the camera issue but I do not know exactly how to solve the transformation problem. Do you have any recommendation how I still could transform the geometry (since I don’t have it given in world coordinates)? Maybe I can generate an instance of the object, using the right transformation matrix and then destroy the actual object, would this be possible?

Again, have you looked at the example primeInstancing?

That example shows exactly what you’re asking for in about 100 lines of code with comments.
Read the code or build it as debug and single step through it inside the debugger.
It doesn’t get simpler than that. Even the OptiX Programming Guide Chapter 9 refers to it.

The primeInstancing example uses 12 base models and builds 10000 instances by default.
If you don’t have duplicate instances to place into the scene, then simply do what primeInstancing does just let it be N different base models and N instances via transform matrices building your scene.

Still, if the scene is static and has not many real instances of identical geometry, ray intersection performance should be faster if you pre-transform the vertex positions into world coordinates yourself before building the scene model.

Thank you again for your quick answer and for your patience ;)

Unfortunately it is not possible to step completely through the primeInstancing example in debug mode. For some reason I get following exception in the primeInstancing.cpp

line 189:  meshes[i].loadModel(filenameBase + filenames[i]);

-> Unhandled exception at 0x000007feda3801cb (sutil.dll) in primeInstancing.exe: 0xC0000005: Access violation reading location 0xffffffffffffffff.

The exception points to the HostMesh.cpp, line 28:

line 28: void HostMesh::loadModel( const std::string& filename ) { m_impl->loadModel(filename); }

After a long search, I still could not figure out what the problem is. Is that a mistake in the sample code or is it a specific error on my computer settings or properties?

Have you built the sutil library as debug as well?
If not, exchanging C++ std containers across the DLL border will not work due to different allocators used in release and debug mode by the compiler and access violations like these are to be expected.
If your sutil library is built as debug version, you should be able to step into all the functions you listed if there is still an error afterwards.

You need to setup the OptiX SDK sample projects with the topmost CMakeLists.txt in OptiX SDK 3.9.1\SDK
It’s worth reading the comments in that as well.
Just rebuild all projects in debug mode. You’ll need to debug through some more examples later to get a grip of what’s necessary to use OptiX Prime optimally.

Yes the sutil library is also built as debug version.
I generated the OptiX-Samples VS Project as described in the Install document. It is possible to compile all samples and it also works to debug the other prime Samples so I assume that the setup should be alright. Only the primeInstancing throws the exception while debugging. There seems to be an issue with the lines:

line 163: std::vector<PrimeMesh> meshes; 
...
line 189: meshes[0].loadModel(objFilename);

Loading a model into the meshes vector throws the exception. I also changed the code at some places (gave the vector a fixed size / wrote the path of the obj file directly into loadModel() etc.) but it still gives me the same error.

Loading a geometry into a single mesh

PrimeMesh mesh;
mesh.loadModel(objFilename);

as in the other examples works totally fine so I assume that there is an issue with the meshes vector.

I can’t reproduce this behaviour.

I just built and debugged though a fresh install and build of only the primeInstancing sample and the sutil library of OptiX 3.9.1. I did not copy anything around or touched any code. Just built Debug x64 and started the debugger with F11.

There was no problem whatsoever running with empty objFilename or with an --obj on the command line. I tried some of the fishes in the swimmingShark example.

The steps were exactly as described in the INSTALL-WIN.txt file.
I use OptiX 3.9.1 installed to “S:/sdk/OptiX 3.9.1” (not “Program Files” because that is protected), CUDA 7.5, and MSVS Professional 2013.
Newer toolkit and compiler versions are not supported, yet.

What exactly is your configuration?
OS version, installed GPU(s), display driver version, OptiX version, CUDA toolkit version, host compiler version?

It shouldn’t matter if the model is assigned to a PrimeMesh variable or to a PrimeMesh element in a vector if that has been resized properly, which it is in the original code.
If it’s in a vector the allocator has been used and this could still be a debug app vs. release sutil mixup. You can debug into the loadModel() routine, right?

Nothing I can do to dry debug this more with the given information.

I reinstalled the OptiX Samples Project - still the same error while debugging primeInstancing.

I am using OptiX 4.0.0, CUDA 7.5, VS Professional 2010 on a Windows 7 with a Quadro K2100M, Driver version 368.39.

I can only step into loadModel() if a mesh variable is used (like in e.g. primeSimple). If a mesh vector is used like in primeInstancing I cannot jump into the loadModel routine and the error occurs.

Means there are two more things you can try:

Use the stable release OptiX 3.9.1, which I recommend for application development at this time.
The OptiX 4.0.0 beta 1 is for early tests of the newer OptiX core architecture.

If that shows the same problem, then it points to a bug inside MSVS 2010.
In that case you would need to upgrade to MSVS 2012 or 2013 (recommended).
MSVS 2015 isn’t supported with CUDA 7.5, and that’s the newest CUDA version supported by OptiX.

Note that MSVS 2010 support is deprecated in CUDA 7.5. See CUDA_Installation_Guide_Windows.pdf in the CUDA 7.5 doc\pdf folder.

Sidenote: When running on an Optimus capable laptop, make sure graphics apps run on the discrete GPU, also for the MSVS IDE during debugging. That might not matter for the simple OptiX Prime examples which default to CPU intersections, but make sure you’ll get GPU acceleration when needed.

very good point, I use something like this :

included.h

#ifdef WIN32
#	define OPENGL_ON_GPU_NOT_CHIPSET		extern "C" { _declspec(dllexport) unsigned int NvOptimusEnablement = 0x00000001; }
#else
#	define OPENGL_ON_GPU_NOT_CHIPSET
#endif //WIN32

main.cpp

OPENGL_ON_GPU_NOT_CHIPSET;

//
int main(int argc, char **argv)
{
    ...
}

source : http://stackoverflow.com/a/14041061

I installed OptiX 3.9.1 which did not solve the problem. After installing MSVS 2013 everything worked perfectly so it seems to be a bug in VS 2010.

Thank you again for your help and for the sidenotes - I will keep them in mind!