Jump to content
  • Advertisement
  • entries
  • comments
  • views

DevLog #7 - Galaxy arms (image based generating)

Sign in to follow this  


Hello again,
it's not much common for me to write entries somewhere too often, so I should better hurry to make this one before I change my mind ^_^
So, what happened in StarDust the last week? For long it looked I will have nothing, as the spiral arms of galaxy completely broke the images I presented in previous log entry. Simply it stopped looking good and I spent incredible amount of time by playing with blending parameters. But either the dust was too mild where layer was thin, or when increased the alpha channel it was too bright in the thick areas. Finally today it all came to fit together and I feel a huge relief from finishing the work (or at least a part of it) :D

So, lets start...
(This time I tell you the implementation details immediatelly here :wink:)

[size="3"]Spiral arms

As I already mentioned in previous entry, I wanted to create the arms from a galaxy image, instead of from a mathematical function only. At first I was afraid it will be harder than generating from a function, but it turned out to be not such a problem.
I use already one colored galaxy image in the scene for views from distance. When camera approaches the disc, the image is blended out. It appears only when leaving the Galaxy disc and looking back onto it. This image is 5600x5600 pixels large however and although it has a fine details of dust patches and clusters, going throught it and generating dust particles or stars in such resolution would kill my PC at this moment (not speaking about the memory it would take). So for the detection of spiral arms I use a smaller 214x214 b&w image with increased contrast (don't know how I came to these numbers :huh: ).

The image is parsed pixel by pixel, reading it's intesity. If the pixel's intensity is over a chosen treshold, a multiple dust clouds are randomly placed in an area covered by this pixel and their alpha is calculated from the pixel's intensity. E.g. in areas that are between the spiral arms are dark pixels, mostly under the treshhold and no dust is generated from them. Pixels closer to arms are brighter, reaching or exceeding the treshhold. From these the dust clouds are already generated, but with low alpha. Pixels in the arms are brightest, generating the dust clouds with greatest alpha channel and making them look more dense.
The only exception is area of Galaxy core, where should be no dust. So although this is the brightest area of whole image, it is ignored.

The blending for dust clouds is set to (GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA).

Galaxy prototype preview footage:
The scene contains 70,000 GL_POINTS and 20,000 blended GL_QUADS without optimizations.
The framerate is 2.5 - 3 fps (on a single core AMD Duron 1.8GHz, 2GB RAM, 128 VGA RAM).
The HyperCam reduced the framerate by half.
When disabling the GL_POINTS and keeping only the GL_QUADS, the framerate is around 18 fps.

Video was speeded up to make it smoother.



[size="3"]Galaxy glow

The galaxy glow is the same dust from previous log entry, using blending parameters (GL_SRC_APLHA, GL_ONE). This blending makes thicker layers (for example the core) appear "shining". The glow is also a subject to the same density map as the spiral arms (only with lower treshold), but has a different way of generating. Dust for arms was generated in a pixel-by-pixel pattern.
The glow is generated by taking a random radius from galaxy center and random angle on the horizontal (x-z) plane. From the X-Z coordinates is then calculated what pixel in the density map has been hit, and the pixel intensity is taken for alpha channel.
This approach results in increased density of glow particles around the center of the galaxy (it's the same as in previous log entry), even without the density map. The density map is just a minor addition for the glow.

[size="3"]Galaxy core

The MilkyWay as I am modelling it is a barred spiral galaxy. The core is not a spherical bulge, but a long bar. Lucky enough the areas on the sides of the bar are empty on the pictures from which I am generating, so I could tread everything in radius 10,000 ly from the center of galaxy as a core, like it would be a spherical bulge. I am not much sure how much it will affects the Near- and Far-3kpc arms later, but they looks fine for now.
When reading the density map, the area of core is ignored for generating dust. The glow on the other side is generated more in the core, and with increased Y-coordinate range. Everywhere else the dust, glow and star clusters after calculating their X-Z coordinates (either from map or from radius-angle) are given random Y coordinate in the limits of galaxy disc thickness. In the core the Y-limit is linearly increased from the core edge to the core centre. I tried also cosinus interpolation istead of linear, but that looked strange.


The halo around the galaxy is made by points. The largest density of the halo should be around the disc and reducing with growing distance. So I used similar radius-angle approach as in case of the galaxy glow, except I power the radius by 2 (intensyfying the reduction of density with distance) and use two angles here - horizontal angle (random 0 to 360?) and vertical angle (random -90? to 90?). This worked partially only. The density was greatest around the galaxy center, but not around whole disc. To fix it, I've multiplied the final Y coordinate (representing height), by random value from 0.0 to 1.0.
This pushed the points closer to the galactic plane and making a fine looking halo.

[size="3"]Smoothing the galaxy edges

The galaxy disc had one more flaw - it looked like a thin slice of some column, i.e. had sharp corners because the height in the disc was always generated within the limits of full disc thickness. At first I thought that I would multiply the Y coordinate simply by cosinus of radius from galaxy center, which would smooth the disc edges. But this wouldn't remove the same problem around the galaxy arms, where it appeared as well. So one more time the density map came to word and the pixel intensity not only influence the alpha channel of the generated element, but also the Y-limits. Darker pixels are reducing the limits, making the disc thinner, while brighter pixels are increasing the limits, making the disc thicker. The smoothing of edges is thus made thanks to the smoothness of image and gradual fading of galaxy disc (or arms) on the image into darkness.
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!