Thanks. I looked into translateMeshToOptiX() but still not sure why my program crashes if I don’t attach any material.
//bool have_textures = false;
//for( int32_t i = 0; i < mesh.num_materials; ++i )
// if( !mesh.mat_params[i].Kd_map.empty() )
// have_textures = true;
//optix::Program closest_hit = optix_mesh.closest_hit;
//optix::Program any_hit = optix_mesh.any_hit;
//createMaterialPrograms( ctx, have_textures, closest_hit, any_hit );
//for( int32_t i = 0; i < mesh.num_materials; ++i )
// optix_materials.push_back( createOptiXMaterial(
// ctx,
// closest_hit,
// any_hit,
// mesh.mat_params[i],
// have_textures ) );
std::string ptx_path("E:/VCM/VCM/build/lib/ptx/optixPathTracer_generated_optixPathTracer.cu.ptx");
optix::Material glass = ctx->createMaterial();
optix::Program glass_ch = ctx->createProgramFromPTXFile(ptx_path, "glass_closest_hit_radiance");
optix::Program glass_ah = ctx->createProgramFromPTXFile(ptx_path, "shadow");
glass->setClosestHitProgram(0, glass_ch);
glass->setAnyHitProgram(1, glass_ah);
memset( mesh.mat_indices, 0, mesh.num_triangles*sizeof(int32_t) );
optix_materials.push_back( glass );
If I comment the code in translateMeshToOptiX() which assigns a default Phong material to my mesh which doesn’t have any material and instead use a glass material as the default material, my program works well.
What’s wrong with the default Phong material?
The error I get is like this:
OptiX Error: 'Type mismatch (Details: Function "_rtContextValidate" caught excep
tion: Variable "lights" assigned type Buffer(1d, 60 byte element). Should be Bu
ffer(1d, 32 byte element).)'
It seems like it’s affecting my next buffer.
The following is the code of my .cpp file:
OptiXMesh mesh;
std::string filename = std::string(sutil::samplesDir()) + "/data/cow.obj";
mesh.context = crtContext;
loadMesh(filename, mesh, Matrix4x4::translate(make_float3(250.f, 180.f, 250.f)) * Matrix4x4::scale(make_float3(50.f)));
gis.push_back(mesh.geom_instance);
// Light
gis.push_back( createParallelogram( make_float3( 343.0f, 548.6f, 227.0f),
make_float3( -130.0f, 0.0f, 0.0f),
make_float3( 0.0f, 0.0f, 105.0f), crtContext) );
setMaterial(gis.back(), diffuse_light, "emission_color", light_em);
// Create geometry group
GeometryGroup geometry_group = crtContext->createGeometryGroup(gis.begin(), gis.end());
//geometry_group->addChild(mesh.geom_instance);
geometry_group->setAcceleration( crtContext->createAcceleration( "Trbvh" ) );
crtContext["top_object"]->set( geometry_group );