Skip to content

Commit af946be

Browse files
author
Bernhard Kerbl
committed
Support for fill color
1 parent cc408a2 commit af946be

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

cuda_rasterizer/forward.cu

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ __global__ void renderCUDA(
264264
float* __restrict__ final_T,
265265
uint32_t* __restrict__ n_contrib,
266266
const float* __restrict__ bg_color,
267+
const float* __restrict__ fill_bg_color,
267268
float* __restrict__ out_color)
268269
{
269270
// Identify current tile and associated min/max pixel range.
@@ -362,8 +363,13 @@ __global__ void renderCUDA(
362363
{
363364
final_T[pix_id] = T;
364365
n_contrib[pix_id] = last_contributor;
365-
for (int ch = 0; ch < CHANNELS; ch++)
366-
out_color[ch * H * W + pix_id] = C[ch] + T * bg_color[ch];
366+
367+
if(last_contributor == 0)
368+
for (int ch = 0; ch < CHANNELS; ch++)
369+
out_color[ch * H * W + pix_id] = fill_bg_color[ch];
370+
else
371+
for (int ch = 0; ch < CHANNELS; ch++)
372+
out_color[ch * H * W + pix_id] = C[ch] + T * bg_color[ch];
367373
}
368374
}
369375

@@ -378,6 +384,7 @@ void FORWARD::render(
378384
float* final_T,
379385
uint32_t* n_contrib,
380386
const float* bg_color,
387+
const float* fill_bg_color,
381388
float* out_color)
382389
{
383390
renderCUDA<NUM_CHANNELS> << <grid, block >> > (
@@ -390,6 +397,7 @@ void FORWARD::render(
390397
final_T,
391398
n_contrib,
392399
bg_color,
400+
fill_bg_color,
393401
out_color);
394402
}
395403

cuda_rasterizer/forward.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ namespace FORWARD
4848
float* final_T,
4949
uint32_t* n_contrib,
5050
const float* bg_color,
51+
const float* fill_bg_color,
5152
float* out_color);
5253
}
5354

cuda_rasterizer/rasterizer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ namespace CudaRasterizer
3838
const float tan_fovx, float tan_fovy,
3939
const bool prefiltered,
4040
float* out_color,
41-
int* radii = nullptr);
41+
int* radii = nullptr,
42+
const float* fill_background = nullptr);
4243

4344
static void backward(
4445
const int P, int D, int M, int R,

cuda_rasterizer/rasterizer_impl.cu

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ int CudaRasterizer::Rasterizer::forward(
205205
const float tan_fovx, float tan_fovy,
206206
const bool prefiltered,
207207
float* out_color,
208-
int* radii)
208+
int* radii,
209+
const float* fill_background)
209210
{
210211
const float focal_y = height / (2.0f * tan_fovy);
211212
const float focal_x = width / (2.0f * tan_fovx);
@@ -215,9 +216,10 @@ int CudaRasterizer::Rasterizer::forward(
215216
GeometryState geomState = GeometryState::fromChunk(chunkptr, P);
216217

217218
if (radii == nullptr)
218-
{
219219
radii = geomState.internal_radii;
220-
}
220+
221+
if (fill_background == nullptr)
222+
fill_background = background;
221223

222224
dim3 tile_grid((width + BLOCK_X - 1) / BLOCK_X, (height + BLOCK_Y - 1) / BLOCK_Y, 1);
223225
dim3 block(BLOCK_X, BLOCK_Y, 1);
@@ -318,6 +320,7 @@ int CudaRasterizer::Rasterizer::forward(
318320
imgState.accum_alpha,
319321
imgState.n_contrib,
320322
background,
323+
fill_background,
321324
out_color);
322325

323326
return num_rendered;
@@ -360,9 +363,7 @@ void CudaRasterizer::Rasterizer::backward(
360363
ImageState imgState = ImageState::fromChunk(img_buffer, width * height);
361364

362365
if (radii == nullptr)
363-
{
364366
radii = geomState.internal_radii;
365-
}
366367

367368
const float focal_y = height / (2.0f * tan_fovy);
368369
const float focal_x = width / (2.0f * tan_fovx);

0 commit comments

Comments
 (0)