@@ -70,6 +70,9 @@ static thrust::device_ptr<PathSegment> devTerminatedPathsThr;
7070static thrust::device_ptr<Intersection> devIntersectionsThr;
7171static thrust::device_ptr<int > devIntersecMatKeysThr;
7272static thrust::device_ptr<int > devSegmentMatKeysThr;
73+
74+ static glm::vec3* devGBufferPos = nullptr ;
75+ static glm::vec3* devGBufferNorm = nullptr ;
7376
7477void InitDataContainer (GuiDataContainer* imGuiData) {
7578 guiData = imGuiData;
@@ -156,6 +159,35 @@ __global__ void generateRayFromCamera(Camera cam, int iter, int traceDepth, Path
156159 }
157160}
158161
162+ __global__ void previewGBuffer (
163+ int iter,
164+ DevScene* scene, Camera cam,
165+ glm::vec3* image, int width, int height,
166+ int kind
167+ ) {
168+ int x = blockDim .x * blockIdx .x + threadIdx .x ;
169+ int y = blockDim .y * blockIdx .y + threadIdx .y ;
170+ if (x >= width || y >= height) {
171+ return ;
172+ }
173+ int index = y * width + x;
174+ thrust::default_random_engine rng = makeSeededRandomEngine (iter, index, 0 );
175+
176+ Ray ray = sampleCamera (cam, x, y, sample4D (rng));
177+ Intersection intersec;
178+ scene->intersect (ray, intersec);
179+
180+ if (kind == 0 ) {
181+ image[index] += intersec.pos ;
182+ }
183+ else if (kind == 1 ) {
184+ image[index] += (intersec.norm + 1 .f ) * .5f ;
185+ }
186+ else if (kind == 2 ) {
187+ image[index] += glm::vec3 (intersec.uv , 1 .f );
188+ }
189+ }
190+
159191// computeIntersections handles generating ray intersections ONLY.
160192// Generating new rays is handled in your shader(s).
161193// Feel free to modify the code below.
@@ -244,10 +276,7 @@ __global__ void pathIntegSampleSurface(
244276 PathSegment& segment = segments[idx];
245277 thrust::default_random_engine rng = makeSeededRandomEngine (iter, idx, 4 + depth * SamplesConsumedOneIter);
246278
247- Material material = scene->devMaterials [intersec.matId ];
248- if (material.baseColorMapId > NullTextureId) {
249- material.baseColor = scene->devTextureObjs ->linearSample (intersec.uv );
250- }
279+ Material material = scene->getMaterialWithTexture (intersec);
251280
252281 glm::vec3 accRadiance (0 .f );
253282
@@ -339,24 +368,20 @@ __global__ void singleKernelPT(
339368 thrust::default_random_engine rng = makeSeededRandomEngine (iter, index, 0 );
340369
341370 Ray ray = sampleCamera (cam, x, y, sample4D (rng));
342-
343371 Intersection intersec;
344372 scene->intersect (ray, intersec);
345373
346374 if (intersec.primId == NullPrimitive) {
347375 goto WriteRadiance;
348376 }
349377
350- Material material = scene->devMaterials [intersec.matId ];
378+ Material material = scene->getMaterialWithTexture (intersec);
379+
351380 if (material.type == Material::Type::Light) {
352381 accRadiance = material.baseColor * material.emittance ;
353382 goto WriteRadiance;
354383 }
355384
356- if (material.baseColorMapId > NullTextureId) {
357- material.baseColor = scene->devTextureObjs ->linearSample (intersec.uv );
358- }
359-
360385 glm::vec3 throughput (1 .f );
361386 intersec.wo = -ray.direction ;
362387
@@ -400,7 +425,7 @@ __global__ void singleKernelPT(
400425 if (intersec.primId == NullPrimitive) {
401426 break ;
402427 }
403- material = scene->devMaterials [ intersec. matId ] ;
428+ material = scene->getMaterialWithTexture ( intersec) ;
404429
405430 if (material.type == Material::Type::Light) {
406431#if SCENE_LIGHT_SINGLE_SIDED
@@ -547,10 +572,15 @@ void pathTrace(uchar4* pbo, int frame, int iter) {
547572 singleKernelPT<<<singlePTBlockNum, singlePTBlockSize>>> (
548573 iter, Settings::traceDepth, hstScene->devScene , cam, devImage, cam.resolution .x , cam.resolution .y );
549574 }
550- else {
575+ else if (Settings::tracer == Tracer::BVHVisualize) {
551576 BVHVisualize<<<singlePTBlockNum, singlePTBlockSize>>> (
552577 iter, hstScene->devScene , cam, devImage, cam.resolution .x , cam.resolution .y );
553578 }
579+ else {
580+ previewGBuffer<<<singlePTBlockNum, singlePTBlockSize>>> (
581+ iter, hstScene->devScene , cam, devImage, cam.resolution .x , cam.resolution .y ,
582+ Settings::GBufferPreviewOpt);
583+ }
554584
555585 if (guiData != nullptr ) {
556586 guiData->TracedDepth = Settings::traceDepth;
0 commit comments