-
Notifications
You must be signed in to change notification settings - Fork 760
Support view dependent & independent light decomposition #705
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
Open
RongLiu-Leo
wants to merge
9
commits into
nerfstudio-project:main
Choose a base branch
from
RongLiu-Leo:light-decomposition
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b7442ca
Update simple_viewer.py
RongLiu-Leo 32d843f
Update gsplat_viewer.py
RongLiu-Leo cac8815
Update rendering.py
RongLiu-Leo 4a8764e
Update simple_viewer.py
RongLiu-Leo 2e2bf45
Update gsplat_viewer.py
RongLiu-Leo 2872db1
black format
RongLiu-Leo 83218b4
Update simple_trainer.py
RongLiu-Leo 96b6368
Update rendering.py
RongLiu-Leo 0523113
Update rendering.py
RongLiu-Leo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,9 @@ def rasterization( | |
| packed: bool = True, | ||
| tile_size: int = 16, | ||
| backgrounds: Optional[Tensor] = None, | ||
| render_mode: Literal["RGB", "D", "ED", "RGB+D", "RGB+ED"] = "RGB", | ||
| render_mode: Literal[ | ||
| "RGB", "D", "ED", "RGB+D", "RGB+ED", "Diffuse", "Specular" | ||
| ] = "RGB", | ||
| sparse_grad: bool = False, | ||
| absgrad: bool = False, | ||
| rasterize_mode: Literal["classic", "antialiased"] = "classic", | ||
|
|
@@ -98,8 +100,10 @@ def rasterization( | |
|
|
||
| .. note:: | ||
| **Depth Rendering**: This function supports colors or/and depths via `render_mode`. | ||
| The supported modes are "RGB", "D", "ED", "RGB+D", and "RGB+ED". "RGB" renders the | ||
| colored image that respects the `colors` argument. "D" renders the accumulated z-depth | ||
| The supported modes are "RGB", "D", "ED", "RGB+D", "RGB+ED", "Diffuse", and "Specular". | ||
| "RGB" renders the colored image that respects the `colors` argument. | ||
| "Diffuse" renders view-independent RGB components while "Specular" renders view-dependent RGB components. | ||
| "D" renders the accumulated z-depth | ||
| :math:`\\sum_i w_i z_i`. "ED" renders the expected z-depth | ||
| :math:`\\frac{\\sum_i w_i z_i}{\\sum_i w_i}`. "RGB+D" and "RGB+ED" render both | ||
| the colored image and the depth, in which the depth is the last channel of the output. | ||
|
|
@@ -181,8 +185,10 @@ def rasterization( | |
| tile_size: The size of the tiles for rasterization. Default is 16. | ||
| (Note: other values are not tested) | ||
| backgrounds: The background colors. [..., C, D]. Default is None. | ||
| render_mode: The rendering mode. Supported modes are "RGB", "D", "ED", "RGB+D", | ||
| and "RGB+ED". "RGB" renders the colored image, "D" renders the accumulated depth, and | ||
| render_mode: The rendering mode. | ||
| Supported modes are "RGB", "D", "ED", "RGB+D", "RGB+ED", "Diffuse", and "Specular". | ||
| "RGB" renders the colored image, "Diffuse" renders view-independent RGB, | ||
| "Specular" renders view-dependent RGB, "D" renders the accumulated depth, and | ||
| "ED" renders the expected depth. Default is "RGB". | ||
| sparse_grad: If true, the gradients for {means, quats, scales} will be stored in | ||
| a COO sparse layout. This can be helpful for saving memory. Default is False. | ||
|
|
@@ -280,7 +286,15 @@ def rasterization( | |
| assert opacities.shape == batch_dims + (N,), opacities.shape | ||
| assert viewmats.shape == batch_dims + (C, 4, 4), viewmats.shape | ||
| assert Ks.shape == batch_dims + (C, 3, 3), Ks.shape | ||
| assert render_mode in ["RGB", "D", "ED", "RGB+D", "RGB+ED"], render_mode | ||
| assert render_mode in [ | ||
| "RGB", | ||
| "D", | ||
| "ED", | ||
| "RGB+D", | ||
| "RGB+ED", | ||
| "Diffuse", | ||
| "Specular", | ||
| ], render_mode | ||
|
|
||
| def reshape_view(C: int, world_view: torch.Tensor, N_world: list) -> torch.Tensor: | ||
| view_list = list( | ||
|
|
@@ -481,6 +495,11 @@ def reshape_view(C: int, world_view: torch.Tensor, N_world: list) -> torch.Tenso | |
| pass | ||
| else: | ||
| # Colors are SH coefficients, with shape [..., N, K, 3] or [..., C, N, K, 3] | ||
| # SH = 0 is the view-independent diffuse component, SH >= 1 are view-dependent specular components. | ||
| if render_mode in ("Diffuse", "Specular"): | ||
| colors = colors.clone() | ||
| sel = slice(1, None) if render_mode == "Diffuse" else slice(0, 1) | ||
| colors[..., sel, :] = 0.0 # Zero out the unwanted SH components. | ||
|
Comment on lines
+498
to
+502
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think this logic should live outside of the
|
||
| campos = torch.inverse(viewmats)[..., :3, 3] # [..., C, 3] | ||
| if viewmats_rs is not None: | ||
| campos_rs = torch.inverse(viewmats_rs)[..., :3, 3] | ||
|
|
@@ -515,7 +534,9 @@ def reshape_view(C: int, world_view: torch.Tensor, N_world: list) -> torch.Tenso | |
| sh_degree, dirs, shs, masks=masks | ||
| ) # [..., C, N, 3] | ||
| # make it apple-to-apple with Inria's CUDA Backend. | ||
| colors = torch.clamp_min(colors + 0.5, 0.0) | ||
| # view-dependent components are in [0, 1]. No need to add and clamp. | ||
| if render_mode != "Specular": | ||
| colors = torch.clamp_min(colors + 0.5, 0.0) | ||
|
|
||
| # If in distributed mode, we need to scatter the GSs to the destination ranks, based | ||
| # on which cameras they are visible to, which we already figured out in the projection | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we dont touch rendering.py we we remove these from here..