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 about code #8

Open
UestcJay opened this issue Apr 14, 2022 · 6 comments
Open

question about code #8

UestcJay opened this issue Apr 14, 2022 · 6 comments

Comments

@UestcJay
Copy link

UestcJay commented Apr 14, 2022

many thanks for your great work!
I have question about the code, can you give me some more detailed explanation?
`
#Compute when the rays enter and leave the grid

offsets_pos = jax.lax.stop_gradient((radius - rays_o) / rays_d)
offsets_neg = jax.lax.stop_gradient((-radius - rays_o) / rays_d)
offsets_in = jax.lax.stop_gradient(jnp.minimum(offsets_pos, offsets_neg))
offsets_out = jax.lax.stop_gradient(jnp.maximum(offsets_pos, offsets_neg))
start = jax.lax.stop_gradient(jnp.max(offsets_in, axis=-1, keepdims=True))
stop = jax.lax.stop_gradient(jnp.min(offsets_out, axis=-1, keepdims=True))
first_intersection = jax.lax.stop_gradient(rays_o + start * rays_d)
`

@sarafridov
Copy link
Owner

Let's focus on a single ray. Then offset_pos is the distance along the ray at which the ray crosses the planes defined by the positive-coordinate faces of the grid cube, and offset_neg is the same but for the planes defined by the negative-coordinate faces of the cube. For example, if the radius is 1, then offset_pos would be a 3-vector containing the distance along the ray before it achieves x coordinate equal to 1, y coordinate equal to 1, and z coordinate equal to 1, respectively (and offset_neg would be a 3-vector with the same ray distances necessary to reach coordinate values of -1). For each coordinate direction, there are two potential points of intersection with the cube, one with the positive face and one with the negative face, stored in offset_pos and offset_neg.

For offset_in and offset_out, we want to know which of these two potential intersections is achieved first vs second. In other words, we want to know how far along the ray it is is potentially entering vs leaving the cube. In each dimension, the potential entry point is the face intersection with smaller ray distance (offset_in) and the potential exit point is the face intersection with larger ray distance (offset_out).

Finally, we want to know which face is actually entered and which is exited, if there is any intersection at all. The ray only actually enters the cube when it has passed the offset_in for all three dimensions, hence the definition of start with a maximum over offsets_in. Likewise, the ray exits the cube as soon as it does so in any of the three dimensions, hence the minimum in the definition of start. Note that if the ray does not actually intersect the cube, we will compute values such that stop < start and be left with essentially an empty ray.

@UestcJay
Copy link
Author

UestcJay commented Apr 18, 2022

many thanks for your reply!
1:Can I think that the origin of the world coordinate system is the center of the grid,
2: and is the code logic of the jax version the same as in svox2?
3:Is there a volume density in per vertex or per small cube in hte grid?

@UestcJay
Copy link
Author

Let's focus on a single ray. Then offset_pos is the distance along the ray at which the ray crosses the planes defined by the positive-coordinate faces of the grid cube, and offset_neg is the same but for the planes defined by the negative-coordinate faces of the cube. For example, if the radius is 1, then offset_pos would be a 3-vector containing the distance along the ray before it achieves x coordinate equal to 1, y coordinate equal to 1, and z coordinate equal to 1, respectively (and offset_neg would be a 3-vector with the same ray distances necessary to reach coordinate values of -1). For each coordinate direction, there are two potential points of intersection with the cube, one with the positive face and one with the negative face, stored in offset_pos and offset_neg.

For offset_in and offset_out, we want to know which of these two potential intersections is achieved first vs second. In other words, we want to know how far along the ray it is is potentially entering vs leaving the cube. In each dimension, the potential entry point is the face intersection with smaller ray distance (offset_in) and the potential exit point is the face intersection with larger ray distance (offset_out).

Finally, we want to know which face is actually entered and which is exited, if there is any intersection at all. The ray only actually enters the cube when it has passed the offset_in for all three dimensions, hence the definition of start with a maximum over offsets_in. Likewise, the ray exits the cube as soon as it does so in any of the three dimensions, hence the minimum in the definition of start. Note that if the ray does not actually intersect the cube, we will compute values such that stop < start and be left with essentially an empty ray.

sorry to bother you again! these codes also have questions, can you give me some more detailed explanation?:
count = int(resolution*3 / uniform) intersections = jnp.linspace(start=realstart + uniform*voxel_len, stop=realstart + uniform*voxel_len*(count+1), num=count, endpoint=False)

@sarafridov
Copy link
Owner

  1. Yes, the origin is the center of the grid.
  2. Generally no. The two versions compute the same rendering formula, but the implementations are quite different.
  3. This is not really an important distinction. In this implementation all values are stored per voxel, but a voxel isn't really that different from a vertex since we are doing trilinear interpolation anyway.
  4. count here is just a loose upper bound on the number of samples we might need along the ray. For JAX to JIT-compile, we need to have the same number of possible intersections along each ray (it's probably not the most efficient implementation; if you see a faster way feel free to submit a PR). There can't be more than 3*resolution voxel lengths along the portion of the ray inside the cube, and we are taking a sample every uniform fraction of a voxel length. Then the intersection points are just spaced out by this distance along the ray, starting where the ray first intersects the cube.

@UestcJay
Copy link
Author

sorry to bother you again! why the last intersection was discarded?
pt_sigma = jnp.sum(weights * neighbor_sigma, axis=1)[:-1]

@UestcJay
Copy link
Author

many thanks for your great work! I have question about the code, can you give me some more detailed explanation? ` #Compute when the rays enter and leave the grid

offsets_pos = jax.lax.stop_gradient((radius - rays_o) / rays_d) offsets_neg = jax.lax.stop_gradient((-radius - rays_o) / rays_d) offsets_in = jax.lax.stop_gradient(jnp.minimum(offsets_pos, offsets_neg)) offsets_out = jax.lax.stop_gradient(jnp.maximum(offsets_pos, offsets_neg)) start = jax.lax.stop_gradient(jnp.max(offsets_in, axis=-1, keepdims=True)) stop = jax.lax.stop_gradient(jnp.min(offsets_out, axis=-1, keepdims=True)) first_intersection = jax.lax.stop_gradient(rays_o + start * rays_d) `

@sarafridov Why directly divide by rays_d, what if the direction component is 0?

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