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

Question for Parallel Light Sources #8

Open
HarryPeverell opened this issue Nov 29, 2024 · 1 comment
Open

Question for Parallel Light Sources #8

HarryPeverell opened this issue Nov 29, 2024 · 1 comment

Comments

@HarryPeverell
Copy link

HarryPeverell commented Nov 29, 2024

Hi ,

First of all, I would like to express my gratitude for the excellent work you've done on this project. It’s truly impressive, and I’ve found your approach to be very insightful.

I have a question regarding the dataset used in the project. It seems that the dataset is designed with point light sources in mind. If the light rays are parallel (as in the case of distant light sources or sunlight), could you please share the necessary modifications to the workflow for handling such changes in the light source? Any guidance on this would be greatly appreciated.

I look forward to your response, and thank you again for your great work.

Best regards,
Harry

@HarryPeverell HarryPeverell changed the title Question Regarding Shadow Splatting for Area and Parallel Light Sources Question for Parallel Light Sources Nov 29, 2024
@iamNCJ
Copy link
Owner

iamNCJ commented Nov 29, 2024

Hi, thanks for your interest. Parallel / Directional lighting can be implemented by setting the shadow_ray_d to the lighting direction and shadow_ray_o to a far distant point. Related code is at:

def get_visibility(self, pls, target_points, up_sample_steps=4,
cos_anneal_ratio=1.0,
offset=1e-2, perturb=False):
device = pls.device
n_samples = self.config.renderer.n_shadow_samples
n_importance_samples = self.config.renderer.n_shadow_importance_samples
with nullcontext() if self.config.renderer.shadow_hint_gradient else torch.no_grad():
shadow_ray_o = pls
shadow_ray_d = target_points - shadow_ray_o

which can be changed into:

def get_visibility(self, olat_ray_dir, target_points, up_sample_steps=4,
                   cos_anneal_ratio=1.0,
                   offset=1e-2, perturb=False):
    device = olat_ray_dir.device
    n_samples = self.config.renderer.n_shadow_samples
    n_importance_samples = self.config.renderer.n_shadow_importance_samples
    with nullcontext() if self.config.renderer.shadow_hint_gradient else torch.no_grad():
        shadow_ray_o = target_points + olat_ray_dir * 10.
        shadow_ray_d = target_points - shadow_ray_o
        light_norms = torch.linalg.norm(shadow_ray_d, ord=2, dim=-1, keepdim=True)
        sample_dist = light_norms / n_samples

Besides, you should also change the lighting direction in the specular hint calculation part. From:

lit_dirs = F.normalize(rays_pl - hit_points, dim=-1, p=2)

to:

lit_dirs = rays_pl

To pass the lighting direction into the system with minimal changes, you can set the pl_pos in your custom dataset as your lighting direction (as they are all 3-channel vectors), and use pl_pos in the codebase as lighting direction.

It is also highly recommended to check the shadow and specular hint maps after your modification to make sure everything is working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants