Friday 1 April 2011

Procedural Galaxy Generation

Where does the time go! I meant to have this blog completed last weekend but it quickly grew into two separate postings (more on that later).

When beginning with this project, I actually started with a top down mentality, my initial research was in creating a galaxy full of stars. Doing so gave me the first major problem that anyone creating on the scale of a galaxy on a computer will have, floating point precision, which I will discuss in another blog sometime soon.

There are many different galaxies but they can be categorized into three categories: elliptical, spiral and irregular. I focused on elliptical and spiral since those are the most common. An elliptical galaxy is really simple to create. All you need to do is generate points inside of a bounding sphere in a logarithmic fashion. Meaning that at the galactic core (center of galaxy) there will be a higher concentration of stars than the outer regions.


More fun and rewarding is creating a spiral galaxy, that is because our own Milky Way galaxy is a spiral galaxy. There are 2 elements to a spiral galaxy. The first is the globular cluster (center of the galaxy) where there is a higher concentration of stars similar to the elliptical galaxy. We create this the same way we created our elliptical galaxy. The second element are spiral arms, I found that using logarithmic spiral is the quickest way to accomplish these spiral arms. More on the Logarithmic Spiral can be found at the excellent Math World website.



How many spirals is up to the creator but I found that between 4-6 works best. Keep in mind that the spiral is not a flat surface but has depth where as the stars closest to the globular cluster vary further from the origin whereas the greatest extents of the arms are closer to the elliptical plane. Keeping in mind that there is a larger concentration of stars at the start of each logarithmic spiral (near the globular cluster) and the density trails off, I actually used a completely linear algorithm for the trailing off of the stars though a logarithmic algorithm would probably work better.



All and all I was very happy with my results. Creating this inspired me to go further but also taught me what I will discuss in the next blog post regarding floating point precision. The galaxy is very big and using a brute force approach can cause many problems.

Sunday 20 March 2011

Starting from somewhere

Welcome to this very barren blogspot. This blog will focus on a yet to be officially titled project I have been working on for well over a year, in the interim I've been calling it Cosmos. At this point I am completely focusing on the technology behind the project.

What is the project? Well, I have been writing code to create a real-time procedural galaxy, if you can imagine, simulating a galaxy on a computer can be a very daunting task, luckily there are tons of articles scattered across the internet discussing the very concept.

I will be using Torque 3D as the actual game engine for this project, the code is entirely written in C++ and HLSL at this point. I have been using Torque for the past 5 years and feel that it should speed my development time tremendously.

Queue Inception soundtrack...