This method for generating 3d star fields was originaly shown to me by Tepi... Thanks man.
I added 2d star field since the method is the same.
I added a warp field star map, a la Star Trek TNG style
The method consist of generating a 3d model using triangles that face the centre of the model.
Each triangle is located at a random distance from the centre of origin, each triangle displays a star from a texture.
The model is usually drawn at the location of the player.
Most of us have been brainwashed to make a square/plane with 2 triangles and set up the uv of the 2 triangle to display a texture... But this can be done using a single triangle as long as all the data resides in a triangle on the texture. Sure, a waste of space on the texture, but not a waste of space in the 3d model.
In this case, the system is smart enough to map multiple uv triangles from the texture for use by the multitude of 3d facets in charge of displaying the stars in the 3d world. So no space is wasted on the texture and a variety of stars can be displayed by the model. You can even animate the sprite if you want.
The system uses vertAPI2 to calculate the proper orientation and positions of the triangles
The function is
MakeStarMapModel(numstars, inerradius, outerradius, mizsize, maxsize, xshape, yshape, zshape, numcels):
numstars, number of stars
inerradius, radius where the stars start
outerradius, radius where the stars end
minsize, min star radius
maxsize, max star radius
xshape, shape, 0 (plate) to 1 sphere to 2 or more (egg)
yshape, shape, 0 (plate) to 1 sphere to 2 or more (egg)
zshape, shape, 0 (plate) to 1 sphere to 2 or more (egg) .5 would flatten the sphere. .05 would be like our milky way
numcels, 2 for 2 stars like Template2Large, 4 for that 4x4 template, 8 for that 8x8 template and so on
I have included a few sprites in there, just change the sprite used in the create of the StraMapObj and the numcels parameter
Running in power saver mode, the field of 1000 stars displays at 500 fps on my laptop.
Warp Field functions
Add 2d star field functions
Followed Tepi's advise,
Added MakeStarMapModelTrueCol, same params, use a grayscale image for texture, the colors will be added to the model data, using the 7 common colors specified in by web site referenced by Tepi. FPS is 400, compared to 550
Added true color stars template... using 7 colors + one color duplicated, it's a color that is most common so it turned out right. So you can be back to that 550 FPS. the result is almost identical to the new function using the original function
Demo now places all stars at same distance, only the triangle size varies. So you can't really walk through the stars, which was never intended anyway. You loose perspective, which would be very minute in real world anyway. But the ability is still there via the parameters to the function in case you want some other wordly packed stars like the original demo
Added image alpha mask, and uses set_alpha_from sprite. this fixes the BUG above
Removed the original crappy texture with the odd star colors...
Added a tiny motion to the stars, so they seem to shimer, varying in intencity due to pixelation as well as the original dual draw method...
The default is now varying distance and constant size... The effect with the offset drawing and pixelation makes the stars glitter more, like atmospheric distortion.
Edited by icuurd12b42, 09 May 2010 - 05:26 AM.