Sign in to follow this  
Ilici

Raymarching

Recommended Posts

Ilici    862
I've read in many places that raymarching is used in volumetric rendering/lighting but I couldn't find any helpful resources on it. The only thing I found out is
Quote:
Raymarching is the process of stepping a trajectory through its collisions with surface elements
Any resources on this, papers, maybe source code?

Share this post


Link to post
Share on other sites
Max_Payne    757
If you can have access to it. The "Realistic Image Synthesis using Photon Mapping" book by Henrik Wann Jensen has a chapter about participating media, and it talks about ray marching.

The idea is just to subdivide the ray into a finite number of steps (short line segments), and at each step, compute the light interaction with the media the ray is going through.

Share this post


Link to post
Share on other sites
ApochPiQ    23059
The basic idea is pretty simple. We use the standard definition for a ray:

Ray
{
Point3D Origin;
Vector3D Direction;
}


If the Direction vector is normalized, we can find a point on the ray x units away from the origin as follows:

Point = (x * Direction) + Origin


The distance value is also commonly referred to as the "time value" t. This should all be familiar up to this point - finding t is part of intersection testing, for instance.


Now, suppose we have some function f(x,y,z) that defines some interesting data, say the density of a particle field. If we sample this function at any point P, we will get the density of the field at that point. The basic idea of volumetric rendering is that we can determine the total apparent density of the field along a line of sight ray R by integrating the function f() at each point along the ray.

Generally, however, this integration cannot be solved analytically (at least not in the general case) so we have to evaluate the integral by numerical methods. This is where ray marching comes in. It essentially becomes the equivalent of a Riemann sum (or a trapezoidal summation if you use the appropriate algorithm) for the integration in question.

The implementation usually looks something like this:

- Determine t1 where the ray enters the volumetric field in question (may be 0)
- Determine t2 where the ray exits the field (if this is very large/infinite, we can just stop integrating when the density total reaches some arbitrary value)
- Find the point on the ray at t1 and evaluate the function
- Add the result to the cumulative total
- Increment t by some small value (the march step size) and repeat
- Continue this process until t2 is reached (or density becomes some threshold, usually 1.0)


Usually, you will sample something more interesting than just a density. For example, to illuminate a participating medium with photon mapping, you first trace photons into the medium and attenuate their strength by the density of the medium, and then trace rays into the medium and sample the illumination strength at each point. Full details of this are of course presented in Jensen's book.

If you can't get ahold of a copy (or to tide you over while it's in the post) check out his site - he has a lot of great papers freely available for download that cover much of the same material. They're not quite as in-depth and they don't explain the maths as clearly in a lot of cases, but they're much better than stabbing in the dark.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this