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