Can't get optixprimepp to register a really simple hit (sample program inside!)

Hi all,

I’m a bit stuck with optix prime at the moment. I’ve basically used all of the API calls from the examples, and hardcoded a single triangle into my test program. I still can’t get a hit. My code is below, can anyone tell me what I am doing wrong ? I’m running out of things to try ;)

I compiled it using:

nvcc -std=c++11 -I/opt/optix/NVIDIA-OptiX-SDK-3.6.3-linux64/include -L/opt/optix/NVIDIA-OptiX-SDK-3.6.3-linux64/lib64 -loptix -loptix_prime test.cpp -o test
#include <optix_prime/optix_primepp.h>
#include <vector_types.h>
#include <iostream>

using Hit = struct HitStruct
{
  float t;
  int   triId;
  float u;
  float v;
};

using Ray = struct RayStruct
{
  float3 origin;
  float  tmin;
  float3 dir;
  float  tmax;
};

optix::prime::Context context;
optix::prime::Model model;

int main(void) {
  using namespace optix::prime;

  context = Context::create(RTP_CONTEXT_TYPE_CPU);
  model = context->createModel();
  float3 v1 {0, 3, 1};
  float3 v2 {-1, 3, -0.5};
  float3 v3 {1, 3, -0.5};
  float3 vlist[3] = {v1, v2, v3};
  int3 t1 {1, 2, 3};

  const int num_tris = 1;
  const int num_vertices = 3;

  model->setTriangles(num_tris, RTP_BUFFER_TYPE_HOST, &t1, num_vertices, RTP_BUFFER_TYPE_HOST, &vlist);
  model->update( 0 );

  // generate a ray at the origin in the y direction
  float3 origin {0, 0, 0};
  float3 direction {0, 1, 0};
  
  Ray r {origin, 0, direction, 1e8};
  Hit h;
  
  const int num_rays = 1;
  const int num_hits = 1;

  Query query = model->createQuery(RTP_QUERY_TYPE_CLOSEST);
  query->setRays(num_rays, RTP_BUFFER_FORMAT_RAY_ORIGIN_TMIN_DIRECTION_TMAX, RTP_BUFFER_TYPE_HOST, &r);
  query->setHits(num_hits, RTP_BUFFER_FORMAT_HIT_T_TRIID_U_V, RTP_BUFFER_TYPE_HOST, &h);
  query->execute(0);

  std::cout << h.t << std::endl;
  std::cout << h.triId << std::endl;
  std::cout << h.u << std::endl;
  std::cout << h.v << std::endl;
}

and for me, it prints out

-1
-1
0
0

I’m using CUDA 6.5 and Optix 3.6.3 on Ubuntu 14.04 x64 with the default gcc (4.8.2). I have compiled the SDK examples and they seem to work fine.

I’ve also attached two screenshots from meshlab that show the triangle should be hit by a ray from the origin in the y direction.

Thanks!

Edit: I have spent the last day trying to get CUDA6.0 running to test it with as another poster mentioned that OptiX was not compatible with CUDA6.5 (I couldn’t get it working). But while Nvidia don’t support running CUDA 6.0 on 14.04, Ubuntu don’t support 13.04 anymore. So I’m not really sure what to do here. Though, I don’t have the ability to replace the operating system anyway as this is a remote computer I am working on.

It doesn’t seem to me that CUDA 6.5 is the problem though, because I get no warnings/linker errors/exceptions.

Edit Edit: I got CUDA6.0 installed on 14.04 and the program behaves identically to CUDA6.5. So that isn’t the problem.


Ok, problem finally solved. model->setTriangles uses 0-indexed vertices, not 1-indexed. Could someone at NVIDIA please put this in the documentation? Lots of software outputs triangle meshes as 1-indexed; even the obj file format defines vertex 0 as invalid.

And for the record, to fix the code you need to change line 33 to:

int3 t1 {0, 1, 2};