Skip to main content
GameDev.net gamedev.net
🔒 Locked

Starfield generation

Started by SewageWorker Sep 27, 2003 at 10:05 PM 13 replies 3.4k views
Original Post
SewageWorker
SewageWorker
Hi, I''m making a space exploration type of game and I was thinking on how to make a starfield sort of thing. These are the current ideas that I have: 1- Use a cube around the world and stick pre-made textures on them. 2- Generate the stars at run-time and render them. Well the first option is a bit hard sinc I have to make high-detail star maps and also wouldn''t it drop the frame rate to load really huge images? number 2 I think is adequate but I have a problem, should I use tiny polygons with textures to render the stars? or should I use some technique to modify the individual pixels based on a starmap stored in memory? Thanks
DukeAtreides076
DukeAtreides076
I''d go with option two. Use a particle system. Also, you should probably work on modifying the individual pixels, since having each star as a polygon will probably give you a huge performance hit. A possiblity would be to have a textured cube around the world, and draw the stars by modifying the texture data.
hplus0603
hplus0603
Your images don''t need to be huge, because your screen resolution isn''t huge. 6 1024x1024 images in a cube would be plenty. Just draw these as your "sky box" (always centered on camera) and you have instant space.

Now, if you want the stars to get closer when you move towards them, then a single texture isn''t going to cut it; you need to render each star individually. Typically, you do that with points, until they get close enough to need sprites, and then you use sprites until you get close enough to use balls with transparent flare effects around them.
enum Bool { True, False, FileNotFound };
sakky
sakky
Here is my two dimensional start field.

‘ 2D Star Field at Runtime
Dim StrX( 0 to 320 ) as Integer
Dim StrY( 0 to 240 ) as Integer
Dim StrS( 0 to 320 ) as Integer

‘ Initialization loop
For I = 0 to 320
StrX( I ) = random_number_between_0_320
StrY( I ) = random_number_between_0_240
StrS( I ) = random_number_between_0_320
Next


‘ Main render loop
For I = 0 to 320
paint_pixel( StrX( I ), StrY( I ), black_color )

If StrS( I ) = 0 Then StrX( I ) = StrX( I ) + 1
If StrS( I ) = 1 Then StrX( I ) = StrX( I ) + 2
If StrS( I ) = 2 Then StrX( I ) = StrX( I ) + 3

If StrS( I ) = 0 Then paint_pixel( StrX( I ), StrY( I ), dark_gray )
If StrS( I ) = 0 Then paint_pixel( StrX( I ), StrY( I ), gray )
If StrS( I ) = 0 Then paint_pixel( StrX( I ), StrY( I ), white )

If StrX( I ) > 320 Then
StrX( I ) = -1
StrY( I ) = random_number_between_0_240
StrS( I ) = random_number_between_0_2
End If
Next

That is it. Replace the paint_pixel function with your pixel function. Making a star field is very simple. You idea about using a texture image is probably the best. You will only have lags at runtime if you are loading the image at runtime during your render loop. This is why you load the image before entering the render loop. Besides, I think your computer can load that image pretty fast so you wouldn’t notice any thing unless the image was something like 6000x6000x64
Take back the internet with the most awsome browser around, FireFox
SewageWorker
SewageWorker
quote:
Original post by hplus0603
Your images don't need to be huge, because your screen resolution isn't huge. 6 1024x1024 images in a cube would be plenty. Just draw these as your "sky box" (always centered on camera) and you have instant space.

Now, if you want the stars to get closer when you move towards them, then a single texture isn't going to cut it; you need to render each star individually. Typically, you do that with points, until they get close enough to need sprites, and then you use sprites until you get close enough to use balls with transparent flare effects around them.



how come?

If my res is 1024x768 that means the section of the texture that I'm seeing has to be the same resolution. So I have to see a section that is 1024x768. And that is only a portion of the sphere, say 1/24. So that means the final texture has to be something like 1024x768x24 (or something). not very nice.

And besides, I don't think the stars need to get bigger when you get closer, since the sun and stuff are actually objects.

So I think option 2 is better. Nebulas and stuff can be added onto the starfeild.


[edited by - SewageWorker on September 28, 2003 7:53:22 AM]
J_Vitel
J_Vitel
I agree with the particle system idea, they''re not difficult to implement an can be reused in later game-effects such as explotions and you can implement each single particle using the billboard effect so in that way you can draw 2d stars and make them look as 3d objects, Billboards rock''s for lightning things
My site Jvitel.com
Cornutopia
Cornutopia
The fastest solution I can think of is a transformed poly so you need one screens worth of texture. Shift/rotate it as the view moves and no one will notice it''s transformed. I''m sure it would be faster than a cube or particles, and you can add multple layers for parallax. I''m using that system now.

Mark
Cornutopia Games
http://www.cornutopia.net
Sound Effects For Game Developers
http://www.indiesfx.co.uk
Vulcan
Vulcan
for best visual quality, do both. Space is not just stars, you need things like nebula and the like. The way to go is to have your skybox be the nebula/sky dust/what have you, and then to place random stars (most likely dots) rendered on top of them. EVE online does this, and looks very nice -

regards
-Eric
raven_soul
raven_soul
quote:
Original post by sakky
‘ 2D Star Field at Runtime
Dim StrX( 0 to 320 ) as Integer
Dim StrY( 0 to 240 ) as Integer
Dim StrS( 0 to 320 ) as Integer

‘ Initialization loop
For I = 0 to 320
StrX( I ) = random_number_between_0_320
StrY( I ) = random_number_between_0_240
StrS( I ) = random_number_between_0_320
Next


‘ Main render loop
For I = 0 to 320
paint_pixel( StrX( I ), StrY( I ), black_color )

If StrS( I ) = 0 Then StrX( I ) = StrX( I ) + 1
If StrS( I ) = 1 Then StrX( I ) = StrX( I ) + 2
If StrS( I ) = 2 Then StrX( I ) = StrX( I ) + 3

If StrS( I ) = 0 Then paint_pixel( StrX( I ), StrY( I ), dark_gray )
If StrS( I ) = 0 Then paint_pixel( StrX( I ), StrY( I ), gray )
If StrS( I ) = 0 Then paint_pixel( StrX( I ), StrY( I ), white )

If StrX( I ) > 320 Then
StrX( I ) = -1
StrY( I ) = random_number_between_0_240
StrS( I ) = random_number_between_0_2
End If
Next



I don't know if you realize this, but that is V(isual) B(asic) code. And he didn't say weither he was using VB or not.

[edited by - raven_soul on September 30, 2003 3:05:54 PM]
rick_appleton
rick_appleton
vulcan: the screenshots of EVE do indeed look fantastic, but wouldn't the skybox with the nebulae take a too large amount of memorey with the kind of detail you can see in those shots?

as calculated before: take 1024 as the width of your screen-> 6 textures of 1024x1024 each, 24bit = 6*1024*1024*3 = 18 MB = ouch

[edited by - rick_appleton on September 30, 2003 9:45:30 PM]
SewageWorker
SewageWorker
quote:
Original post by rick_appleton
vulcan: the screenshots of EVE do indeed look fantastic, but wouldn't the skybox with the nebulae take a too large amount of memorey with the kind of detail you can see in those shots?

as calculated before: take 1024 as the width of your screen-> 6 textures of 1024x1024 each, 24bit = 6*1024*1024*3 = 18 MB = ouch

[edited by - rick_appleton on September 30, 2003 9:45:30 PM]


Yeah thats what I'm doing ... and I honestly don't know any other way. That parallax thing I didn't understand either. Currently I have 6 1024x1024 textures which I add stars to at the startup and then randomly copy the nebulas accross. Looks really nice but the memory requirement is rediculous. Any ideas? btw I'm using C++ w/ DX8.

EDIT: Eh... spelling

[edited by - SewageWorker on October 1, 2003 7:44:23 AM]
sakky
sakky
You guys know that you can use smaller images then 1024x1024, right? You don’t need a huge picture to get good detailed graphics. Most 3D graphics cards only allow about half that side. Just use 256x256 or 512x512 textures with linear filter. You could still use a particle system, but you would have to turn off depth testing.
Take back the internet with the most awsome browser around, FireFox
Vulcan
Vulcan
sure, 18MB total in textures is a sacrifice, but when you load up your skybox and draw a 256x256 texture on there instead you may reconsider when you see what it looks like...

-Eric
zekis
zekis
Hi, this is my first post.
anyway if you convert your stars(1024,1024) to greyscale then they are only 1mb each and if they are jpegs then there half that on the disk. All coloured stars, asteroid fields and nebula should be textured plains or billboards.

[edited by - zekis on January 23, 2004 2:22:50 AM]
Creating a level is like directing a movie.
Trienco
Trienco
quote:
Original post by zekis
Hi, this is my first post.
anyway if you convert your stars(1024,1024) to greyscale then they are only 1mb each and if they are jpegs then there half that on the disk. All coloured stars, asteroid fields and nebula should be textured plains or billboards.


but only on the disk and i dont think he's worried about that. also, i think the look of jpegs as textures are a good reason why they are frowned upon (especially with regular texture compression making them small on disk AND in memory and probably looking a lot better)

but i agree on using billboards for quite some stuff, especially if he doesnt care about the whole space being filled with nebulas. using points to fill the gaps shouldnt hurt performance too much (much less than a big texture with only a few bright pixels). also, adding a few points around the ship that wont move with it is somewhat "important" to give the player a sense of movement (just randomly create them in front of him and replace those that get behind with new ones.. simple particle system).



[edited by - Trienco on January 23, 2004 3:11:11 AM]
f@dzhttp://festini.device-zero.de

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.