As a slight departure from my usual projects I thought it would be nice to see an animated galaxy model. I was hoping that there would be star coordinate data freely available on t’interwebs, Hipparcos is one, but the data is only for relatively nearby stars so you just end up with a sphere of stars centred on the Sun - not very interesting.
So I changed tack and re-used my terrain mesh building code to load a picture of a galaxy as a height-map. I used this one (can’t remember which galaxy it is though):
Obviously there is no ‘height’ as such in a flat image, to generate the galaxy disk and bulge I randomized the vertical coordinates, with the range being higher in the bulge and tapering off towards the edge of the disk. The colours of the ‘stars’ are the pixel colours in the image, after discarding pixels with a total luminance below a certain threshold, i.e. the resultant model does not have a ‘star’ for every pixel of the image, only the brightest ones.
Here’s a side-on view:
Edge on:
Close-up:
The galaxy model is rendered using a ‘point cloud’ mesh re-used from my particle system code, each ‘star’ is a point-sprite with the shader creating a imposter sphere, blended with the stars behind it and ordered by distance. With the cut-off threshold I applied there are about 50K stars in the model and it renders way above 60 FPS, though obviously goes slower as more stars are added.
I’m quite pleased with the results for what turned out to be relatively little work using (largely) existing code. It’s far from perfect and there’s plenty more that could be done: it doesn’t look too great close-up (perhaps to be expected), and the blending can look a bit clunky sometimes (need to experiment with other functions). I’d be interested to see if anyone else has tried anything similar.
- chris