top of page

Procedural Planets

About: 

A procedural planet generation system built from the ground up, this project highlights my proficiency in C# and algorithmic design. It demonstrates my capability to create dynamic, scalable environments with advanced procedural techniques, ensuring both performance optimization and creative flexibility in virtual world generation.

Technologies and Tools Used:

Programming Language:

C#

Game Engine:

Unity 6

Design Patterns:

  • Procedural Generation for terrain and textures.

  • Modular Architecture for planet creation.

Project Overview

I developed this system as a challenge to create a procedurally generated planet with dynamic features. It leverages Perlin Noise for terrain generation, with a modular architecture that allows flexible planet creation, including terrain, textures, and atmosphere, all designed for scalability and efficiency.

Challenges and Learnings:

This project enhanced my skills in several key areas:

  1. Procedural Generation: Mastering Perlin Noise for dynamic planet and terrain creation.

  2. Modular Design: Creating scalable systems for easy future expansion.

  3. Performance Optimization: Ensuring efficient rendering and resource management.

  4. Problem-Solving:  Addressing challenges in real-time generation and performance consistency.

  5. Code Clarity: Writing maintainable, well-documented code for future scalability

It reinforced the importance of clean architecture, efficient resource handling, and procedural techniques in game development.

Key Features:

  1. Modular Architecture:

    • Each feature, such as terrain generation, texture mapping, and planet creation, is encapsulated into distinct modules. This design ensures:​​

      • Ease of Expansion: New planet features or generation methods can be added easily.​

      • Improved Debugging: Isolated modules streamline issue identification.​

​

  • Procedural Terrain Generation:

    • Utilizes Perlin Noise for dynamic and varied planet terrains, allowing each planet to have unique features and elevations. This approach provides:

      • Endless Variety: Every generated planet is different.

      • Efficient Rendering: Optimized terrain generation for smoother performance.

​​

  • Dynamic Planet Creation:

    • The system allows for the generation of fully customizable planets with different textures, atmospheres, and terrain styles. Key benefits include:

      • Flexible Design: Easy customization of planetary attributes.

      • Real-Time Updates: Immediate feedback when generating new planets.

​

  • Real-Time Rendering:

    • The system ensures seamless rendering while generating and displaying planet features, keeping the process fluid and visually engaging.

​​​​​

Code Breakdown

Commit 1: Initial Setup:

  • The initial commit sets up the foundational classes for procedural planet generation.

  • Key Classes Introduced:

    • Planet.cs: Initializes planet generation and manages the terrain creation process.

    • ShapeGenerator.cs: Handles the procedural generation of the planet's surface

​​

​

Commit 2: Terrain Mesh Generation

The TerrainFace.cs class is introduced to handle terrain generation for each cube face of the planet.

  • This commit refines how terrain meshes are created by setting up vertices and triangles for each face.

  • Key Code Snippet:

    • The ConstructMesh() method generates vertices, triangles, and calculates UV coordinates.​

​

                                  Vector3[] vertices = new Vector3[resolution * resolution];

                                   int[] triangles = new int[(resolution - 1) * (resolution - 1) * 6];​

​

​

Commit 3: Shape Generator Integration

  • Elevation Calculation Using Perlin Noise:

    • The ShapeGenerator.cs class is further refined to calculate the unscaled elevation at each point on the planet's surface using Perlin Noise.​

  • Elevation is calculated based on the position on the unit sphere, and the heightmap is generated using Perlin Noise:

​

 float unscaledElevation =shapeGenerator.CalculateUnscaledElevation(pointOnUnitSphere);

​​

​

Commit 4: Biome and Color Mapping

  • Adding Biome Generation:

    • The ColorGenerator.cs is introduced to map biomes (e.g., desert, forest) based on the terrain's elevation and coordinates.

    • Uses Perlin Noise to determine the biome at each point on the planet's surface.

  • The BiomePercentFromPoint method is used to assign the correct biome based on terrain coordinates.

​

 uv[i].x = colorGenerator.BiomePercentFromPoint(pointOnUnitSphere);

​

​

Commit 5: UV Mapping and Texture Handling

  • UV Mapping for Texture Application:

    • The UpdateUV() method is added to handle the assignment of UV coordinates, which is necessary for applying textures to the planet's terrain.

    • UV mapping ensures the textures align with the terrain properly.

​

uv[i].x = colorGenerator.BiomePercentFromPoint(pointOnUnitSphere);

 

 

Commit 6: Optimization and Final Touches

  • Optimized mesh creation and improved resource management to reduce computational load.

    • Tweaks to improve the performance of terrain generation and texture mapping.

    • Efficient handling of meshes and textures to ensure that the procedural generation runs smoothly:

​

mesh.Clear();

mesh.vertices = vertices;

mesh.triangles = triangles;

​


                               

Conclusion

The Procedural Planets project demonstrates the use of procedural generation for creating dynamic, realistic planets in Unity. Key highlights include:

  • Modular Architecture for easy scalability and maintainability.

  • Perlin Noise for generating terrain and biomes, ensuring unique planets.

  • Efficient Resource Management for handling large, complex planets smoothly.

  • UV Mapping for accurate texture application across terrain.

This project showcases effective procedural generation and modular design, making it a solid foundation for creating diverse planets in game development.

bottom of page