Thursday, February 20, 2025

Building a Subdividing Cube for Procedural Planet Generation

Hey everyone! Welcome back to my journey into procedural planet generation. In my last post, I explored the pros and cons of using an icosphere versus a subdividing cube as the base mesh for a planet. After weighing the options, I decided to go with the subdividing cube approach—and that’s what today’s post is all about!

🔗 Code is now public on GitHub: Raiblin/ProceduralPlanet

⬇️ (Interactive demo below) ⬇️


Why a Subdividing Cube?

The main reason I went with a subdividing cube is that it plays really nicely with level of detail (LOD) systems. Each face of the cube starts as a simple rectangle, which is subdivided into smaller quads. This structure is super helpful when you need to zoom in and out of the planet, as you can dynamically adjust the subdivision level per face without running into awkward geometry seams.

Plus, handling neighbors is straightforward—since each face is a grid, you don’t have to worry about complicated adjacency calculations. (If you’ve ever tried stitching different LOD levels on an icosphere, you’ll know the pain I’m talking about! 😅)


How It Works (Without Drowning in Code)

I won’t paste the full code here (check out the GitHub repo if you’re curious), but here’s the general idea:

1. Starting with a Cube

We begin with a basic cube defined by eight corner vertices. Each face of the cube is identified by a set of four vertices.

2. Subdividing the Faces

Each face is represented by a rectangle that’s recursively subdivided. Every subdivision splits the face into smaller quads, which can then be subdivided further. This creates a flexible grid system that scales easily.

3. Projecting onto a Sphere

To turn the cube into a planet, we normalize the vertices of each face (stretching them outward from the center) and scale them to the desired radius. This step morphs the cube into a sphere. One challenge here is minimizing distortion at the cube's corners, but proper spherical projection helps smooth that out.

4. Wireframe Toggle (for Visualization)

I added a wireframe toggle (press F1) to visualize how the faces subdivide. This helps me (and you!) see the underlying mesh structure, which is crucial for debugging LOD transitions.


What’s Interesting About This Approach?

  • Dynamic Level of Detail: The grid-like structure of each face makes LOD adjustments smooth and neighbor-friendly. No weird cracks between faces!
  • Randomized Colors (for now): Each face gets a random color for visualization. Eventually, I’ll replace this with terrain textures.
  • Efficient Midpoint Calculations: Subdividing rectangles involves a lot of midpoint calculations. I implemented a caching system to avoid recalculating the same points over and over—it’s a small optimization that adds up as subdivisions increase.

Try It Out!

Check out the live demo below:



Controls:

  • W / S: Move forward/backward
  • Mouse: Look around
  • F1: Toggle wireframe

What’s Next?

With the basic subdividing cube working, my next focus will be:

  • Implementing adaptive LOD so areas closer to the camera have higher detail.
  • Exploring terrain heightmaps to add mountains and valleys.
  • Reducing corner distortion with improved spherical mapping techniques.

Final Thoughts

So far, I’m really happy with how the subdividing cube is shaping up (pun intended 😎). It’s flexible, efficient, and—most importantly—easy to expand on. There’s still a long road ahead, but getting this foundational geometry in place feels like a solid step forward.

I’ll be sharing more updates soon, including details on LOD transitions and terrain generation. In the meantime, feel free to explore the code on GitHub and let me know your thoughts!

Until next time,
Ciaran

Friday, February 14, 2025

Icosahedron vs. Subdividing Cube: Choosing a Base for My Procedural Planet

 

Icosahedron vs. Subdividing Cube: Choosing a Base for My Procedural Planet

Hey everyone! 👋 Welcome to my second post since relaunching Decade Engine. After shaking off the dust from my old projects, I’ve jumped headfirst into building a procedural planet system. Today, I want to walk you through my initial research on how to structure the planet mesh and explain why I’ve chosen a subdividing cube over an icosphere as my base.

If you scroll down, you’ll see a little demo of my current work—a simple icosphere with basic movement controls:

The GitHub repository for this project isn’t public yet, but I’ll share the link in a future post once it’s ready!


Rising from the Digital Dust: Decade Engine Returns!

 

Well, this is awkward... Thirteen years, huh? I guess I really took my time getting back to this blog! Honestly, I’m half convinced no one reads blogs anymore, but here I am, typing away into the void. If you’ve somehow stumbled across this post—hi! You’re a legend. Drop a comment and make my day.

So, where have I been? Life, my friends. Life happened. In the time since my last post, I’ve been on quite the journey. I got married, had kids, and built a career that’s taken me to CTO and founder roles across multiple tech startups. But through all the chaos and milestones, this little blog has quietly lived in my browser favourites. Every now and then, I’d click on it—just to relive the joy of those nights spent wrestling with C++ and dreaming up procedurally generated worlds.

I never finished the procedural planet system back then. The project ended on a heartbreak: the hard drive holding my code corrupted during my move to Australia. Losing that work stung—so much that I couldn’t bring myself to start over. But the itch never went away.

So here we are—take two! This time, I’m swapping C++ for TypeScript and WebGL. I toyed with using Three.js (because, let’s be real, it’s fantastic), but I decided to stay low-level. Part of the fun was always getting my hands dirty with the nitty-gritty. I rarely get to do that these days, so this project is my playground.

I’ve even got a proper home for it: proceduralplanet.com—a domain I’ve owned for a decade and never used. (Procrastination level: expert.) All my code will be up on GitHub for anyone curious—or foolish—enough to peek inside.

So, will anyone read this? Honestly, who knows? Blogs feel a bit like digital time capsules these days. But I’m not doing this for the clicks—I’m doing it for the same reason I did it back then: because it’s fun. Still, if you are reading this, leave a comment and say hi. It’d be great to know I’m not the only one out here talking to the void.

Here’s to new beginnings—again.

Cheers
Ciarán