Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blockspace

Minecraft-style voxel worlds generated entirely from mathematics. Two of them, each a single dependency-free HTML file — no engine, no assets, no build step.

Island → Walk an island whose every hill, beach and treeline falls out of one height function
Minimal surfaces → Fly through five triply periodic minimal surfaces as an endless labyrinth

Island

The island from the air

Everything you can see comes from one line of maths:

h(x,z) = sea + A · ( fBm(x,z) · mask(r) − 0.3 )

fBm is fractional Brownian motion — a sum of Perlin noise octaves at doubling frequency and halving amplitude. It is the reason the terrain has both broad hills and fine roughness at once, and the octave count is live: press [ and ] to add or remove terms and watch the same island get smoother or rougher. That is the whole idea of fBm, one term at a time.

mask(r) is a radial falloff that drops the coastline into the sea. Its input distance is warped by low-frequency noise — without that the mask dominates the noise and the island comes out a dome of concentric contour rings.

Everything else is a consequence. Blocks below the height get sand, grass, stone or snow by elevation. Trees are hash-placed on flat grass above the waterline, so the same seed always grows the same forest. Water fills every column up to sea level.

Standing among the trees

Controls

Input Action
Click Capture the mouse (falls back to drag-to-look where pointer lock is refused)
WASD Walk
Space Jump
F Toggle fly
Look, for when there is no mouse to capture
[ ] fBm octaves
= Sea level
R New island

Walking is a real AABB swept per axis against the voxel grid, with gravity and jumping. Water is not solid, so you can swim through it.


Minimal surfaces

A minimal surface has zero mean curvature everywhere — the shape a soap film takes. The five here are triply periodic: they tile space with period 2π in x, y and z.

That periodicity is the whole trick. The world repeats exactly, so a fixed 72³ block of geometry is all that is ever meshed; flying out of the middle period cell wraps the camera back into it, and because the field is identical one period over, the wrap is invisible. No chunk streaming anywhere.

Surface Level set
Gyroid sin x cos y + sin y cos z + sin z cos x = 0
Schwarz P cos x + cos y + cos z = 0
Schwarz D cos x cos y cos z − sin x sin y sin z = 0
Neovius 3(cos x + cos y + cos z) + 4 cos x cos y cos z = 0
Lidinoid ½(sin 2x cos y sin z + …) − ½(cos 2x cos 2y + …) = 0

A minimal surface also cuts space into two regions. The blocks fill one; you are flying in the other, and no route connects them. At thickness 0 the two are congruent — the demo reports 50.01% solid normally and 49.98% inverted, summing to 100%. Press I to swap sides.

Minimal surface interior


Implementation notes

Shared by both worlds.

Meshing. One quad per solid face that touches air, with the standard four-tap voxel ambient occlusion per corner. No greedy merging — the face counts land between 60k and 155k, which is a single uninteresting draw call. AO matters far more than triangle count for how solid this reads.

Textures are generated, not shipped. A 16×16 atlas is drawn procedurally into a canvas at startup — grass with a jagged fringe, dirt, sand, stone, snow, bark, growth rings, leaves, water — then uploaded with NEAREST filtering. No image files, no copyrighted assets, and the per-pixel grain is what makes a flat face read as material.

Texture orientation. On side faces the texture's v axis has to follow world +Y, or the grass fringe lands sideways. Each face carries its own corner→UV table derived from its normal axis.

Water is a second pass, blended with depth writes off and two-sided so it still reads from underneath. Opaque blocks emit a face against water as well as air, so the seabed stays visible through it. A single large quad at sea level keeps the horizon open water rather than the world's edge.

Input. Pointer lock where it is allowed, drag-to-look where it is refused (an iframe without allow="pointer-lock", or touch), and arrow-key look everywhere as a floor. The title card listens on the document rather than the canvas — it covers the viewport, so a canvas-only listener never fires.

Running it

git clone https://github.com/kamilch1k/blockspace.git

Open index.html in any browser with WebGL2.

Licence

MIT — see LICENSE. Not affiliated with Mojang or Minecraft; every texture is generated procedurally by the code in this repo.

About

A Minecraft-style voxel world carved by triply periodic minimal surfaces. One dependency-free HTML file, WebGL2.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages