another universe heard from

Here’s a fun place to visit:

place1

As in the previous post, it’s a no-interpolation scalar field. However, this one is continuous, making normal vectors easier to calculate.

var field = function(x, y, z) {
	var a = 2 * Math.cos(1.2 * x);
	var b = 2 * Math.cos(0.7 * y);
	var c = 2 * Math.cos(1.3 * z);
	
	return (Math.sin(x + y + a) + Math.sin(y + z + b) + Math.sin(z + x + c)) / 3;
};

Changing the constants in the first three lines will create all sorts of wacky alternate realities.

we don’t need no interpolation

Polygonizing a scalar field takes time. The marching cubes algorithm is O(N³), so every unit of radius you want to polygonize increases the processing time by a factor of eight geometrically. The code that implements the scalar field runs within its inner loop. You’ll want this to be as fast as possible.

The set of functions (a) defined for all R³, (b) sufficiently interesting, and (c) fast isn’t a big club. We can create interesting surfaces by interpolating across noise sources (or pseduo-noise sources—see a few posts down), but a 3D interpolation is “fast” only in the sense of running in constant time.

Here’s a pleasant little alternative that I’ve been playing with.

var source = function(x, y, z) {

	var ix = Math.floor(x);
	var iy = Math.floor(y);
	var iz = Math.floor(z);

	return  Math.cos(ix * Math.cos(iy * Math.cos(iz)));
};

The marching cubes algorithm calls this function directly. There is no interpolation step, which cuts total runtime by an order of magnitude. Visually, it’s rough, but a start.

func

There are wide-open spaces and confined areas, plus that all-important sense of structure, making it something more than interpolated noise.

func2

It’s blocky, sure, but there are ways to modulate the field to round the surfaces. I’ll see what else I can come up with in future posts.