Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render accumulation (allow custom background blending) #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions diff_gaussian_rasterization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,24 @@ def forward(
ctx.raster_settings = raster_settings
ctx.num_rendered = num_rendered
ctx.save_for_backward(colors_precomp, means3D, scales, rotations, cov3Ds_precomp, radii, sh, geomBuffer, binningBuffer, imgBuffer)
return color, radii

accumulation = None
if raster_settings.return_accumulation:
alignment = 128
offset = (alignment - imgBuffer.data_ptr()) % alignment
total_size = raster_settings.image_height * raster_settings.image_width * 4
accumulation = (
imgBuffer[offset: offset + total_size]
.view(torch.float32)
.clone()
.mul_(-1)
.add_(1)
.view((raster_settings.image_height, raster_settings.image_width))
)
return color, radii, accumulation

@staticmethod
def backward(ctx, grad_out_color, _):
def backward(ctx, grad_out_color, _1, _2):

# Restore necessary values from context
num_rendered = ctx.num_rendered
Expand Down Expand Up @@ -167,6 +181,7 @@ class GaussianRasterizationSettings(NamedTuple):
campos : torch.Tensor
prefiltered : bool
debug : bool
return_accumulation : bool

class GaussianRasterizer(nn.Module):
def __init__(self, raster_settings):
Expand Down