View Full Version : What is the best & most realistic method of rendering a starfield??
10-29-2004, 05:30 AM
I'm trying to write a small space game where you can fly around in space (obviously). What do you guys think is the best method of rendering a 360 degree starfield in OpenGL? At the moment I've basically created a cube which is texture mapped with a 512x512 star texture. I'm not really happy with it though as you can tell that it's a cube. I tried a GLU sphere but the texture mapping was all stretched and it looked dreadful. The effect I'm looking for is exactly like the starfield in the 3D modelling program 'Lightwave'. If any of you haven't seen this, Lightwave can automatically create a sphere of stars and it looks really awesome. I might try a similar thing with OpenGL but create a sphere of points, though I'm not sure the points will look much like stars.
The other problem is how large do you need to make the stars? Ideally they would be placed at an infinite location but clearly this isn't possible in OpenGL so I've set my perspective with a maximum range of 15000 and put the star cube at 10000. It's still not really far enough away though. How far will OpenGL let you go with this? How do commercial space games do their starfields?? Thanks for reading this rather long-winded post. lol. :p
10-29-2004, 10:20 AM
Well, I've never tried to make a star field myself but it seems like an interesting topic so I'll just say a few things that come to mind. these are ideas and have never been implemented.
I'd probably stay away from a skybox implementation...I can't imagine a texture of a starfield looking all that convincing.
I'd probably almost always render the stars using a modelview matrix that ignores any z translations, they're *really* far away...for all intensive purposes i would render them to make them appear really far away and never make them seem to be approaching.
GL_POINTS certainly won't do. perhaps small point sprites of a radial gradiant?
stars flicker...i would try to replicate that in the star field, something very subtle.
I haven't seen the starfield you mentioned earlier, are there screen shots anywhere?
proabably wasn't much help, but i felt like thinking about it a little. :)
10-29-2004, 10:53 AM
Hmm, I've never made a starfield, but I'd prolly use random sized (within a range) texture mapped quadrics, with random positions. I find that skyboxes are good if the textures applied to them don't show where the textures meet (in the corners). If the textures were made with that in mind the skybox would look awesome. If you go to this link GameTutorials (http://www.gametutorials.com/Tutorials/opengl/OpenGL_Pg5.htm) and download the "Frustum Culling" tut you will find a perfect example of this.
Actually, when I first did that tut, I thought of how it could be used, quite easily, to make a space game.
Hope that helps. :D
10-29-2004, 12:07 PM
Avoid skyboxes for this, unless you want flat, fuzzy-looking starfields.
GL_POINTS are easy, fast and might look a lot better than you think. They'd certainly be more realistic than textured quads for all but the very brightest stars. Stars do look very very small in real life, and should look even smaller in a window assuming typical FOV angles. I did the math a while ago on how big the Sun should appear from around 1 AU (i.e. Earth) based on size, distance and FOV, and the result was quite a surprise - even in a large window, it *ought* to be only a few pixels across.
The single most important thing with point stars is colour. Don't make them all white; it'll look pants. Most stars will be smaller than a pixel, and vary a lot in apparent brightness, so draw them in random shades of grey. And don't worry about putting "twinkles" in; twinkling is an atmospheric effect, so you wouldn't see it when your viewpoint is in space.
Don't know what Lightwave's starfield looks like; without a screenshot it's hard to guess. Oh, and you might want to take a look at one of the astronomy simulators, such as Celestia (which I believe is open source, though I wouldn't swear to it).
10-29-2004, 12:14 PM
You didn't mention the platform you're working on, but assuming it's either Win32 or OS X, here\'s a link (http://p-squared.com/SpaceTime.php) that may help get you started.
10-29-2004, 12:41 PM
I'll second MikeC's nod for the points. I've implemented a point-based sky and it looked fantastic. Though, a textured *dome* can look quite nice too, if you get the curvature right, and the texture resolution is sufficient for the given view distance. In any case, you could sprinkle the sky with a few point sprites for the larger stars, planets, and misc effects.
10-29-2004, 07:34 PM
I've had good results with a Pov-ray generated
skyboxes using Galaxy (http://www.geocities.com/SiliconValley/Lakes/1434/galaxy.html)
I've also had pretty good results from texturing the inner part of a gluSpere. You might want to give it a try. It doesn't give a 3D effect but it looks nice. Try searching for a site from NASA I think that has some really good (and big!) image files of starfields.
11-02-2004, 07:30 AM
Thanks for all your advice guys. I'll start having a play with the different styles and let you know how it goes.
11-02-2004, 07:59 AM
I, too, had never made a starfield, but it seems like
something you can do easily if you are creative.
I would suggest that you avoid using textured mapped
objects, and stick with GL_POINTS. Also, excellent
advice by MikeC to use multiple colours or a white,
red, light blue, and mauve variety -- this is what
stars really look like.
Finally, there are two ways by which you can do the
arrangement of the points: 1) simply in the viewable
area, and 2) all around the "viewr's position."
I would do the latter one, because it is simple.
Also, the order by which you do things is critical.
I suggest that you first draw all the points
relative to the viewr's position with disabled
depth buffer. Then, enable the depth buffer and
render all other objects. What you should achieve
is aa starfield that simply looks like it rotates
relative to the observer and all stars are way far
at a distance.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.