Yeah, 3D fractals are awesome.

But then, why do you rarely see procedural rendering used in games?

I mean, raymarching unlimited objects in real-time seems really useful, right?

Well, the problem is: Sure there's efficient ways to draw these objects, but how do you actually interact with them?

Well, I'm gonna show you Marble Marcher. It's a proof of concept to show that fractals

aren't just fun to look at, but real games can be built with them using a fractal physics engine.

The download link and source code are in the description.

If you want to understand how Ray marching works you'll definitely want to

check out my other video on that first, otherwise some of this video might not

make any sense. So what do we actually need for a physics engine? The most

critical and difficult piece is collision detection, and that's why it's

often the biggest source of glitches in modern games. Collisions are

fundamentally difficult, because the math is complicated and expensive, so games

make a lot of approximations, and they're always trying to balance accuracy with

speed. And even then, after a few thousand objects, things typically start to slow

down. Now we should have an opportunity to do better, because rendering a fractal

is really only rendering a single root object with a bunch of transformations

and folds applied to it. So how can we transfer this to the physics? Remember

how fractals have a really efficient distance estimator? Well this is actually

really useful. If our object is a sphere with a radius, then just by checking the

distance estimator, we can immediately know if we're intersecting or colliding

with the fractal if the distance is less than the radius. So problem solved, right?

Nope, knowing that you're colliding with something isn't enough, because you also

have to know how to react to the collision and unintersect yourself, and it's not obvious

how we would get that information efficiently, so I'm gonna put a big twist

on everything. Normally you compute folds and transformations a bunch of times and

then finally take the distance estimate of a root object, but let's say instead

of computing the distance, you compute the closest point? Okay but the closest

point on the root object isn't actually that useful. Once we have it though, we

can just unfold that point by undoing all of the transformations until

finally we have the closest point on the original fractal. That means it's just as

efficient as computing the distance. Using that point, it now allows us to

update the sphere so we know exactly the optimal direction and amount it needs to

move to avoid the collision, and that to me was an amazing discovery. It allows

extremely fast precise collisions with infinite objects. That inspired me to

make marble marcher, a marble racing game where you race on fractal surfaces to

reach the goal. Since everything is ray marched, you can take advantage of a

bunch of cool features, like reflection, refraction, soft shadows, dynamic lighting

ambient occlusion, and since nothing is baked, not even the physics, we can

actually have the entire fractal evolve during gameplay, and everything just

works. It even runs at 60 frames per second, no problems at all, though you

will need a really high end GPU for the high resolutions. There's one caveat

though, remember how we're dealing with distance estimates. To have the physics

work, that estimate needs to be really accurate. A lot of fractals have perfect

distance estimates, but some don't. I'm not sure what causes this problem. I

think it has something to do with using a scalar instead of a Jacobian matrix in

the estimate, but I just made sure to pick only fractals that worked, so it

wasn't a problem. And yeah, this game is free and open-source, so I really hope

you give the demo a try. It's truly unique, and I've never seen anything like

this before. I also really want to thank the artist Petty Theft for doing all the

music for the game and this video. Be sure to check out his Soundcloud. And for

anyone that dares to speedrun the game, these are my personal bests so far.

Thanks for watching, and have fun.