/* called by the C++ code to render */ extern "C" void device_render (int* pixels, const unsigned int width, const unsigned int height, const float time, const ISPCCamera& camera) { float t0 = 0.7f*time; float t1 = 1.5f*time; /* rotate instances around themselves */ LinearSpace3fa xfm; xfm.vx = Vec3fa(cos(t1),0,sin(t1)); xfm.vy = Vec3fa(0,1,0); xfm.vz = Vec3fa(-sin(t1),0,cos(t1)); /* calculate transformations to move instances in cirle */ for (int i=0; i<4; i++) { float t = t0+i*2.0f*float(pi)/4.0f; instance_xfm[i] = AffineSpace3fa(xfm,2.2f*Vec3fa(+cos(t),0.0f,+sin(t))); } /* calculate transformations to properly transform normals */ for (int i=0; i<4; i++) normal_xfm[i] = transposed(rcp(instance_xfm[i].l)); /* set instance transformations */ rtcSetTransform2(g_scene,g_instance0,RTC_MATRIX_COLUMN_MAJOR_ALIGNED16,(float*)&instance_xfm[0],0); rtcSetTransform2(g_scene,g_instance1,RTC_MATRIX_COLUMN_MAJOR_ALIGNED16,(float*)&instance_xfm[1],0); rtcSetTransform2(g_scene,g_instance2,RTC_MATRIX_COLUMN_MAJOR_ALIGNED16,(float*)&instance_xfm[2],0); rtcSetTransform2(g_scene,g_instance3,RTC_MATRIX_COLUMN_MAJOR_ALIGNED16,(float*)&instance_xfm[3],0); /* update scene */ rtcUpdate(g_scene,g_instance0); rtcUpdate(g_scene,g_instance1); rtcUpdate(g_scene,g_instance2); rtcUpdate(g_scene,g_instance3); rtcCommit (g_scene); /* render all pixels */ const int numTilesX = (width +TILE_SIZE_X-1)/TILE_SIZE_X; const int numTilesY = (height+TILE_SIZE_Y-1)/TILE_SIZE_Y; parallel_for(size_t(0),size_t(numTilesX*numTilesY),[&](const range<size_t>& range) { const int threadIndex = (int)TaskScheduler::threadIndex(); for (size_t i=range.begin(); i<range.end(); i++) renderTileTask((int)i,threadIndex,pixels,width,height,time,camera,numTilesX,numTilesY); }); }
void Scene::embreeInit(RTCDevice device) { Embree.scene = rtcDeviceNewScene(device, EMBREE_SFLAGS_SCENE, EMBREE_AFLAGS_SCENE); for (uint i = 0; i < objects.size(); i++) { objects[i]->embreeInit(device); uint instID = rtcNewInstance2(Embree.scene, objects[i]->Embree.scene); rtcSetTransform2(Embree.scene, instID, RTC_MATRIX_COLUMN_MAJOR_ALIGNED16, objects[i]->matrix.e); Embree.instIDmap[instID] = objects[i]; } rtcCommit(Embree.scene); }
extern "C" void ispcSetTransform2 (RTCScene scene, unsigned geomID, RTCMatrixType layout, const float* xfm, size_t timeStep) { return rtcSetTransform2(scene,geomID,layout,xfm,timeStep); }