This assume you already have the algorithms implemented in a fragment shader. I will use GLSL, but one can easily just switch to HLSL for DX pipeline.

Animation and movement

Rotate a plane

vec3 planeOrientation = vec3(0.0, 1.0, 0.0);
float planeH = dot(pos, normalize(planeOrientation));
float box = sdBox(pos + vec3(1., -1.5, 0.), vec3(1.5));
return min(planeH, box);

Image for post

Then we can change where the plane is pointing to

vec3 planeOrientation = vec3(0.5 * sin(iTime), 1., 0.0);
float planeH = dot(pos, normalize(planeOrientation));
float box = sdBox(pos + vec3(1., -1.5, 0.), vec3(1.5));
return min(planeH, box);

Image for post

Move an object from within the SDF Call:

float d1 = sphere(pos + vec3(1.0, 0.0, 0.0), 2.0);

Move an object using time so it moves:

float d1 = sphere(pos + vec3(sin(iTime), 0.0, 0.0), 2.0);

Make the change of position more than between -1 and 1.

float d1 = sphere(pos + vec3(sin(iTime) * 6, 0.0, 0.0), 2.0);

Image for post

Make the animation quicker by changing the frequency

float d1 = sphere(pos + vec3(sin(iTime * 5.), 0.0, 0.0), 2.0);

Image for post

Make animation on more than one axis

float d1 = sphere(pos + vec3(sin(iTime * 5.),-abs(cos(iTime * 2.5)) * 12., 0.0), 2.0);

Image for post

Object combination

Chain SDF.

float planeDist = plane(pos);
float d1 = sphere(pos + vec3(3.0, -1.0, 0.), 2.);
float d2 = sphere(pos + vec3(-3.0, -1.0, 0.), 2.);
return min(planeDist, min(d1, d2));

Image for post

Show the object used by both object

Image for post
Image for post

float d1 = sphere(pos + vec3(3.0, -1.0, 0.), 2.);
float d2 = sphere(pos + vec3(3.5, -1.7, 0.), 2.);
return max(d1, d2);

Giving us:

Image for post

Remove a part from an object

float d1 = sphere(pos + vec3(-1.5, -1., 1.), 2.);
float d2 = sphere(pos, 2.);
return max(-d1,d2);

Let’s say I have two sphere and I want to remove the smaller from the bigger, as it carve a hole.

Image for post

float d1 = sphere(pos + vec3(-1., -1., 1.), 1.);
float d2 = sphere(pos, 2.);
return max(-d1, d2);

We have this as our main Map return

Image for post

Create a shell from two object

float d1 = sphere(pos + vec3(3.0, -1.0, 0.), 3.);
float d2 = sphere(pos + vec3(2., -1.7, 1.), 2.);
d2 = abs(d2) — .08;
return max(d1, d2);

Image for post

Shell an object using a plane

vec3 planeOrientation = vec3(
0.5 * sin(iTime),
sin(iTime), 1.2 * (cos(iTime)))
— sin(cos(iTime * 5.));
float planeH = dot(pos, normalize(planeOrientation));
float box = sdBox(pos + vec3(1., -1.5, 0.), vec3(1.5));
box = abs(box) — .1;
return max(planeH, box);

Image for post

Slice object and combine them with a plane

vec3 sliceOrientation = vec3(1., 1, -3.);
float pSlice = dot(pos, normalize(sliceOrientation));
float plane = plane(pos);
float box = sdBox(pos + vec3(1., -1.5, 0.), vec3(1.5));
box = abs(box) — .1;
return min(plane, max(box, pSlice));

Image for post

Leave a Reply

Your email address will not be published. Required fields are marked *