<p>In your example of a BVH cell partitioned along the x axis, if the ray is going left to right (increasing x), then the cell with the lower x comes first; but if it's going right to left (decreasing x), then the cell with the higher x comes first. So, you can look at the sign of the x component of the direction vector to determine which cell to test first.</p>

CC BY-SA 4.0
2019-12-04T07:18:37.963Z
2019-12-04T07:18:37.963Z
Nathan Reed
<p>I'm reading about BVH from PBRT. According to the book, in the linear bvh part using morton encoding:</p>

<blockquote>
  <p>An efficient way to perform a front-to-back traversal without incurring the expense of intersecting the ray with both child nodes and comparing the distances is to use the sign of the ray’s direction vector for the coordinate axis along which primitives were partitioned for the current node: if the sign is negative, we should visit the second child before the first child, since the primitives that went into the second child’s subtree were on the upper side of the partition point. (And conversely for a positive-signed direction.)</p>
</blockquote>

<p>I'm unable to understand how the sign of the ray's direction vector helps in deciding which child to visit. If the partitioning axis is x, doesn't the point with a lower x come in the 1st child? Or have I understood something wrong?</p>

<raytracing><bounding-volume-hierarchy><pbrt>
How to decide which child of BVH to visit based on sign of ray's direction vector?
Karthik
# How to decide which child of BVH to visit based on sign of ray's direction vector?

(Asked by: username_0 on 2019-12-03)

I'm reading about BVH from PBRT. According to the book, in the linear bvh part using morton encoding:

> An efficient way to perform a front-to-back traversal without incurring the expense of intersecting the ray with both child nodes and comparing the distances is to use the sign of the ray’s direction vector for the coordinate axis along which primitives were partitioned for the current node: if the sign is negative, we should visit the second child before the first child, since the primitives that went into the second child’s subtree were on the upper side of the partition point. (And conversely for a positive-signed direction.)

I'm unable to understand how the sign of the ray's direction vector helps in deciding which child to visit. If the partitioning axis is x, doesn't the point with a lower x come in the 1st child? Or have I understood something wrong?

**Tags:** raytracing, bounding-volume-hierarchy, pbrt


---

## 1 answers

### Answer by username_1 on 2019-12-04. Score: 1 | Accepted answer

In your example of a BVH cell partitioned along the x axis, if the ray is going left to right (increasing x), then the cell with the lower x comes first; but if it's going right to left (decreasing x), then the cell with the higher x comes first. So, you can look at the sign of the x component of the direction vector to determine which cell to test first.


---

