Tuesday, March 26, 2013

Starfield Builder (Iteration 2)

As part of the directx 11 port, I've finally revisited the starfield generator.  There isn't much new in this version, as it was mostly just porting dx9 to 11, but it finally draws textures on the quads for the stars, and colorizes them to match the actual star color.


The colors are very subtle, but still noticeable.  I'd rather have them that way, to be honest, instead of being obnoxiously in-your-face.

A simple re-write, but the results look much better!

Thursday, March 14, 2013

Ring Systems (Part 1)

I think it's pretty safe to say that Saturn's rings are one of the coolest things in the solar system (or at least one of the prettiest).  I've been wanting to give more love to rings for a while.  When I originally implemented them I was having quite a bit of stenciling problems (zbuffering doesn't work at these scales), and dropped them after I got them barely rendering.  Now that I've been slowly rebuilding every part of the engine to work with DirectX 11 I've come back around to gas giants.  Instead of doing the jovian shader immediately, I decided I really wanted to get rings right first (rationalizing to myself that they applied to all types of planets, and was thus a bigger step than just one specific type).

 The formation of ring systems isn't well understood, so I had to take a somewhat less-than-scientific approach to generating my own.  To over-simplify it, rings are basically a collection of particles inside of a planet's Roche Limit, meaning that the gravity of the primary is too strong inside that limit to allow them to coalesce into a planet.  I did a bit of reading on what we know about Saturn's rings and tried to nail down a way that they could be generated programmatically.  For a first iteration, I'm pleased with the results.

Structure


The Voyager probes were the first to discover that Saturn's rings were more complex than just the two main rings we could make out at our distance.  In reality, they are comprised of hundreds of thousands of tiny ringlets.  It's generally theorized that the structure of ring systems is closely tied to the moons orbiting the planet that hosts the rings.  The interaction of the gravity of the moons and planet with the ring particles creates "divisions" in the rings.  Moons that produce this effect are called "shepherd moons". 

To create the major structures I'm using a Weibull distribution modified by a portion of the number of moons the planet has.  There is a minimum value, so there is still some variety even if the planet has no moons.  "Major structures" includes rings and divisions.  By taking the modulus of the iterator in each loop I can alternate between divisions and rings.  An Inverse Gamma distribution is used to determine structure thickness, with the scale argument for divisions being smaller than rings.  Each structure is then written to the texture, with the alpha value varied using Perlin Noise to keep them from appearing as one solid color.

Here are some examples (each ring is given a random color to make them distinct during development):

Rainbow Rings!



There will be more on composition in a minute, but for now just know that each ring will have a general color.  To break up that homogeneity I added "minor structures", which are a randomly generated number of 1-texel wide rings roughly uniformly distributed throughout the major rings to add some flair.  Right now they're just green to make them stand out:



Composition & Color


Saturn's rings are comprised primarily of water-ice, with fragments of rock, dust, and minerals providing most of the color.  Right now all of the colors seen here are only for testing purposes.  Even though they look awesome, I don't want clown planets sprinkled around the galaxy.

This won't be implemented until much later, but the appearance of rings will eventually be determined by the composition of the planet they orbit.  The reason this feature is on hold for a while is because I have yet to figure out a good way to smear elements around the solar system with interesting distribution.  Before I can determine which elements will be present in the rings (and thus, which colors) I will need to determine the composition of the planet.

In general, lighter elements tend to be pushed into the outer solar system during stellar ignition (which is why all our outer planets are gas giants).  This is because when a star finally ignites the sudden burst of solar wind pushes the lighter elements away faster, leaving the silicates and heavy elements to form rocky planets.

Once I've finally managed to determine the composition of the planet I can take that and color the rings.  Right now I'm thinking that the more abundant materials of the planet will form the major rings, and the rarer and often brighter elements will provide the hint of variety in the minor rings.

Other Cool Stuff (in the future)


Eventually, I'll need to give the rings some real mass so that when you fly through them you don't realize it's really just a textured triangle ring.  Saturn's rings are made of particles ranging from a few centimeters to ten or more meters.  In terms of thickness, they range from a few meters to almost a kilometer.  In order to get this thickness, the shader will have to do a few things.  The first will be to fade away the texture nearest to the camera so there is a hole (in much the same way that you can't see the fog closest to you).  In order to fill that hole in the texture, I'll have to render dust specks in the field of view.  For more substantial particles, I haven't made up my mind on how to implement those.  Creating unique geometry on the fly for dozen or even hundreds of meter-sized asteroids seems like it would be a strain, even using geometry shaders.  Voxels may be the answer here, but I haven't yet implemented a sparse oct-tree renderer as it would be quite a task.

But I can dream.