1
$\begingroup$

I'm supposed to compute partial derivatives for 3D volume rendering (in ray tracing). I'm bad at math and so I can't understand what $f$ is in my case. In reviewing examples, I'm seeing the $f$ function being provided. Like in the Stewart Calculus textbook, the first given example defines a function $𝑓(π‘₯,𝑦)=π‘₯^2βˆ’3π‘₯𝑦+2𝑦^2βˆ’4π‘₯+5π‘¦βˆ’12$

My Basic Computation in 1D

I'm told that we have $f(x)$ (black squiggly)

enter image description here

Then for the derivative at any point on $x$, say $x_i$, I've been told I can use:

$f`(x_i) = df(x_i)/dx = [f(x_i) - f(x_i-1)]/dx$.

I'm told $dx$ is constant, so it is dropped:

$f`(x_i) = df(x_i)/dx = [f(x_i) - f(x_i-1)]$.

But what is $f$?

What if I have $x_i=2$, for example? Or any number, since that is the info I do know. Please explain what I do, or how I ascertain $f$.

Working in 3D

Once I understand the basics, I need to compute the values for 3D, meaning I need partial derivatives for $x$, $y$ and $z$. I've been given the formulas to achieve this:

$\frac{πœ•π‘“}{πœ•π‘₯} =\frac{1}{2}(f(x_{i+1}, y_j, z_k,) - f(x_{i-1}, y_j, z_k))$ $\frac{πœ•π‘“}{πœ•y} =\frac{1}{2}(f(x_i, y_{j+1}, z_k,) - f(x_i, y_{j-1}, z_k))$ $\frac{πœ•π‘“}{πœ•z} =\frac{1}{2}(f(x_i, y_j, z_{k+1}) - f(x_i, y_j, z_{k-1}))$

I have the required $x$, $y$ and $z$ ranges, so if I can understand the math, my goal is compute the three above values.

Note: based on this paper

$\endgroup$
1
  • $\begingroup$ $f$ is some function defined on your voxel grid. For example a density. $\endgroup$
    – lightxbulb
    Mar 5 at 20:28

1 Answer 1

1
$\begingroup$

You can't drop $dx$, since it "normalizes" the difference in function value $df$. Numerically, you assign a value to $dx$, vall it $\Delta x$. Then you approximate the derivative as $\frac{f(x+\Delta x)-f(x)}{\Delta x}$.

The paper suggests that $f$ is already known as input data, if I'm not mistaken.

In a grid, you only know $f$ in determined coordinates (or cells). In one dimension, you function might be defined in an interval $[a,b]$. This interval is discretized into $N$ cells, indexed using $i$. So you values are $\{ f_i \}_{i=0}^N$.

First, understand how your points are distributed. Including the boundary: $x_i = a + i \frac{b-a}{N-1}$ or only looking at the cell center: $x_i = a + \frac{b-a}{2N} + i \frac{b-a}{N}$. For these two cases, the distance between two gridpoints where $f$ is known is different. But lets assume the first case, then $dx \approx \Delta x = \frac{b-a}{N-1}$. This becomes your normalizing distance.

Then you must approximate the derivative. Note that your boundaries are "problematic" and one must be handled separately. We can approximate the first order derivative for $1 \leq i<N-1$ as: $\frac{df(x_i)}{dx} \approx \frac{f_{i+1}-f_i}{\Delta x}$. As you might figure out, when $i=N$ we can't index $i+1$. So we use the reverse derivative: $\frac{df(x_i)}{dx} \approx \frac{f_N-f_{N-1}}{\Delta x}$. Note that you might want higher order derivatives instead to avoid artifacts.

In higher dimensions you apply the same logic on each separate axis or index. If $f(\vec{x}): \mathbb{R}^3 \rightarrow \mathbb{R}$, then we will index $f$ as $f_{ijk}$ or whatever characters you want to use.

Edit: corrected a mistake

$\endgroup$
3
  • $\begingroup$ Are there any concrete examples you can point to? I'm not able to follow most of that :( $\endgroup$
    – Mote Zart
    Mar 6 at 22:56
  • 1
    $\begingroup$ I implemented a small demo at shadertoy: shadertoy.com/view/msy3Rh $\endgroup$
    – Mathis
    Mar 7 at 9:46
  • 1
    $\begingroup$ That's an awesome demo! $\endgroup$
    – Mote Zart
    Mar 7 at 14:37

Your Answer

By clicking β€œPost Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.