Hello,
I tried to exchange the code in the progressive example with the “wrapper”-code.
So what I did was replace this code:
void create_context( RTcontext* context, RTbuffer* output_buffer, RTbuffer* stream_buffer );
void create_material( RTcontext context, RTmaterial* material );
void create_geometry( RTcontext context, RTmaterial material );
void ptxPath( const char* base, char* path );
void cross( const float a[3], const float b[3], float result[3] );
void normalize( float a[3] );
float dot( const float a[3], const float b[3] );
// global variables
RTcontext context;
RTremotedevice rdev = 0;
RTbuffer output_buffer, stream_buffer, seed_buffer;
RTmaterial material;
RTvariable var_eye;
RTvariable var_U;
RTvariable var_V;
RTvariable var_W;
unsigned int width = 800;
unsigned int height = 600;
int sqrt_occlusion_samples = 2;
int stream_bitrate;
int stream_fps;
float stream_gamma;
char stream_format[128];
char ptx_path[1024];
float eye[3] = { 3.0f, 2.0f, -3.0f };
float eye_org[3] = { 3.0f, 2.0f, -3.0f };
float hfov_org = 75.0f, hfov = 75.0f;
void set_cam_vars( float eye[3], float fov )
{
float lookat[3], up[3];
float camera_u[3], camera_v[3], camera_w[3];
lookat[0] = 0.0f; lookat[1] = 0.3f; lookat[2] = 0.0f;
up[0] = 0.0f; up[1] = 1.0f; up[2] = 0.0f;
const float aspect_ratio = (float)width/(float)height;
sutilCalculateCameraVariables( eye, lookat, up, fov, aspect_ratio, camera_u, camera_v, camera_w );
rtVariableSet3fv( var_eye, eye );
rtVariableSet3fv( var_U, camera_u );
rtVariableSet3fv( var_V, camera_v );
rtVariableSet3fv( var_W, camera_w );
}
void create_context( RTcontext* context, RTremotedevice rdev, RTbuffer* output_buffer, RTbuffer* stream_buffer )
{
// Context
RT_CHECK_ERROR2( rtContextCreate( context ) );
// When using a remove device, it must be set right after creating the context.
if( rdev ) {
RT_CHECK_ERROR2( rtContextSetRemoteDevice( *context, rdev ) );
}
RT_CHECK_ERROR2( rtContextSetEntryPointCount( *context, 1 ) );
RT_CHECK_ERROR2( rtContextSetRayTypeCount( *context, 2 ) );
RT_CHECK_ERROR2( rtContextSetStackSize( *context, 320 ) );
// Output buffer
RT_CHECK_ERROR2( rtBufferCreate( *context, RT_BUFFER_OUTPUT, output_buffer ) );
RT_CHECK_ERROR2( rtBufferSetFormat( *output_buffer, RT_FORMAT_FLOAT4 ) );
RT_CHECK_ERROR2( rtBufferSetSize2D( *output_buffer, width, height ) );
RT_CHECK_ERROR2( rtBufferCreate( *context, RT_BUFFER_PROGRESSIVE_STREAM, stream_buffer ) );
RT_CHECK_ERROR2( rtBufferSetFormat( *stream_buffer, RT_FORMAT_UNSIGNED_BYTE4 ) );
RT_CHECK_ERROR2( rtBufferSetSize2D( *stream_buffer, width, height ) );
RT_CHECK_ERROR2( rtBufferBindProgressiveStream( *stream_buffer, *output_buffer ) );
// Ray generation program
RTprogram raygen_program;
ptxPath( "camera.cu", ptx_path );
RT_CHECK_ERROR2( rtProgramCreateFromPTXFile( *context, ptx_path, "pinhole_camera", &raygen_program ) );
RT_CHECK_ERROR2( rtContextSetRayGenerationProgram( *context, 0, raygen_program ) );
// Exception program
RTprogram exception_program;
RT_CHECK_ERROR2( rtProgramCreateFromPTXFile( *context, ptx_path, "exception", &exception_program ) );
RT_CHECK_ERROR2( rtContextSetExceptionProgram( *context, 0, exception_program ) );
// Miss program
RTprogram miss_program;
ptxPath( "constantbg.cu", ptx_path );
RT_CHECK_ERROR2( rtProgramCreateFromPTXFile( *context, ptx_path, "miss", &miss_program ) );
RT_CHECK_ERROR2( rtContextSetMissProgram( *context, 0, miss_program ) );
// Random seed buffer
RT_CHECK_ERROR2( rtBufferCreate( *context, RT_BUFFER_INPUT, &seed_buffer ) );
RT_CHECK_ERROR2( rtBufferSetFormat( seed_buffer, RT_FORMAT_UNSIGNED_INT ) );
unsigned int* seeds;
RT_CHECK_ERROR2( rtBufferSetSize2D( seed_buffer, width, height ) );
RT_CHECK_ERROR2( rtBufferMap( seed_buffer, (void**)&seeds ) );
for( unsigned int i = 0; i < width*height; ++i )
seeds[i] = rand();
RT_CHECK_ERROR2( rtBufferUnmap( seed_buffer ) );
// Variables
RTvariable var_output_buffer;
RTvariable var_seed_buffer;
RTvariable var_scene_epsilon;
RTvariable var_radiance_ray_type;
RTvariable var_badcolor;
RTvariable var_bgcolor;
RTvariable var_frame;
RT_CHECK_ERROR2( rtContextDeclareVariable( *context, "output_buffer", &var_output_buffer ) );
RT_CHECK_ERROR2( rtContextDeclareVariable( *context, "rnd_seeds", &var_seed_buffer) );
RT_CHECK_ERROR2( rtContextDeclareVariable( *context, "scene_epsilon", &var_scene_epsilon ) );
RT_CHECK_ERROR2( rtContextDeclareVariable( *context, "radiance_ray_type", &var_radiance_ray_type ) );
RT_CHECK_ERROR2( rtContextDeclareVariable( *context, "bad_color", &var_badcolor ) );
RT_CHECK_ERROR2( rtContextDeclareVariable( *context, "bg_color", &var_bgcolor ) );
RT_CHECK_ERROR2( rtContextDeclareVariable( *context, "frame", &var_frame ) );
RT_CHECK_ERROR2( rtVariableSetObject( var_output_buffer, *output_buffer ) );
RT_CHECK_ERROR2( rtVariableSetObject( var_seed_buffer, seed_buffer ) );
RT_CHECK_ERROR2( rtVariableSet1f( var_scene_epsilon, 1e-3f ) );
RT_CHECK_ERROR2( rtVariableSet1ui( var_radiance_ray_type, 0u ) );
RT_CHECK_ERROR2( rtVariableSet1i( var_frame, 0u ) );
RT_CHECK_ERROR2( rtVariableSet3f( var_badcolor, 1.0f, 1.0f, 0.0f ) );
RT_CHECK_ERROR2( rtVariableSet3f( var_bgcolor, 0.462f, 0.725f, 0.0f ) );
RT_CHECK_ERROR2( rtContextDeclareVariable( *context, "eye",&var_eye ) );
RT_CHECK_ERROR2( rtContextDeclareVariable( *context, "U",&var_U ) );
RT_CHECK_ERROR2( rtContextDeclareVariable( *context, "V",&var_V ) );
RT_CHECK_ERROR2( rtContextDeclareVariable( *context, "W",&var_W ) );
}
void create_material( RTcontext context, RTmaterial* material )
{
RTvariable var_occlusion_distance;
RTvariable var_sqrt_occlusion_samples;
RTprogram ch_radiance_program;
RTprogram ah_occlusion_program;
/* Material. */
RT_CHECK_ERROR( rtMaterialCreate(context,material) );
ptxPath( "ambocc.cu", ptx_path );
RT_CHECK_ERROR( rtProgramCreateFromPTXFile( context, ptx_path, "closest_hit_radiance", &ch_radiance_program ) );
RT_CHECK_ERROR( rtProgramCreateFromPTXFile( context, ptx_path, "any_hit_occlusion", &ah_occlusion_program ) );
RT_CHECK_ERROR( rtMaterialSetClosestHitProgram( *material, 0, ch_radiance_program ) );
RT_CHECK_ERROR( rtMaterialSetAnyHitProgram( *material, 1, ah_occlusion_program ) );
/* Variables. */
RT_CHECK_ERROR( rtMaterialDeclareVariable( *material, "occlusion_distance", &var_occlusion_distance ) );
RT_CHECK_ERROR( rtVariableSet1f( var_occlusion_distance, 150.0f ) );
RT_CHECK_ERROR( rtMaterialDeclareVariable( *material, "sqrt_occlusion_samples", &var_sqrt_occlusion_samples ) );
RT_CHECK_ERROR( rtVariableSet1i( var_sqrt_occlusion_samples, sqrt_occlusion_samples ) );
}
void create_geometry( RTcontext context, RTmaterial material )
{
RTgeometry sphere_geom;
RTprogram sphere_isect_program;
RTprogram sphere_bounds_program;
RTvariable var_sphere;
RTgeometry ground_geom;
RTprogram ground_isect_program;
RTprogram ground_bounds_program;
RTvariable var_plane;
RTvariable var_v1;
RTvariable var_v2;
RTvariable var_anchor;
float v1[3], v2[3];
float anchor[3];
float normal[3];
float inv_len2;
float plane[4];
RTgeometryinstance sphere_inst;
RTgeometryinstance ground_inst;
RTacceleration accel;
RTgeometrygroup geometrygroup;
RTvariable var_group;
/* Sphere geometry. */
RT_CHECK_ERROR( rtGeometryCreate( context,&sphere_geom ) );
RT_CHECK_ERROR( rtGeometrySetPrimitiveCount( sphere_geom, 1 ) );
ptxPath( "sphere.cu", ptx_path );
RT_CHECK_ERROR( rtProgramCreateFromPTXFile( context, ptx_path, "intersect", &sphere_isect_program ) );
RT_CHECK_ERROR( rtProgramCreateFromPTXFile( context, ptx_path, "bounds", &sphere_bounds_program) );
RT_CHECK_ERROR( rtGeometrySetIntersectionProgram( sphere_geom, sphere_isect_program ) );
RT_CHECK_ERROR( rtGeometrySetBoundingBoxProgram( sphere_geom, sphere_bounds_program ) );
RT_CHECK_ERROR( rtGeometryDeclareVariable( sphere_geom, "sphere", &var_sphere ) );
RT_CHECK_ERROR( rtVariableSet4f( var_sphere, 0.0f, 1.2f, 0.0f, 1.0f ) );
/* Ground geometry. */
RT_CHECK_ERROR( rtGeometryCreate( context, &ground_geom ) );
RT_CHECK_ERROR( rtGeometrySetPrimitiveCount( ground_geom, 1 ) );
ptxPath( "parallelogram.cu", ptx_path );
RT_CHECK_ERROR( rtProgramCreateFromPTXFile( context, ptx_path, "intersect", &ground_isect_program ) );
RT_CHECK_ERROR( rtProgramCreateFromPTXFile( context, ptx_path, "bounds", &ground_bounds_program ) );
RT_CHECK_ERROR( rtGeometrySetIntersectionProgram( ground_geom,ground_isect_program ) );
RT_CHECK_ERROR( rtGeometrySetBoundingBoxProgram( ground_geom,ground_bounds_program ) );
RT_CHECK_ERROR( rtGeometryDeclareVariable( ground_geom, "plane", &var_plane ) );
RT_CHECK_ERROR( rtGeometryDeclareVariable( ground_geom, "v1", &var_v1 ) );
RT_CHECK_ERROR( rtGeometryDeclareVariable( ground_geom, "v2", &var_v2 ) );
RT_CHECK_ERROR( rtGeometryDeclareVariable( ground_geom, "anchor", &var_anchor ) );
anchor[0] = -30.0f; anchor[1] = 0.0f; anchor[2] = 20.0f;
v1[0] = 40.0f; v1[1] = 0.0f; v1[2] = 0.0f;
v2[0] = 0.0f; v2[1] = 0.0f; v2[2] = -40.0f;
cross( v1, v2, normal );
normalize( normal );
inv_len2 = 1.0f / dot( v1, v1 );
v1[0] *= inv_len2;
v1[1] *= inv_len2;
v1[2] *= inv_len2;
inv_len2 = 1.0f / dot( v2, v2 );
v2[0] *= inv_len2;
v2[1] *= inv_len2;
v2[2] *= inv_len2;
plane[0] = normal[0];
plane[1] = normal[1];
plane[2] = normal[2];
plane[3] = dot( normal, anchor );
RT_CHECK_ERROR( rtVariableSet4fv( var_plane, plane ) );
RT_CHECK_ERROR( rtVariableSet3fv( var_v1, v1 ) );
RT_CHECK_ERROR( rtVariableSet3fv( var_v2, v2 ) );
RT_CHECK_ERROR( rtVariableSet3fv( var_anchor, anchor ) );
/* Sphere instance. */
RT_CHECK_ERROR( rtGeometryInstanceCreate( context, &sphere_inst ) );
RT_CHECK_ERROR( rtGeometryInstanceSetGeometry( sphere_inst,sphere_geom ) );
RT_CHECK_ERROR( rtGeometryInstanceSetMaterialCount( sphere_inst, 1 ) );
RT_CHECK_ERROR( rtGeometryInstanceSetMaterial( sphere_inst, 0, material ) );
/* Ground instance. */
RT_CHECK_ERROR( rtGeometryInstanceCreate( context, &ground_inst ) );
RT_CHECK_ERROR( rtGeometryInstanceSetGeometry( ground_inst, ground_geom ) );
RT_CHECK_ERROR( rtGeometryInstanceSetMaterialCount( ground_inst, 1 ) );
RT_CHECK_ERROR( rtGeometryInstanceSetMaterial( ground_inst, 0 ,material ) );
/* Accelerations. */
RT_CHECK_ERROR( rtAccelerationCreate( context, &accel ) );
RT_CHECK_ERROR( rtAccelerationSetBuilder( accel, "NoAccel" ) );
RT_CHECK_ERROR( rtAccelerationSetTraverser( accel, "NoAccel" ) );
/* GeometryGroup. */
RT_CHECK_ERROR( rtGeometryGroupCreate( context, &geometrygroup ) );
RT_CHECK_ERROR( rtGeometryGroupSetChildCount( geometrygroup, 2 ) );
RT_CHECK_ERROR( rtGeometryGroupSetChild( geometrygroup, 0, sphere_inst ) );
RT_CHECK_ERROR( rtGeometryGroupSetChild( geometrygroup, 1, ground_inst ) );
RT_CHECK_ERROR( rtGeometryGroupSetAcceleration( geometrygroup, accel ) );
/* Attach to context */
RT_CHECK_ERROR( rtContextDeclareVariable( context, "top_object", &var_group ) );
RT_CHECK_ERROR( rtVariableSetObject( var_group, geometrygroup ) );
}
void display( RTbuffer buffer, RTformat buffer_format, RTsize element_size )
{
GLenum gl_data_type = GL_FALSE;
GLenum gl_format = GL_FALSE;
switch (buffer_format)
{
case RT_FORMAT_UNSIGNED_BYTE4:
gl_data_type = GL_UNSIGNED_BYTE;
//gl_format = 0x80E1; //GL_BGRA
gl_format = GL_RGBA;
break;
case RT_FORMAT_UNSIGNED_BYTE3:
gl_data_type = GL_UNSIGNED_BYTE;
//gl_format = 0x80E0; //GL_BGR
gl_format = GL_RGB;
break;
case RT_FORMAT_FLOAT:
gl_data_type = GL_FLOAT;
gl_format = GL_LUMINANCE;
break;
case RT_FORMAT_FLOAT3:
gl_data_type = GL_FLOAT;
gl_format = GL_RGB;
break;
case RT_FORMAT_FLOAT4:
gl_data_type = GL_FLOAT;
gl_format = GL_RGBA;
break;
default:
fprintf(stderr, "Unrecognized buffer data type or format.\n");
exit(2);
break;
}
int align = 1;
if ((element_size % 8) == 0) align = 8;
else if ((element_size % 4) == 0) align = 4;
else if ((element_size % 2) == 0) align = 2;
glPixelStorei(GL_UNPACK_ALIGNMENT, align);
GLvoid* imageData;
RT_CHECK_ERROR( rtBufferMap(buffer,&imageData) );
glDrawPixels(width, height, gl_format, gl_data_type, imageData);
RT_CHECK_ERROR( rtBufferUnmap(buffer) );
}
void glut_display(void)
{
int ready;
unsigned int subframe_count, max_subframes;
RT_CHECK_ERROR( rtBufferGetProgressiveUpdateReady( stream_buffer, &ready, &subframe_count, &max_subframes ) );
if( ready )
{
//printf("disp: subframe=%d max=%d\n", subframe_count, max_subframes );
display( stream_buffer, RT_FORMAT_UNSIGNED_BYTE4, 4 );
glutSwapBuffers();
}
// Calling rtContextLaunchProgressive while a launch is already in progress is a no-op,
// so we can unconditionally call it here. In case the user interacted with the scene
// and thus changed the state of the context (by calling rtVariableSet), this will restart
// progressive rendering with the new context state.
RT_CHECK_ERROR(rtContextLaunchProgressive2D(context, 0, width, height, 0));
}
int main( int argc, char** argv )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA );
glutInitWindowSize( width, height );
glutCreateWindow( "progressive" );
create_context( &context, rdev, &output_buffer, &stream_buffer );
create_material( context, &material );
create_geometry( context, material );
set_cam_vars( eye_org, hfov_org );
RT_CHECK_ERROR( rtBufferGetAttribute(stream_buffer, RT_BUFFER_ATTRIBUTE_STREAM_BITRATE, sizeof(int), &stream_bitrate) );
RT_CHECK_ERROR( rtBufferGetAttribute(stream_buffer, RT_BUFFER_ATTRIBUTE_STREAM_FPS, sizeof(int), &stream_fps) );
RT_CHECK_ERROR( rtBufferGetAttribute(stream_buffer, RT_BUFFER_ATTRIBUTE_STREAM_GAMMA, sizeof(float), &stream_gamma) );
RT_CHECK_ERROR( rtBufferGetAttribute(stream_buffer, RT_BUFFER_ATTRIBUTE_STREAM_FORMAT, sizeof(stream_format), stream_format) );
printf( "Stream options: bitrate=%d, target fps=%d, gamma=%.2f, format=%s\n", stream_bitrate, stream_fps, stream_gamma, stream_format );
RT_CHECK_ERROR(rtContextValidate(context));
RT_CHECK_ERROR(rtContextCompile(context));
RT_CHECK_ERROR(rtContextLaunchProgressive2D(context, 0, width, height, 0));
// register glut callbacks
glutDisplayFunc( glut_display );
glutIdleFunc( glut_display );
glutMainLoop();
return 0;
}
with this
void create_context();
void create_material();
void create_geometry();
void ptxPath( const char* base, char* path );
void cross( const float a[3], const float b[3], float result[3] );
void normalize( float a[3] );
float dot( const float a[3], const float b[3] );
// global variables
optix::Context context;
optix::RemoteDevice rdev = 0;
optix::Buffer output_buffer, stream_buffer, seed_buffer;
optix::Material material;
optix::float3 eye = { 3.0f, 2.0f, -3.0f };
optix::float3 U, V, W;
std::string vca_url;
std::string vca_user;
std::string vca_password;
int vca_num_nodes = 1;
int vca_config_index = 0;
unsigned int width = 800;
unsigned int height = 600;
int sqrt_occlusion_samples = 2;
int stream_bitrate;
int stream_fps;
float stream_gamma;
char stream_format[128];
char ptx_path[1024];
void set_cam_vars(optix::float3 eye,float hfov)
{
optix::float3 lookat, up;
optix::float3 camera_u, camera_v, camera_w;
lookat = { 1.0f, 1.3f, 0.0f };
up = { 0.0f, 1.0f, 0.0f };
const float aspect_ratio = (float)width / (float)height;
float ulen, vlen, wlen;
camera_w.x = lookat.x - eye.x;
camera_w.y = lookat.y - eye.y; /* Do not normalize W -- it implies focal length */
camera_w.z = lookat.z - eye.z;
wlen = sqrtf(dot(camera_w, camera_w));
camera_u = cross(camera_w, up);
normalize(camera_u);
camera_v = cross(camera_u, camera_w);
normalize(camera_v);
ulen = wlen * tanf(hfov / 2.0f * 3.14159265358979323846f / 180.0f);
camera_u.x *= ulen;
camera_u.y *= ulen;
camera_u.z *= ulen;
vlen = ulen / aspect_ratio;
camera_v.x *= vlen;
camera_v.y *= vlen;
camera_v.z *= vlen;
context["eye"]->setFloat(eye);
context["U"]->setFloat(camera_u);
context["V"]->setFloat(camera_v);
context["W"]->setFloat(camera_w);
}
void create_context()
{
// Context
context = optix::Context::create();
// When using a remove device, it must be set right after creating the context.
if (rdev) {
//RT_CHECK_ERROR2(rtContextSetRemoteDevice(*context, rdev));
context->setRemoteDevice(rdev);
}
context->setEntryPointCount(1);
context->setRayTypeCount(2);
context->setStackSize(320);
//create output buffer
output_buffer = context->createBuffer(RT_BUFFER_OUTPUT);
output_buffer->setFormat(RT_FORMAT_FLOAT4);
output_buffer->setSize(width, height);
stream_buffer = context->createBuffer(RT_BUFFER_PROGRESSIVE_STREAM);
stream_buffer->setFormat(RT_FORMAT_UNSIGNED_BYTE4);
stream_buffer->setSize(width, height);
stream_buffer->bindProgressiveStream(output_buffer);
// Ray generation program
ptxPath("camera.cu", ptx_path);
context->setRayGenerationProgram(0, context->createProgramFromPTXFile(ptx_path, "pinhole_camera"));
// Exception program
context->setExceptionProgram(0, context->createProgramFromPTXFile(ptx_path, "exception"));
// Miss program
ptxPath("constantbg.cu", ptx_path);
context->setMissProgram(0, context->createProgramFromPTXFile(ptx_path, "miss"));
// Random seed buffer
seed_buffer = context->createBuffer(RT_BUFFER_INPUT);
seed_buffer->setFormat(RT_FORMAT_UNSIGNED_INT);
unsigned int* seeds;
seed_buffer->setSize(width, height);
seeds = (unsigned int*)seed_buffer->map();
for (unsigned int i = 0; i < width*height; ++i)
seeds[i] = rand();
seed_buffer->unmap();
// Variables
context["output_buffer"]->set(output_buffer);
context["rnd_seeds"]->set(seed_buffer);
context["scene_epsilon"]->setFloat(1.e-3f);
context["radiance_ray_type"]->setUint(0);
context["bad_color"]->setFloat(1.0f, 1.0f, 0.0f);
context["bg_color"]->setFloat(0.462f, 0.725f, 0.0f);
context["frame"]->setInt(0u);
context["eye"]->setFloat(eye);
context["U"]->setFloat(U);
context["V"]->setFloat(V);
context["W"]->setFloat(W);
}
void create_material()
{
material = context->createMaterial();
//ground material
ptxPath("ambocc.cu", ptx_path);
material->setAnyHitProgram(0, context->createProgramFromPTXFile(ptx_path, "any_hit_occlusion"));
material->setClosestHitProgram(0, context->createProgramFromPTXFile(ptx_path, "closest_hit_radiance"));
material["occlusion_distance"]->setFloat(150.0f);
material["sqrt_occlusion_samples"]->setInt(2);
}
void create_geometry()
{
optix::Geometry sphere_, ground_;
optix::GeometryInstance sphere_gi, ground_gi;
optix::GeometryGroup geom_group;
//geometry sphere
sphere_ = context->createGeometry();
ptxPath("sphere.cu", ptx_path);
sphere_->setPrimitiveCount(1u);
sphere_->setBoundingBoxProgram(context->createProgramFromPTXFile(ptx_path, "bounds"));
sphere_->setIntersectionProgram(context->createProgramFromPTXFile(ptx_path, "intersect"));
sphere_["sphere"]->setFloat(2.0f, 3.2f, 0.0f, 1.3f);
/* Ground geometry. */
ground_ = context->createGeometry();
ptxPath("parallelogram.cu", ptx_path);
ground_->setPrimitiveCount(1u);
ground_->setBoundingBoxProgram(context->createProgramFromPTXFile(ptx_path, "bounds"));
ground_->setIntersectionProgram(context->createProgramFromPTXFile(ptx_path, "intersect"));
optix::float3 anchor = { -30.0f, 0.0f, 20.0f };
optix::float3 v1 = { 40.0f, 0.0f, 0.0f };
optix::float3 v2 = { 0.0f, 0.0f, -40.0f };
optix::float3 normal = cross(v2, v1);
normal = normalize(normal);
float d = dot(normal, anchor);
v1 *= 1.0f / dot(v1, v1);
v2 *= 1.0f / dot(v2, v2);
optix::float4 plane = make_float4(normal, d);
ground_["plane"]->setFloat(plane);
ground_["v1"]->setFloat(v1);
ground_["v2"]->setFloat(v2);
ground_["anchor"]->setFloat(anchor);
////geometry instance
sphere_gi = context->createGeometryInstance();
sphere_gi->setGeometry(sphere_);
sphere_gi->setMaterialCount(1);
sphere_gi->setMaterial(0, material);
ground_gi = context->createGeometryInstance();
ground_gi->setGeometry(ground_);
ground_gi->setMaterialCount(1);
ground_gi->setMaterial(0, material);
//geometry group & acceleration
geom_group = context->createGeometryGroup();
geom_group->setChildCount(2);
geom_group->setChild(0, sphere_gi);
geom_group->setChild(1, ground_gi);
geom_group->setAcceleration(context->createAcceleration("NoAccel", "NoAccel"));
//attach to context
context["top_object"]->set(geom_group);
}
void display(optix::Buffer buffer, RTformat buffer_format, RTsize element_size)
{
GLenum gl_data_type = GL_FALSE;
GLenum gl_format = GL_FALSE;
switch (buffer_format)
{
case RT_FORMAT_UNSIGNED_BYTE4:
gl_data_type = GL_UNSIGNED_BYTE;
//gl_format = 0x80E1; //GL_BGRA
gl_format = GL_RGBA;
break;
case RT_FORMAT_UNSIGNED_BYTE3:
gl_data_type = GL_UNSIGNED_BYTE;
//gl_format = 0x80E0; //GL_BGR
gl_format = GL_RGB;
break;
case RT_FORMAT_FLOAT:
gl_data_type = GL_FLOAT;
gl_format = GL_LUMINANCE;
break;
case RT_FORMAT_FLOAT3:
gl_data_type = GL_FLOAT;
gl_format = GL_RGB;
break;
case RT_FORMAT_FLOAT4:
gl_data_type = GL_FLOAT;
gl_format = GL_RGBA;
break;
default:
fprintf(stderr, "Unrecognized buffer data type or format.\n");
exit(2);
break;
}
int align = 1;
if ((element_size % 8) == 0) align = 8;
else if ((element_size % 4) == 0) align = 4;
else if ((element_size % 2) == 0) align = 2;
glPixelStorei(GL_UNPACK_ALIGNMENT, align);
GLvoid* imageData;
imageData= buffer->map();
glDrawPixels(width, height, gl_format, gl_data_type, imageData);
buffer->unmap();
}
void glut_display(void)
{
int ready;
unsigned int subframe_count, max_subframes;
stream_buffer->getProgressiveUpdateReady(&ready, &subframe_count, &max_subframes);
if (ready)
{
//printf("disp: subframe=%d max=%d\n", subframe_count, max_subframes );
display(stream_buffer, RT_FORMAT_UNSIGNED_BYTE4, 4);
glutSwapBuffers();
}
// Calling rtContextLaunchProgressive while a launch is already in progress is a no-op,
// so we can unconditionally call it here. In case the user interacted with the scene
// and thus changed the state of the context (by calling rtVariableSet), this will restart
// progressive rendering with the new context state.
context->launchProgressive(0, width, height, 0);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(width, height);
glutCreateWindow("progressive");
create_context();
create_material();
create_geometry();
set_cam_vars(eye, hfov_org);
stream_buffer->getAttribute(RT_BUFFER_ATTRIBUTE_STREAM_BITRATE, sizeof(int), &stream_bitrate);
stream_buffer->getAttribute(RT_BUFFER_ATTRIBUTE_STREAM_FPS, sizeof(int), &stream_fps);
stream_buffer->getAttribute( RT_BUFFER_ATTRIBUTE_STREAM_GAMMA, sizeof(float), &stream_gamma);
stream_buffer->getAttribute(RT_BUFFER_ATTRIBUTE_STREAM_FORMAT, sizeof(stream_format), stream_format);
//printf("Stream options: bitrate=%d, target fps=%d, gamma=%.2f, format=%s\n", stream_bitrate, stream_fps, stream_gamma, stream_format);
context->validate();
context->compile();
context->launchProgressive(0, width, height, 0);
// register glut callbacks
glutDisplayFunc(glut_display);
glutIdleFunc(glut_display);
glutMainLoop();
return 0;
}
which is in my opinion the corresponding way to write the code.
But now my output changed from
to this
So now my question is, what could be the reason for this kind of error? Isn’t the code nearly the same and should get the same output or did I get something wrong there?
I’m sorry for this big pile of code, but I couldn’t think of a shorter way to describe my problem.
I hope you can help me and thanks a lot