@@ -17,7 +17,8 @@ RasterizeMeshesNaiveCpu(
17
17
const int image_size,
18
18
const float blur_radius,
19
19
const int faces_per_pixel,
20
- const bool perspective_correct);
20
+ const bool perspective_correct,
21
+ const bool cull_backfaces);
21
22
22
23
#ifdef WITH_CUDA
23
24
std::tuple<at::Tensor, at::Tensor, at::Tensor, at::Tensor>
@@ -28,7 +29,8 @@ RasterizeMeshesNaiveCuda(
28
29
const int image_size,
29
30
const float blur_radius,
30
31
const int num_closest,
31
- const bool perspective_correct);
32
+ const bool perspective_correct,
33
+ const bool cull_backfaces);
32
34
#endif
33
35
// Forward pass for rasterizing a batch of meshes.
34
36
//
@@ -55,6 +57,14 @@ RasterizeMeshesNaiveCuda(
55
57
// coordinates for each pixel; if this is False then
56
58
// this function instead returns screen-space
57
59
// barycentric coordinates for each pixel.
60
+ // cull_backfaces: Bool, Whether to only rasterize mesh faces which are
61
+ // visible to the camera. This assumes that vertices of
62
+ // front-facing triangles are ordered in an anti-clockwise
63
+ // fashion, and triangles that face away from the camera are
64
+ // in a clockwise order relative to the current view
65
+ // direction. NOTE: This will only work if the mesh faces are
66
+ // consistently defined with counter-clockwise ordering when
67
+ // viewed from the outside.
58
68
//
59
69
// Returns:
60
70
// A 4 element tuple of:
@@ -80,7 +90,8 @@ RasterizeMeshesNaive(
80
90
const int image_size,
81
91
const float blur_radius,
82
92
const int faces_per_pixel,
83
- const bool perspective_correct) {
93
+ const bool perspective_correct,
94
+ const bool cull_backfaces) {
84
95
// TODO: Better type checking.
85
96
if (face_verts.is_cuda ()) {
86
97
#ifdef WITH_CUDA
@@ -91,7 +102,8 @@ RasterizeMeshesNaive(
91
102
image_size,
92
103
blur_radius,
93
104
faces_per_pixel,
94
- perspective_correct);
105
+ perspective_correct,
106
+ cull_backfaces);
95
107
#else
96
108
AT_ERROR (" Not compiled with GPU support" );
97
109
#endif
@@ -103,7 +115,8 @@ RasterizeMeshesNaive(
103
115
image_size,
104
116
blur_radius,
105
117
faces_per_pixel,
106
- perspective_correct);
118
+ perspective_correct,
119
+ cull_backfaces);
107
120
}
108
121
}
109
122
@@ -274,7 +287,8 @@ RasterizeMeshesFineCuda(
274
287
const float blur_radius,
275
288
const int bin_size,
276
289
const int faces_per_pixel,
277
- const bool perspective_correct);
290
+ const bool perspective_correct,
291
+ const bool cull_backfaces);
278
292
#endif
279
293
// Args:
280
294
// face_verts: Tensor of shape (F, 3, 3) giving (packed) vertex positions for
@@ -296,6 +310,14 @@ RasterizeMeshesFineCuda(
296
310
// coordinates for each pixel; if this is False then
297
311
// this function instead returns screen-space
298
312
// barycentric coordinates for each pixel.
313
+ // cull_backfaces: Bool, Whether to only rasterize mesh faces which are
314
+ // visible to the camera. This assumes that vertices of
315
+ // front-facing triangles are ordered in an anti-clockwise
316
+ // fashion, and triangles that face away from the camera are
317
+ // in a clockwise order relative to the current view
318
+ // direction. NOTE: This will only work if the mesh faces are
319
+ // consistently defined with counter-clockwise ordering when
320
+ // viewed from the outside.
299
321
//
300
322
// Returns (same as rasterize_meshes):
301
323
// A 4 element tuple of:
@@ -321,7 +343,8 @@ RasterizeMeshesFine(
321
343
const float blur_radius,
322
344
const int bin_size,
323
345
const int faces_per_pixel,
324
- const bool perspective_correct) {
346
+ const bool perspective_correct,
347
+ const bool cull_backfaces) {
325
348
if (face_verts.is_cuda ()) {
326
349
#ifdef WITH_CUDA
327
350
return RasterizeMeshesFineCuda (
@@ -331,7 +354,8 @@ RasterizeMeshesFine(
331
354
blur_radius,
332
355
bin_size,
333
356
faces_per_pixel,
334
- perspective_correct);
357
+ perspective_correct,
358
+ cull_backfaces);
335
359
#else
336
360
AT_ERROR (" Not compiled with GPU support" );
337
361
#endif
@@ -372,7 +396,14 @@ RasterizeMeshesFine(
372
396
// coordinates for each pixel; if this is False then
373
397
// this function instead returns screen-space
374
398
// barycentric coordinates for each pixel.
375
- //
399
+ // cull_backfaces: Bool, Whether to only rasterize mesh faces which are
400
+ // visible to the camera. This assumes that vertices of
401
+ // front-facing triangles are ordered in an anti-clockwise
402
+ // fashion, and triangles that face away from the camera are
403
+ // in a clockwise order relative to the current view
404
+ // direction. NOTE: This will only work if the mesh faces are
405
+ // consistently defined with counter-clockwise ordering when
406
+ // viewed from the outside.
376
407
//
377
408
// Returns:
378
409
// A 4 element tuple of:
@@ -400,7 +431,8 @@ RasterizeMeshes(
400
431
const int faces_per_pixel,
401
432
const int bin_size,
402
433
const int max_faces_per_bin,
403
- const bool perspective_correct) {
434
+ const bool perspective_correct,
435
+ const bool cull_backfaces) {
404
436
if (bin_size > 0 && max_faces_per_bin > 0 ) {
405
437
// Use coarse-to-fine rasterization
406
438
auto bin_faces = RasterizeMeshesCoarse (
@@ -418,7 +450,8 @@ RasterizeMeshes(
418
450
blur_radius,
419
451
bin_size,
420
452
faces_per_pixel,
421
- perspective_correct);
453
+ perspective_correct,
454
+ cull_backfaces);
422
455
} else {
423
456
// Use the naive per-pixel implementation
424
457
return RasterizeMeshesNaive (
@@ -428,6 +461,7 @@ RasterizeMeshes(
428
461
image_size,
429
462
blur_radius,
430
463
faces_per_pixel,
431
- perspective_correct);
464
+ perspective_correct,
465
+ cull_backfaces);
432
466
}
433
467
}
0 commit comments