I want to write a simple ray tracing(?) algorithm in WebGL with continuous refraction. So my idea was, what if you have a material whose optical density varies continuously, if this is physically possible?
So say you have some closed zero-set $A\subseteq\mathbf{R}^3$ and the optical density of some point $x$ in your world is $n(x):=\exp(-d(x,A)^2)$ where $d(x,A)$ is the distance between $x$ and (one of) the closest point to $x$ in $A$. I couldn't find a formula for this, but I assume it would be some limit of Snell's law where you you round $n(x)$ to some multiple of $\epsilon$ and let $\epsilon$ approach $0$.
What would be a good algorithm to approximate this? Basically my idea is to have a position and a direction, which describe the current stat of your ray, then you loop over some fixed number of iterations and in each step do
- compute the vector $v$ from the current position to the closest point in $A$ (I hope the set of $x$ with more than one closest point in $A$ is a zero-set and I will never encounter it),
- compute length of $v$ and its angle relative to the current travelling direction,
- then compute a new direction and some distance to travel, update the position and continue the loop, or break if you encounter some texture inbetween.
The idea is that the travel distances are shorter when you are closer to $A$, as the refraction index changes more rapidly here. How could the function for the last step look like?