Original Post
**Edit There is now a demo, see below for details [attachment=5417:star.zip]
The other day I decided to write a simple 3d based game, just something small and easy that I could and would actually finish. I decided to start by adding a pretty background, somehow this ended with me writing program to procedurally generate and render a galaxy of stars...
It is written in C++ using D3D10 pretty much all the work is done on the GPU, so really it's mostly in HLSL. It is split into two stages; generation and rendering, the generation stage is simply a geometry shader set to stream out a list of stars as point primitives, the rendering stages takes each point rendering as a quad sprite.
Currently I am focused on getting dynamic LoD working nicely; there are billions of stars in a galaxy, so obviously not all be drawn at the same time. To solve this; the galaxy is split into an 3d array of cubes, at each cube I take into account its distance from the camera and a density function to determine how many stars in this sector will be visible, the stars are generated in order of visibility, brightest first. The density function takes position of the cube as input and is of course what determines the shape the galaxy, changing this function would allow different shaped galaxies.
The drawing of the stars, as sprites is varied by distance so up close I can have clean points as stars and a cloudy galaxy when viewed from afar. Nothing pops in or out, every change is neatly faded, which is important and you can't really tell from screenshots.
The faint blue cloudiness in the background is simply a few octaves of Perlin noise, based on the two "Implementing Improved Perlin Noise" articles in Gpu Gems.
I think this could be useful Games of course; either to pregenerate a skybox/sphere, or rendered on the fly. The generation phase is most expensive but that only needs done when the camera moves a great distance (light years).
It is not finished, still a work in progress, a few things on the to-do list:
I intend when determining how many stars to draw, to try taking into account the density at the camera position, so less far away stars are drawn when actually in side a the galaxy.
When moving from a mid distance to a far distance the galaxy changes colour, probably as my render target becomes saturated, needs fixed.
Custom stars will be able to added at any position, rendered as normal but details specified instead generated.
Optimization of course, there's a lot to be done.
I thought I would post some screens and hopefully get some nice or useful feedback;
A far away shot;
http://i410.photobuc...amie1664/ss.jpg
A little closer;
http://i410.photobuc...mie1664/ss2.jpg
This is inside an arm looking at the core;
http://i410.photobuc...mie1664/ss3.jpg
This is inside the same arm again but looking away from the galaxy
http://i410.photobuc...mie1664/ss4.jpg
And finally this inside the core of the galaxy, the brighter strip at the bottom is the disc;
http://i410.photobuc...mie1664/ss5.jpg
The other day I decided to write a simple 3d based game, just something small and easy that I could and would actually finish. I decided to start by adding a pretty background, somehow this ended with me writing program to procedurally generate and render a galaxy of stars...
It is written in C++ using D3D10 pretty much all the work is done on the GPU, so really it's mostly in HLSL. It is split into two stages; generation and rendering, the generation stage is simply a geometry shader set to stream out a list of stars as point primitives, the rendering stages takes each point rendering as a quad sprite.
Currently I am focused on getting dynamic LoD working nicely; there are billions of stars in a galaxy, so obviously not all be drawn at the same time. To solve this; the galaxy is split into an 3d array of cubes, at each cube I take into account its distance from the camera and a density function to determine how many stars in this sector will be visible, the stars are generated in order of visibility, brightest first. The density function takes position of the cube as input and is of course what determines the shape the galaxy, changing this function would allow different shaped galaxies.
The drawing of the stars, as sprites is varied by distance so up close I can have clean points as stars and a cloudy galaxy when viewed from afar. Nothing pops in or out, every change is neatly faded, which is important and you can't really tell from screenshots.
The faint blue cloudiness in the background is simply a few octaves of Perlin noise, based on the two "Implementing Improved Perlin Noise" articles in Gpu Gems.
I think this could be useful Games of course; either to pregenerate a skybox/sphere, or rendered on the fly. The generation phase is most expensive but that only needs done when the camera moves a great distance (light years).
It is not finished, still a work in progress, a few things on the to-do list:
I intend when determining how many stars to draw, to try taking into account the density at the camera position, so less far away stars are drawn when actually in side a the galaxy.
When moving from a mid distance to a far distance the galaxy changes colour, probably as my render target becomes saturated, needs fixed.
Custom stars will be able to added at any position, rendered as normal but details specified instead generated.
Optimization of course, there's a lot to be done.
I thought I would post some screens and hopefully get some nice or useful feedback;
A far away shot;
http://i410.photobuc...amie1664/ss.jpg
A little closer;
http://i410.photobuc...mie1664/ss2.jpg
This is inside an arm looking at the core;
http://i410.photobuc...mie1664/ss3.jpg
This is inside the same arm again but looking away from the galaxy
http://i410.photobuc...mie1664/ss4.jpg
And finally this inside the core of the galaxy, the brighter strip at the bottom is the disc;
http://i410.photobuc...mie1664/ss5.jpg