2012-10-10 27 views
1

你好我正在使用Nvidia OptiX創建一個RayTracer。 我使用示例程序「sample0」和「tutorial」來設置一個簡單的示蹤器。Nvidia OptiX GeometryGroup

在我的C++代碼,我設置了一切:

this->buffer_height = 512u; 
this->buffer_width = 512u; 
char path_to_ptx[512]; 
_context = _context->create(); 
_context->setRayTypeCount(1); 
_context->setEntryPointCount(1); 
_context->setStackSize(4640); 
_context["radiance_ray_type"]->setUint(0); 
_context["scene_epsilon"]->setFloat(1.e-3f); 
_context["result_buffer"]->set(_context->createBuffer(RT_BUFFER_OUTPUT, RT_FORMAT_FLOAT4, this->buffer_width, this->buffer_height)); 

sprintf(path_to_ptx, "%s/%s", projectPath, "RayTracer_generated_draw_color.cu.ptx"); 
_context->setRayGenerationProgram(0, _context->createProgramFromPTXFile(path_to_ptx, "draw_solid_color")); 
_context["draw_color"]->setFloat(0.462f, 0.725f, 0.0f, 1.0f); 
_context["eye"]->setFloat(0.0f, 0.0f, 5.0f); 

_context->setMissProgram(0, _context->createProgramFromPTXFile(path_to_ptx, "miss")); 
_context["bg_color"]->setFloat(1.0f, 0.0f, 0.0f, 1.0f); 

sprintf(path_to_ptx, "%s/%s", projectPath, "RayTracer_generated_box.cu.ptx"); 
Program box_bounds = _context->createProgramFromPTXFile(path_to_ptx, "box_bounds"); 
Program box_intersect = _context->createProgramFromPTXFile(path_to_ptx, "box_intersect"); 

sprintf(path_to_ptx, "%s/%s", projectPath, "RayTracer_generated_draw_color.cu.ptx"); 

// This block must be full there. It is not possible just to create a geometry and not attach a program to it this would lead the program to crash when _context->compile(); 
Geometry gbox = _context->createGeometry(); 
gbox->setPrimitiveCount(1u); 
gbox->setBoundingBoxProgram(box_bounds); 
gbox->setIntersectionProgram(box_intersect); 
gbox["boxmin"]->setFloat(-2.0f, 0.0f, -2.0f); 
gbox["boxmax"]->setFloat( 2.0f, 7.0f, 2.0f); 

Material box_matl = _context->createMaterial(); 
Program box_ch = _context->createProgramFromPTXFile(path_to_ptx, "closest_hit_radiance0"); 
box_matl->setClosestHitProgram(0, box_ch); 

GeometryInstance geomIns = _context->createGeometryInstance(/* gbox, &box_matl, &box_matl+1 */); 
geomIns->setGeometry(gbox); 
geomIns->setMaterialCount(1u); 
geomIns->setMaterial(0, box_matl); 

GeometryGroup geomGrp = _context->createGeometryGroup(); 
geomGrp->setChildCount(1u); 
geomGrp->setChild(0, geomIns); 
geomGrp->setAcceleration(_context->createAcceleration("NoAccel","NoAccel")); 
//_context["target"]->set(geomGrp); 

_context->validate(); 
_context->compile(); 
_context->launch(0, buffer_width, buffer_height); 

this->imageData = _context["result_buffer"]->getBuffer()->map(); 
this->vboId = 0; 
rtBufferGetGLBOId(_context["result_buffer"]->getBuffer()->get() , &this->vboId); 

RTsize buffer_width_tmp, buffer_height_tmp; 

rtBufferGetSize2D(_context["result_buffer"]->getBuffer()->get() , &buffer_width_tmp , &buffer_height_tmp); 
this->width = static_cast<GLsizei>(buffer_width_tmp); 
this->height = static_cast<GLsizei>(buffer_height_tmp); 

我.CU程序是這樣的:

#include <optix.h> 
#include <optixu/optixu_math_namespace.h> 
#include "commonStructs.h" 

using namespace optix; 


// Variables of Context 

rtDeclareVariable(unsigned int, radiance_ray_type, ,); 
rtDeclareVariable(float, scene_epsilon, ,); 
rtDeclareVariable(rtObject, target, ,); 

rtBuffer<float4, 2> result_buffer; 

// Variables of RayGenerationProgram 
rtDeclareVariable(float3, eye, ,); 
rtDeclareVariable(float4, draw_color, ,); 

// Globals 
rtDeclareVariable(PerRayData_radiance, prd_radiance, rtPayload,); 
rtDeclareVariable(uint2, launch_index, rtLaunchIndex,); 
rtDeclareVariable(uint2, launch_dim, rtLaunchDim,); 
rtDeclareVariable(float3, shading_normal, attribute shading_normal,); 


RT_PROGRAM void draw_solid_color() 
{ 
    float2 d = make_float2(launch_index)/make_float2(launch_dim) * 2.f - 1.f; 

float3 U,V,W; 
U.x = 1.0; U.y = 0.0; U.z = 0.0; 
V.x = 0.0; V.y = 1.0; V.z = 0.0; 
W.x = 0.0; W.y = 0.0; W.z = -1.0; 

// Calc the ray Direction 
float3 ray_origin = eye; 
float3 ray_direction = normalize(d.x*U + d.y*V + W); 

// shoot the ray 
optix::Ray ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon); 

// Add ray Data 
PerRayData_radiance prd; 
prd.importance = 1.f; 
prd.depth = 0; 

//rtTrace(target, ray, prd); 

//result_buffer[launch_index] = make_float4(prd.result.x, prd.result.y, prd.result.z, prd.result.w); 

result_buffer[launch_index] = make_float4(abs(d.x), abs(d.y), 0.0f, 1.0f); 


} 

// 
// Returns solid color for miss rays 
// 
rtDeclareVariable(float4, bg_color, ,); 
RT_PROGRAM void miss() 
{ 
    prd_radiance.result = bg_color; 
} 


// 
// Returns shading normal as the surface shading result 
// 
RT_PROGRAM void closest_hit_radiance0() 
{ 
    float3 res = normalize(rtTransformNormal(RT_OBJECT_TO_WORLD, shading_normal))*0.5f + 0.5f; 
    float4 result; 
    result.x = res.x; 
    result.y = res.y; 
    result.z = res.z; 
    result.w = 1.0f; 
    prd_radiance.result = result; 
} 

就像我張貼,它工作正常和彩色圖畫是可見的,但你可能已經注意到// _ context [「target」] - > set(geomGrp);在C++代碼中。如果我取消註釋該程序在_context-> compile()中得到異常;

盒子程序與所有例子中的相同。

有沒有人有什麼想錯當我想將目標設置爲_context。

_context類似於#include中的上下文類型。

問候

編輯:發現更多關於異常:

_context->compile(); 

是optixx_namespace.h返回的結果爲

checkError(rtContextCompile(m_context)); 

快捷方式,在checkError檢查是一個RT_ERROR_INVALID_VALUE。

+0

我很樂意提供幫助,但我可能需要運行該應用程序。您可以向我們發送完整的源代碼(或如何將我們的一個示例轉換爲您的應用程序的完整說明)?請通過[email protected]與我們聯繫。如果您發送.zip文件,請將擴展名重命名爲.zi_。 David McAllister, OptiX Manager – 2012-10-14 03:55:51

+2

大家好,David McAllister,非常感謝你的報價。幸運的是我可以自己解決這個問題。我的問題是我的舊版CUDA 3.2和CUDA 5.0並排運行。 – rcpfuchs

+1

rcpfuchs:因爲它解決了你的問題,所以做出答案。 –

回答

1

幸運的是我可以自己解決這個問題。我的問題是我的舊版CUDA 3.2和CUDA 5.0並行運行。