首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nvidia OptiX GeometryGroup

Nvidia OptiX GeometryGroup
EN

Stack Overflow用户
提问于 2012-10-10 22:47:55
回答 1查看 1.4K关注 0票数 1

你好,我正在使用Nvidia OptiX创建一个RayTracer。我使用示例程序"sample0“和"tutorial”设置了一个简单的跟踪程序。

在我的C++代码中,我使用以下命令设置所有内容:

代码语言:javascript
复制
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程序如下所示:

代码语言:javascript
复制
#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;
}

就像我发布的一样,它工作得很好,并且可以看到一张彩色图片,但是您可能已经注意到c++代码中的//_context“->set”目标( geomGrp );。如果我取消注释,程序在_context->compile()中获得异常;

Box程序与所有示例中的程序相同。

有人知道当我想要将目标设置为_context时,哪里出了问题吗?

_context的类型类似于#include中的上下文。

诚挚的问候

编辑:找到有关异常的更多信息:

代码语言:javascript
复制
_context->compile();

是一个快捷方式,

代码语言:javascript
复制
checkError( rtContextCompile( m_context ) );

在optixx_namespace.h中,在checkError中检查的返回结果是一个RT_ERROR_INVALID_VALUE。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-29 03:16:01

幸运的是,我可以自己解决这个问题。我的问题是我有一个同时运行的CUDA 3.2和CUDA 5.0的旧安装。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12822205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档