## Raymarching L-Systems

**category:**gfx [glöplog]

Rez: what flure said. It takes some time to "get it" initially (or it did for me at least.. plotting the intersection of a sphere with the scene along the path of a ray? Huh, what?) But once you get it (and it seems incredibly hard at first, but it really isn't) you'll find it is indeed quite easy. I'd say remembering all the opengl crap to set up a scene and render it is harder.

I find it more intuitive to think of the marching functions return value as the maximum distance you can travel in any direction without hitting the object(s) instead of some magical sphere moving around and changing its size.

But I think I'll try marching some fractals now :)

But I think I'll try marching some fractals now :)

@msqrt: that is indeed a much easier concept to get the idea with, at least it was for me. i think all this 'sphere marching' was kind of a scientific approach. i work in research at the moment, and most of the time it's really simple and intuitive conecpts wrapped up in unnecessary complex fornulae.

i do find myself suspecting that scientists try to look smarter than they really are quite often. but then again, it's just another type of language, and one can argue that it is much more precise...

i do find myself suspecting that scientists try to look smarter than they really are quite often. but then again, it's just another type of language, and one can argue that it is much more precise...

I think the 'sphere tracing' concept makes complete sense.. but only after you understand the basic concepts of ray marching. Then it's kind of obvious. But to begin with, yeah, it's quite baffling when terms like that are used. Here's a (hopefully) simple explanation of what it is:

You render the scene by tracing a ray, starting at the camera, and moving in steps out into the scene until it hits an object. Now, the length of each step is critical - each step is quite expensive so we want the minimum number of them. Short steps are accurate, but we need many of them, long steps are more efficient but we don't want to step past any objects.

So what we do, is find out how far each point on the ray is from the nearest object. This is where 'distance fields' come in. It's quite simple, we just have a formula that tells us the distance from a point to an object. If we have many objects, we get the distance from each, then take the minimum.

If we know the distance from the closest object, we know it's safe to march to the next point on the ray, and we can march by that distance and guarantee we won't go past anything.

That's basically it, it's just a way of knowing how fast you can move along that ray without missing stuff, so it's efficient. When we hit something (or get close enough to call it a hit, that helps with speed) we get the normal at that point (just by taking the distance to the object, from a few points around the collision point), add light and materials, and that's the pixel rendered.

And what is the 'sphere tracing' part? When we get the distance from the closest object, it's that. That distance is the intersection of a sphere, with the centre on the current position, and the scene. And the sphere is the space we can move the point in, without risking missing an object.

You render the scene by tracing a ray, starting at the camera, and moving in steps out into the scene until it hits an object. Now, the length of each step is critical - each step is quite expensive so we want the minimum number of them. Short steps are accurate, but we need many of them, long steps are more efficient but we don't want to step past any objects.

So what we do, is find out how far each point on the ray is from the nearest object. This is where 'distance fields' come in. It's quite simple, we just have a formula that tells us the distance from a point to an object. If we have many objects, we get the distance from each, then take the minimum.

If we know the distance from the closest object, we know it's safe to march to the next point on the ray, and we can march by that distance and guarantee we won't go past anything.

That's basically it, it's just a way of knowing how fast you can move along that ray without missing stuff, so it's efficient. When we hit something (or get close enough to call it a hit, that helps with speed) we get the normal at that point (just by taking the distance to the object, from a few points around the collision point), add light and materials, and that's the pixel rendered.

And what is the 'sphere tracing' part? When we get the distance from the closest object, it's that. That distance is the intersection of a sphere, with the centre on the current position, and the scene. And the sphere is the space we can move the point in, without risking missing an object.

Just image the distance function f(x,y,z) as the radius of a protecting sphere around any point [x,y,z] the function f is defined for. You can move inside this sphere without hitting anything.

Come on, the "Sphere tracing" concept is not that damn abstract as you all pretend.

Come on, the "Sphere tracing" concept is not that damn abstract as you all pretend.

It's not, but for me at least it made raymarching seem way more complex than it really is. Once I 'got it', yeah, it's a quite simple concept :)

yeah, it's quite an easy concept to begin with, also far from being too abstract. I was referring to (mathmatics based) science in general.

I think you meant that the overall number of steps is expensive, because a single step is quite cheap actually.

**Quote:**

Now, the length of each step is critical - each step is quite expensive so we want the minimum number of them

I think you meant that the overall number of steps is expensive, because a single step is quite cheap actually.

it's the same thing - longer steps = fewer steps, and a cheap step is still expensive when there's many of them :)

I agree with that, but you said and that was misleading, at least to me. also, i'm quite excessively splitting hairs today ;-)

**Quote:**

each step is quite expensive

well, maybe we should say each step *should* be cheap if you want to use many of them (I know I've done some stuff with quite expensive steps, and it hurts :D)

...this could develop into a german law text if we're going on like this :D

haha, 'how to raymarch', written by a lawyer :D

That pic is awesome IQ. I've looked up IFS, seen the article on your site but I cant get my head round how to raymarch them. Any ideas?

Still stuck on this :(