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

Update camera_ray_tracing.py: fix small bugs #726

Open
wants to merge 1 commit into
base: master
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
10 changes: 6 additions & 4 deletions examples/recipes/camera/camera_ray_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import torch
import numpy as np
from typing import Tuple
from kaolin.render.camera import Camera, CameraFOV
from kaolin.render.camera import Camera
from kaolin.render.camera.intrinsics import CameraFOV
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one isn't actually needed as __init__.py has:

from .intrinsics import *


def generate_pixel_grid(res_x=None, res_y=None, device='cuda'):
h_coords = torch.arange(res_x, device=device)
Expand Down Expand Up @@ -45,20 +46,21 @@ def generate_perspective_rays(camera: Camera, pixel_grid: Tuple[torch.Tensor, to

return ray_orig, ray_dir, camera.near, camera.far


img_width = 200
img_height =200
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Please fix the space here

camera = Camera.from_args(
eye=torch.tensor([4.0, 4.0, 4.0]),
at=torch.tensor([0.0, 0.0, 0.0]),
up=torch.tensor([0.0, 1.0, 0.0]),
fov=30 * np.pi / 180, # In radians
x0=0.0, y0=0.0,
width=800, height=800,
width=img_width, height=img_height,
near=1e-2, far=1e2,
dtype=torch.float64,
device='cuda'
)

pixel_grid = generate_pixel_grid(200, 200)
pixel_grid = generate_pixel_grid(img_width, img_height)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this snippet should be a simple recipe, I agree with your suggestion of having the raygen grid and image plane with the same resolution.
To complete the picture however - the raygen grid resolution and image plane resolution can actually differ, and this can also be exploited to, i.e., trace a lower-resolution image.

For reference, kaolin-wisp implements exactly that for its interactive mode:

  1. https://github.com/NVIDIAGameWorks/kaolin-wisp/blob/main/wisp/renderer/core/render_core.py#L167C9-L167C9
  2. https://github.com/NVIDIAGameWorks/kaolin-wisp/blob/main/wisp/renderer/core/render_core.py#L290

Picking an arbitrary resolution (which is not a power of 2 downscale factor) can indeed cause alignment issues, which I think it what you're worried about?

ray_orig, ray_dir, near, far = generate_perspective_rays(camera, pixel_grid)

print('Ray origins:')
Expand Down