@@ -241,19 +241,6 @@ __global__ void pathIntegSampleSurface(
241241 return ;
242242 }
243243
244- #if BVH_DEBUG_VISUALIZATION
245- float logDepth = 0 .f ;
246- int size = scene->BVHSize ;
247- while (size) {
248- logDepth += 1 .f ;
249- size >>= 1 ;
250- }
251- segment.radiance = glm::vec3 (float (intersec.primId ) / logDepth * .1f );
252- // segment.radiance = intersec.primitive > 16 ? glm::vec3(1.f) : glm::vec3(0.f);
253- segment.remainingBounces = 0 ;
254- return ;
255- #endif
256-
257244 PathSegment& segment = segments[idx];
258245 thrust::default_random_engine rng = makeSeededRandomEngine (iter, idx, 4 + depth * SamplesConsumedOneIter);
259246
@@ -430,6 +417,29 @@ WriteRadiance:
430417 image[index] += accRadiance;
431418}
432419
420+ __global__ void BVHVisualize (int iter, DevScene* scene, Camera cam, glm::vec3* image, int width, int height) {
421+ int x = blockDim .x * blockIdx .x + threadIdx .x ;
422+ int y = blockDim .y * blockIdx .y + threadIdx .y ;
423+ if (x >= width || y >= height) {
424+ return ;
425+ }
426+ int index = y * width + x;
427+
428+ thrust::default_random_engine rng = makeSeededRandomEngine (iter, index, 0 );
429+ Ray ray = sampleCamera (cam, x, y, sample4D (rng));
430+
431+ Intersection intersec;
432+ scene->visualizedIntersect (ray, intersec);
433+
434+ float logDepth = 0 .f ;
435+ int size = scene->BVHSize ;
436+ while (size) {
437+ logDepth += 1 .f ;
438+ size >>= 1 ;
439+ }
440+ image[index] += glm::vec3 (float (intersec.primId ) / logDepth * .1f );
441+ }
442+
433443struct CompactTerminatedPaths {
434444 __host__ __device__ bool operator () (const PathSegment& segment) {
435445 return !(segment.pixelIndex >= 0 && segment.remainingBounces <= 0 );
@@ -465,22 +475,7 @@ void pathTrace(uchar4* pbo, int frame, int iter) {
465475
466476 auto devTerminatedThr = devTerminatedPathsThr;
467477
468- if (Settings::singleKernel) {
469- const int BlockSizeSinglePTX = 8 ;
470- const int BlockSizeSinglePTY = 8 ;
471- int blockNumSinglePTX = (cam.resolution .x + BlockSizeSinglePTX - 1 ) / BlockSizeSinglePTX;
472- int blockNumSinglePTY = (cam.resolution .y + BlockSizeSinglePTY - 1 ) / BlockSizeSinglePTY;
473-
474- dim3 singlePTBlockNum (blockNumSinglePTX, blockNumSinglePTY);
475- dim3 singlePTBlockSize (BlockSizeSinglePTX, BlockSizeSinglePTY);
476-
477- singleKernelPT<<<singlePTBlockNum, singlePTBlockSize>>> (
478- iter, Settings::traceDepth, hstScene->devScene , cam, devImage, cam.resolution .x , cam.resolution .y );
479- if (guiData != nullptr ) {
480- guiData->TracedDepth = Settings::traceDepth;
481- }
482- }
483- else {
478+ if (Settings::tracer == Tracer::Streamed) {
484479 bool iterationComplete = false ;
485480 while (!iterationComplete) {
486481 // clean shading chunks
@@ -531,6 +526,28 @@ void pathTrace(uchar4* pbo, int frame, int iter) {
531526 int numContributing = devTerminatedThr.get () - devTerminatedPaths;
532527 finalGather<<<numBlocksPixels, BlockSizeGather>>> (numContributing, devImage, devTerminatedPaths);
533528 }
529+ else {
530+ const int BlockSizeSinglePTX = 8 ;
531+ const int BlockSizeSinglePTY = 8 ;
532+ int blockNumSinglePTX = (cam.resolution .x + BlockSizeSinglePTX - 1 ) / BlockSizeSinglePTX;
533+ int blockNumSinglePTY = (cam.resolution .y + BlockSizeSinglePTY - 1 ) / BlockSizeSinglePTY;
534+
535+ dim3 singlePTBlockNum (blockNumSinglePTX, blockNumSinglePTY);
536+ dim3 singlePTBlockSize (BlockSizeSinglePTX, BlockSizeSinglePTY);
537+
538+ if (Settings::tracer == Tracer::SingleKernel) {
539+ singleKernelPT<<<singlePTBlockNum, singlePTBlockSize>>> (
540+ iter, Settings::traceDepth, hstScene->devScene , cam, devImage, cam.resolution .x , cam.resolution .y );
541+ }
542+ else {
543+ BVHVisualize<<<singlePTBlockNum, singlePTBlockSize>>> (
544+ iter, hstScene->devScene , cam, devImage, cam.resolution .x , cam.resolution .y );
545+ }
546+
547+ if (guiData != nullptr ) {
548+ guiData->TracedDepth = Settings::traceDepth;
549+ }
550+ }
534551
535552 // Send results to OpenGL buffer for rendering
536553 sendImageToPBO<<<blocksPerGrid2D, blockSize2D>>> (pbo, cam.resolution , iter, devImage, Settings::toneMapping);
0 commit comments