## Raymarching Beginners' Thread

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

psonice: i know this' not actual geometry... so i wasn't talking about that kinda displacement. I just remembered the green jelly a few pages ago which didn't 'demarch' the surface in that league of detail. so...

anyway... this' nice development to see. ;)

anyway... this' nice development to see. ;)

**Quote:**

\o/ Another member of the "ball intersecting cube" club, welcome :D

Is it gay if the balls intersect?

las : wow it looks like a real time version of one of my favorite wild entry : http://www.pouet.net/prod.php?which=9489 vit by noice. A real time version was made some times ago but it sucks

yumeji: you take the formula that produces the spike ball, and comine it with the formula that makes the noise bump (guess it's the cellular noise?). You can change the size of either, making the spike ball big and the noise small gives a nice detailed surface. Combining a bunch of formulas + scales, you can make sexy objects like that :)

Rare: intersecting is about the opposite of touching, so I'd say no. We need to start adding objects instead of subtracting :)

Rare: intersecting is about the opposite of touching, so I'd say no. We need to start adding objects instead of subtracting :)

Nope it's three octave of perlin noise.

**Code:**

```
float d = spikeball(p);
d += fn(p*90.)*0.05;
```

A simple 5x5x5 blur on classic box minus sphere

Nice, but it is just so slow... and the surface is not smooth :(

Nice, but it is just so slow... and the surface is not smooth :(

Oh, you're blurring the object rather than the rasterised output? Cool :D

I quite like how it looks actually. Looks polygon rendered. Hmm.. smoothing the object is an interesting idea. Perhaps marching with different values for the bailout and mixing the result?

I quite like how it looks actually. Looks polygon rendered. Hmm.. smoothing the object is an interesting idea. Perhaps marching with different values for the bailout and mixing the result?

nice, missing smoothness gives it a cool look :)

hmm maybe "pretend" that there is a sphere on every point of the surface?

hmm maybe "pretend" that there is a sphere on every point of the surface?

How do you do that?

**Quote:**

return max(cube(), -sphere()) - radius;

Maybe? (Not tested at all.. i'll give it a go later)

The thing behind the idea is called "sphere swept surfaces" and I'm not yet sure how to do that in rm.

psonice: that does not work :)

psonice: that does not work :)

Hmm.. it doesn't. And I'm a bit confused as to why.

With it being raymarching, you don't need a sphere on every point of every surface - just a sphere on the nearest point (assuming the spheres are all the same size).

So, we get the distance to the nearest point (on the sphere/cube object - is there a name for it?). Then we subtract from that distance the radius of the sphere. That gives the distance to the closest point on a sphere on the surface of the object, no?

Well, except that it clearly doesn't work :D There's a big hole in my reasoning somewhere.

With it being raymarching, you don't need a sphere on every point of every surface - just a sphere on the nearest point (assuming the spheres are all the same size).

So, we get the distance to the nearest point (on the sphere/cube object - is there a name for it?). Then we subtract from that distance the radius of the sphere. That gives the distance to the closest point on a sphere on the surface of the object, no?

Well, except that it clearly doesn't work :D There's a big hole in my reasoning somewhere.

Something with moving the surface in the direction of the normal? Wild guess...

The direction doesn't matter, the sphere trace tells us the distance to the nearest surface, and the distance to the surface of a sphere at that point is always the same because it's a sphere. So distance to surface minus radius of sphere should be correct for all points on the surface.. but it doesn't work :)

Oh well, cases like this are good for learning. Sometimes. ;)

Oh well, cases like this are good for learning. Sometimes. ;)

Some AA distance field scenes here, with a fake global illumination.

XT95 - great! - how do you do the fake GI? Is it realtime?

XT95: nice. I remembered the distocubesub "shape" from ergon, but that's it!! ...and the rest is fake illumination? even more nice. ;)

las: not real time because of the big supersampling but it's possible ..

For the fake GI, it's a small trick, not normal oriented :

Just add a color and modulate her by the distance of the object

(Sorry for my bad english ..)

For the fake GI, it's a small trick, not normal oriented :

Just add a color and modulate her by the distance of the object

**Code:**

```
color += vec4(1.,.5,.1,1.) /(1.+object(p)*10.)
```

(Sorry for my bad english ..)

XT95: very nice. Cool trick with the lighting too, i was wondering how that worked when the long glowy shapes appeared :)

Any more thoughts on why subtracting a number from the minimum distance doesn't smooth the surface btw? That's really bugging me :)

It seems to just make the object bigger. Why does it keep a square corner on a (non-rounded) cube, when we're adding a fixed distance? That should make a rounded corner.

It seems to just make the object bigger. Why does it keep a square corner on a (non-rounded) cube, when we're adding a fixed distance? That should make a rounded corner.

XT95, thank you, great trick - just tried it - using an exponential falloff works also pretty nice.

psonice: that is because you subtract distance "everywhere" - draw a figure and you see what happens. You have to find a way to subtract less at some positions... maybe one needs to consider the curvature or something like that - didn't really think about it yet - I just wanted to share the "basic idea".

**Code:**

```
finalColor += objColor/(1.+exp(obj(p))*0.25)
```

psonice: that is because you subtract distance "everywhere" - draw a figure and you see what happens. You have to find a way to subtract less at some positions... maybe one needs to consider the curvature or something like that - didn't really think about it yet - I just wanted to share the "basic idea".

las: I drew a figure, it shows a cube getting bigger but with rounded corners :(

Really cool XT95! :)

XT95:

We (urs & me) just thought about an improvement - because it also lights objects that are facing away from the emitter... maybe multiplying with max(dot(gradF(p),-gradObj(p)), .0) might be a good idea (untested).

We (urs & me) just thought about an improvement - because it also lights objects that are facing away from the emitter... maybe multiplying with max(dot(gradF(p),-gradObj(p)), .0) might be a good idea (untested).

XT95 do you have an executable that generates this video?