Check out the new starfield and compare it with the old one.
Edit: thanks to fashai for pointing out an issue, I updated the code again - now the stars no longer form straight lines if the Silverlight control was invisible for some time. Also updated the speed algorithm, to be more close-to-nature 🙂
Source and demo below show the latest changes.
Some notes on how it is made below the stars 🙂
Source code: http://nokola.com/sources/StarField.zip
Do you like the new one or the old one better? Please comment
I made 4 improvements to the star field:
· First I fixed the star brightness to actually be from 0 to 1 (initially it was in the range 0..256).
· If you think about it, the further you look, the more stars you see. In the previous example, the further you look, the same number of stars you see. This takes a away a lot of the realism and feeling of "depth" to the field.
To fix this, I chose a 60 degrees viewing angle, then divided my "3d" space into 8 planes parallel to the screen (near to far plane).
Then, I compute the number of stars in each plane, based on the previous plane. The first plane contains 4 stars (chosen arbitrarily).
· The other fix is star speed – the further back stars are, the slower they appear to move. Fixed it – nice J
· Next one is star brightness – stars get dimmer based on the square of the distance from the viewer, not linearly
I also fixed a few bugs, and added some “magic” constants here and there. For example, the dimmest star is has alpha of 0.3…because I don’t want to waste resources on stars that are not noticeable on screen.