We now describe our AMR cell volume rendering technique. First we demonstrate how to achieve high quality, semi-analytical preintegration of a single hexahedral cell, then we show that this technique can be extended to shaded volume rendering. Finally, we show how the first two subsections apply to AMR meshes by handling the case of adjacent cells of different AMR levels.

### 3.1 Single cell rendering

Our cell rendering technique can be decomposed into three stages: first we reconstruct the analytical function across the current viewing ray. Second, we carefully choose the sampling points over this analytical function according to its properties. Third, we apply the transfer function. We now describe these three stages in more detail.

Signal reconstruction. Trilinear signal reconstruction inside a hexahedral cell is a weighted sum of the eight scalar values *s*_{ijk} at the eight vertices of the cell. For a given point (*x* *y* *z*) inside a hexahedral cell of normalized coordinates in [0,1]^{3}, the trilinear interpolation of the signal *s*(*x* *y* *z*) is defined as follows:
TeX Source
$$\eqalign{ & s(x,y,z) = s_{000} \cdot (1 - x) \cdot (1 - y) \cdot (1 - z) + s_{100} \cdot x \cdot (1 - y) \cdot (1 - z) + \cr & \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,s_{010} \cdot (1 - x) \cdot y \cdot (1 - z) \cdot + s_{001} \cdot (1 - x) \cdot (1 - x) \cdot z + \cr & \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,s_{101} \cdot x \cdot (1 - y) \cdot z + s_{011} \cdot (1 - x) \cdot y \cdot z + \cr & \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,s_{110} \cdot x \cdot y \cdot (1 - z) + s_{111} \cdot x \cdot y \cdot z \cr} $$
where *s*_{ijk} is the sample value at the cell corner (*i* *j* *k*). Let us consider a single ray parametrized by *t* traversing a hexahedral cell. We can express the Cartesian coordinates (*x* *y* *z*) of a point over this ray as a function of *t*:
TeX Source
$$\eqalign{ & x = x_0 + t \cdot v_x \cr & y = y_0 + t \cdot v_y \cr & z = z_0 + t \cdot v_z \cr} $$
where (*x*
_{0} *y*
_{0} *z*
_{0}) are the entry coordinates of the ray in the cell, and (*v*_{x} *v*_{y} *v*_{z}) are the differences between the exit and entry coordinates. By replacing the *x* *y* and *z* coordinates with their parametrization over the ray in the trilinear interpolation formula, we can now compute *s*(*x* *y* *z*) over the ray as a function of the parameter *t*:
TeX Source
$$s(t) = a \cdot t^3 + b \cdot t^2 + c \cdot t + d,\,\,\,t \in [0,1]$$
with the *a* *b* *c* and *d* coefficients as follows:
TeX Source
$$\eqalign{ & a = (s_{100} - s_{000} + s_{010} + s_{001} + s_{111} - s_{110} - s_{011} - s_{101}) \cr & \,\,\,\, \cdot v_x \cdot v_y \cdot v_z \cr} $$
TeX Source
$$\displaylines{ b = (- x_0 \cdot v_y \cdot v_z - v_x \cdot y_0 \cdot v_z - v_x \cdot v_y \cdot z_0 + v_x \cdot v_z) \cdot s_{101} \cr + (x_0 \cdot v_y \cdot v_z + v_x \cdot y_0 \cdot v_z + v_x \cdot v_y \cdot z_0) \cdot s_{111} \cr + (v_y \cdot v_z - x_0 \cdot v_y \cdot v_z - v_x \cdot y_0 \cdot v_z - v_x \cdot v_y \cdot z_0) \cdot s_{011} \cr + (- v_x \cdot v_z + v_x \cdot v_y \cdot z_0 - v_y \cdot v_z + x_0 \cdot v_y \cdot v_z + v_x \cdot y_0 \cdot v_z) \cdot s_{001} \cr + (- v_x \cdot v_z + v_x \cdot y_0 \cdot v_z + v_x \cdot v_y \cdot z_0 - v_x \cdot v_y + x_0 \cdot v_y \cdot v_z) \cdot s_{100} \cr + (- v_x \cdot y_0 + v_z - x_0 \cdot v_y \cdot v_z + v_x \cdot v_y - v_x \cdot v_y \cdot z_0) \cdot s_{110} \cr + (v_x \cdot v_y + v_y \cdot v_z - v_x \cdot v_y \cdot z_0 + v_x \cdot v_z - x_0 \cdot v_y \cdot v_2) \cr - v_x \cdot y_0 \cdot v_2) \cdot s_{000} + (v_x \cdot v_y \cdot z_0 - v_y \cdot v_z - v_x \cdot v_y + x_0 \cdot v_y \cdot v_z) \cr + v_x \cdot y_0 \cdot v_z) \cdot s_{010} \cr} $$
TeX Source
$$\displaylines{ c = (- x_0 \cdot y_0 \cdot v_z + x_0 \cdot v_z + v_x \cdot z_0 - v_x \cdot y_0 \cdot z_0 - x_0 \cdot v_y \cdot z_0) \cdot s_{101} \cr + (v_x \cdot y_0 \cdot z_0 + x_0 \cdot v_y \cdot z_0 + x_0 \cdot y_0 \cdot v_z) \cdot s_{111} \cr + (y_0 \cdot v_z - x_0 \cdot v_y \cdot z_0 - v_x \cdot y_0 \cdot z_0 + v_y \cdot z_0 - x_0 \cdot y_0 \cdot v_z) \cdot s_{011} \cr + (x_0 \cdot y_0 \cdot v_z + v_z - y_0 \cdot v_z - v_y \cdot z_0 - x_0 \cdot v_z - v_x \cdot z_0 \cr + x_0 \cdot v_y \cdot z_0 + v_x \cdot y_0 \cdot z_0) \cdot s_{001} + (v_x \cdot y_0 \cdot z_0 + x_0 \cdot y_0 \cdot v_z \cr + x_0 \cdot v_y \cdot z_0 - v_x \cdot z_0 - v_x \cdot y_0 - x_0 \cdot v_z - x_0 \cdot v_y + v_x) \cdot s_{100} \cr + (x_0 \cdot v_y + v_x \cdot y_0 - x_0 \cdot y_0 \cdot v_z - x_0 \cdot v_y \cdot z_0 - v_x \cdot y_0 \cdot z_0) \cdot s_{110} \cr + (- v_x \cdot y_0 + x_0 \cdot v_y \cdot z_0 - y_0 \cdot v_z - x_0 \cdot v_y \cdot x_0 \cdot y_0 \cdot v_2 + v_y \cr + v_x \cdot y_0 \cdot z_0 - v_y \cdot z_0) \cdot s_{010} + (- x_0 \cdot v_y \cdot z_0 - v_z + v_x \cdot y_0) \cr - x_0 \cdot y_0 \cdot v_z - v_x \cdot y_0 \cdot z_0 - v_y + y_0 \cdot v_z + v_x \cdot z_0 + v_y \cdot z_0 \cr + x_0 \cdot v_y - v_x + x_0 \cdot v_z \cdot s_{000} \cr} $$
TeX Source
$$\displaylines{ d = (x_0 \cdot z_0 - x_0 \cdot y_0 \cdot z_0) \cdot s_{101} + (y_0 \cdot z_0 - x_0 \cdot y_0 \cdot z_0) \cdot s_{011} \cr + (- x_0 \cdot z_0 - y_0 \cdot z_0 + x_0 \cdot y_0 \cdot z_0 + z_0) \cdot s_{001} + (- x_0 \cdot z_0 + x_0 \cr + x_0 \cdot y_0 \cdot z_0 - x_0 \cdot y_0)s_{100} + (x_0 \cdot y_0 - x_0 \cdot y_0 \cdot z_0) \cdot s_{110} \cr + (- y_0 \cdot z_0 - x_0 \cdot y_0 + y_0 + x_0 \cdot y_0 \cdot z_0) \cdot s_{010} + (- y_0 - z_0 \cr - x_0 \cdot y_0 \cdot z_0 + x_0 \cdot z_0 + y_0 \cdot z_0 - x_0 + x_0 \cdot y_0 + 1.0) \cdot s_{000} \cr + s_{111} \cdot x_0 \cdot y_0 \cdot z_0 \cr} $$

Therefore, when using trilinear interpolation, the reconstructed signal over a ray traversing a hexahedron is a third degree polynomial in *t*.

Ray sampling. The next step consists in sampling the ray at the relevant values. In the context of ray casting, the sampling over the ray is usually homogeneous. Doing so is suboptimal when small structures are present in the dataset, as such a sampling could easily miss these structures. A naive solution would consist in analytically integrating the function over the interval, however for high frequency transfer functions this could quickly become inefficient. The alternative of preintegrating over the whole interval is not technically feasible either, as it would require a 5-dimensional preintegration table (4 scalar values which uniquely define the third degree polynomial along with the interval length). Instead, in order to avoid missing isovalues during the sampling stage, we sample at the entry and exit faces of the hexahedron, and also at the local extrema of the reconstructed function as shown on Figure 4. As we know the analytical form of the reconstructed function *s*′(*t*), we can compute its derivative *s*^{′}(*t*) analytically. Since *s*′(*t*) is a quadratic function, it has at most two roots, and *s*′(*t*) has at most two local extrema *r*
_{1} and *r*
_{2}. We compute the extrema of *s*(*t*), prune those that lie outside the cell and finally sort them along the ray. At this point we have reconstructed monotonic intervals for *s*(*t*) over the ray inside a given cell.

Transfer function application. The last stage is the application of the transfer function. Since the transfer function can be arbitrary, missing a single value in the previous stage can result in missing or discontinuous isosurfaces. We now begin with the standard volume rendering equation where *I* is the final intensity *c*() is the color transfer function and τ () is the opacity transfer function. If we have two extrema and both those extrema lie within [0,1], we get:
TeX Source
$$\displaylines{ I = \int_0^L {c(s(t))e^{ - \int_0^t {{\rm{\tau }}(s(u))du} } dt = \int_0^{r_1 } {c(s(t)})e^{ - \int_0^t {{\rm{\tau }}(s(u))du} } } \cr + \int_{r_1 }^{r_2 } {c(s(t))e^{ - \int_0^t {{\rm{\tau }}(s(u))du} } } dt + \int_{r_2 }^L {c(s(t))e^{ - \int_0^t {{\rm{\tau }}(s(u))du} } dt} \cr} $$
Over each interval [*t*1 *t*2], we replace *s*(*t*) with a linear form (1 − *t*) · *s*(*t*1) + *t* · *s*(*t*2) and obtain a formulation similar to [2]:
TeX Source
$$\eqalign{ & I \approx \int_0^{r_1 } {c((1 - t) \cdot s(0) + t \cdot s(r_1))e^{ - \int_0^t {\rm{\tau }} ((1 - u) \cdot s(0) + u \cdot s(r_1))du} } dt \cr & + \int_{r_1 }^{r_2 } {c((1 - t) \cdot s(r_1) + t \cdot s(r_2))e^{ - \int_0^t {\rm{\tau }} (s((1 - u) \cdot s(r_1) + u \cdot s(r_2)))du} dt} \cr & + \int_{r_2 }^L c ((1 - t) \cdot s(r_2) + t \cdot s(L))e^{ - \int_0^t {\rm{\tau }} ((1 - u) \cdot s(r_2) + u \cdot s(L)du} dt \cr & \approx C(s(0),s(r_1),r_1) + (1 - \alpha (s(0),s(r_1),r_1))C(s(r_1),s(r_2),r_2 - r_1) \cr & + (1 - \alpha (s(0),s(r_1),r_1)) \cdot (1 - \alpha (s(r_1),s(r_2),r_2 - r_1)) \cr & \cdot C(s(r_2),s(L),L - r_2) \cr} $$
with
TeX Source
$$\eqalign{ & C(a,b,l) = \int_0^1 {c((1 - t) \cdot a + t \cdot b)le^{ - \int_0^t {\rm{\tau }} ((1 - t) \cdot a + t \cdot b)ldu} dt} \cr & \alpha (a,b,l) = 1 - e^{ - \int_0^1 {\rm{\tau }} ((1 - t) \cdot b + t \cdot a)ldt} \cr} $$
Since over each monotonic interval, the ranges of *s*(*t*) and of its piecewise linear approximation are identical, we will not miss any isovalue when using piecewise linear approximations over these intervals. We are thereby able to ensure that all the volume features are present and have accurate topology according to the trilinear interpolation. As the topology is consistent from one frame to another, the only remaining kind of artifacts is wobbling of the surfaces and structures inside the cells as the viewpoint changes.

### 3.2 Extension to volume shading

We now demonstrate how to extend our approach to achieve local Phong shading with directional light sources; this process is described for the case of diffuse shading but straightforwardly generalizes to specular shading by using the half vector instead of the light vector. By analyzing the behaviour of the gradient inside the cell, we reconstruct a shading function over the ray and show how to use it to achieve high quality volume shading.

Shading computation. The gradient of the scalar function (as shown in Equation 1) can be obtained analytically by computing the partial derivatives of *s*(*x* *y* *z*). Diffuse shading *d*(*x* *y* *z*) is defined for any point of the cell as the dot product of this gradient with the light vector :
TeX Source
$$\displaylines{ d(x,y,z) = \overrightarrow \nabla s(x,y,z) \cdot \overrightarrow L = lx \cdot {{\partial s} \over {\partial x}} + ly \cdot {{\partial s} \over {\partial y}} + lz \cdot {{\partial s} \over {\partial z}} \cr = lx \cdot (- s_{000} - s_{011} \cdot y \cdot z + s_{101} \cdot z \cr - s_{101} \cdot z \cdot y - s_{010} \cdot y - s_{100} \cdot z - s_{100} \cdot y - s_{001} \cdot z \cr + s_{000} \cdot z + s_{000} \cdot y + s_{111} \cdot y \cdot z - s_{000} \cdot y \cdot z + s_{010} \cdot y + z \cr + s_{110} \cdot y - s_{110} \cdot y \cdot z + s_{100} + s_{100} \cdot y \cdot z + s_{001} \cdot z \cdot y) \cr + ly \cdot (- s_{000} - s_{011} \cdot z \cdot x - s_{101} \cdot x \cdot z - s_{010} \cdot z - s_{010} \cdot x \cr - s_{100} \cdot x - s_{001} \cdot z + s_{010} + s_{000} \cdot z + s_{000} \cdot x + s_{111} \cdot x \cdot z \cr - s_{000} \cdot x \cdot z + s_{010} \cdot x \cdot z + s_{110} \cdot x \cdot z + s_{100} \cdot x \cdot z \cr + s_{001} \cdot z \cdot x + s_{011} \cdot z) \cr + lz \cdot (- s_{000} - s_{011} \cdot y \cdot x + s_{101} \cdot x - s_{101} \cdot x \cdot y - s_{010} \cdot y \cr - s_{100} \cdot x - s_{001} \cdot y - s_{001} \cdot x + s_{000} \cdot y + s_{000} \cdot x + s_{111} \cdot x \cdot y \cr - s_{000} \cdot x \cdot y + s_{010} \cdot y \cdot x - s_{110} \cdot x \cdot y + s_{100} \cdot x \cdot y + s_{001} \cr + s_{001} \cdot x \cdot y + s_{001} \cdot y) \cr} $$

We again use the parametrization described in Equation 2 and obtain:
TeX Source
$$d(t) = e \cdot t^2 + f \cdot t + g $$
where *e* *f* and *g* can be trivially computed as previously done in Subsection 3.1 for *a* *b* *c* and *d*. For a parametrized ray inside a cell, the gradient variation over this ray is thus a quadratic form in *t*.

Ray sampling. In order to capture all the variations of the diffuse shading function, we sample this function at the cell faces and at the local extrema of *d*(*t*). Since *d*(*t*) is a quadratic polynomial, there is at most a single local extremum *r*. Therefore, if we apply shading on top of the previously described preintegration method, we only need at most one additional sampling point per cell. As in the case of scalar value integration, we thereby ensure that all extrema of the shading function are captured. We start from the volume rendering equation with diffuse shading; *c*() and τ () are defined as previously, and *d*() represents the diffuse shading coefficient.
TeX Source
$$\displaylines{ I = \int_0^L {c(s(t))d(t)e^{ - \int_0^t {{\rm{\tau }}(s(u))du} } } dt \cr = \int_0^r {c(s(t))d(t)e^{ - \int_0^t {\rm{\tau }} (s(u))du} } dt + \int_r^L {c(s(t))d(t)e^{ - \int_0^t {\rm{\tau }} (s(u))du} } dt \cr} $$
Over each interval [*t*1 *t*2], We replace *s*(*t*) with a linear form (1 − *t*) · *s*(*t*1) + *t* · *s*(*t*2), similarly to [11]. We obtain:
TeX Source
$$\displaylines{ I \approx d(s(0)) \cdot C_{front} (s(0),s(r_1),r_1) + d(s(r_1)) \cdot C_{back} (s(0),s(r_1),r_1) \cr + (1 - \alpha (s(0),s(r_1),r_1))(d(s(r_1)) \cdot C_{front} (s(r_1),s(L),L - r_1) \cr + d(s(L)) \cdot C_{back} (s(r_1),s(L),L - r1)) \cr} $$
with
TeX Source
$$\eqalign{& C_{back} (a,b,1) = \int_0^1 {c((1 - t) \cdot a + t \cdot b)te^{ - \int_0^t {{\rm{\tau }}(1 - t) \cdot a + t \cdot b)ldu} } } dt \cr & C_{front} (a,b,l) = \int_0^1 {c((1 - t) \cdot a + t \cdot b)(1 - t)e^{ - \int_0^t {x((1 - t) - a + t \cdot b)ldu} } } \cr & \alpha (a,b,l) = 1 - e^{ - \int_0^1 {\rm{\tau }} ((1 - t) \cdot b + t \cdot a)lbt} \cr} $$
At this point, the ranges for both the scalar and the shading functions are the same as their reconstructed counterparts over each of the integration intervals. The right of Figure 4 depicts this situation: the scalar function integration requires two additional samples, and the shading function integration requires one additional sample. The corresponding piecewise linear approximation for this function is shown in green. In that case, four integration steps over the ray are required to achieve accurate rendering.

Notice that since the reconstructed scalar field is only *C*^{0} across the cell faces, the gradient is not continuous across those faces. Therefore, shading is not continuous across the cell faces either.