Creating 3D Moveable Starfield in XNA

Started by
16 comments, last by IcedCrow 10 years, 9 months ago

G'day everyone. I'm working a space simulator project and one of the challenges I am facing is a proper starfield. I've done some research but have not come up with any conclusive answer so thought I'd post a new topic.

Some information on what I've gleaned and some options that I'm considering:

* this is my first 3d title so I am still learning how to work with the environment. I am used to 2d development.

* the game is inspired by the old xwing series. The camera will either be situated in the cockpit of a ship or be situated behind the ship as it travels.

* the camera will therefore have full rotation, yaw, and pitch functionality as the object moves through 3d space

* the starfield that it sits over must appear to move to give the illusion of movement. therefore if i pitch up, the starfield should adjust accordingly and if I pitch back down I'd expect the starfield to adjust back to where it started from.

* the starfield will have some other objects besides stars such as nebulae and clouds

Some ideas that I am considering that I'm not 100% sold on yet

* a skybox with starfield texture. - pros: easy to implement. cons: edging

* a skysphere with a starfield texture - pros: no edging issues. cons: more resources

* a particle system for stars - pros: fairly easy to create in code cons: moving it around for me, and the appearance is kind of dated but that could be just my limited shader experience

Ideas and input appreciated on the best way to implement this. I'd love something like from EVE but I am not sure how they accomplish their backdrops. They appear to me to be a skybox of super detailed textures with star particles over them.

For more on my wargaming title check out my dev blog at http://baelsoubliette.wordpress.com/
Advertisement

Try focusing on one thing!

Remember EVE is a huge game, and a lot of developers are working on it!

  • About the particle systems, for the stars I would recommend you using instancing.
  • The skybox, edging? Just make it more detailed, but on the skybox you dont need light calculations, so you shoudn't see the edges wink.png
  • Skysphere, I personally use this one, and I don't think you need to worry on the resources on this one.
  • The Camera, What i do is that the camera is following the spaceship (I made a demo once)
  • With the nebula and clouds, I would recommend you using camera facing quads with softness, more than one, so they appear volumetrical.
  • With the sense of movement, what I did was to have stars dynamically generated with a lifetime around my spaceship, and then regenerate them on the way, and then when you move, the stars go backwards, creating this sense of movement!

BUT REMEMBER! This is only my personal opinion! blink.png

GOOD LUCK! smile.png

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Could you explain "instancing"? I'm not familiar with that term.

When you say you use a skysphere, do you use a texture of a starfield over it?

As to your movement, are you saying that when you perform a pitch or a yaw that you through code generate the particle stars and then when you go back you kill the ones you just generated and generate new ones as they get into your field of vision?

That woudl work and would indeed create the illusion of movement. The only negative would be stars not in the same position anymore but that might be nitpicking on my part :D

For more on my wargaming title check out my dev blog at http://baelsoubliette.wordpress.com/

Instancing in a nutshell is a very efficient way of rendering multiple meshes of the same mesh: http://www.rastertek.com/dx11tut37.html

2nd : Yes

3rd : If I understood you correctly, then yes huh.png

4th: I understand you, but actually that's how many games do it :)

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

skybox / skysphere

particle system stars / rocks / debris around the ship

3d billboards of distant nebulas, galaxies, etc.

lens flare and such are popular, but unrealistic, unless the view is supposed to be through a remote camera.

this is the standard method.

in SIMTrek, my first hit game, the particle system stars were 3d lines that changed length from points at sublight speed to stretched out lines at warp speeds (20-50 particles).

Wing Commander used a 3d rock billboard particle system around the ship ( 6-8 particles ). pre-rendered sprites. looked great (for the time, now they'd probably be instanced meshes).

When i made Gamma Wing (a wing commander type game), I found that nebula / galaxy billboards in the 6 cardinal directions aided greatly in providing visual orientation cues to the player.

and nothing beats a great texture.

getting skybox textures with no repetition can be difficult. the black background of them tends to makes seams a non-issue. Just watch out for textures with hazy clouds of stars near the edges of the texture. these will require seamless texture type work to blend well.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

for your star field around the ship, you randomly generate some particles (say 100) in a volume around the camera (say -100, -100, -100 to 100, 100, 100). then each turn, you move each particle in the _opposite_ direction of the ship. if it exits the volume, you regenerate a new random position for it on the "leading edge" of the volume (the face the player is flying towards). then you just draw the star field around the camera, sort of like drawing rain around the camera. these will turn and move as though the ship were flying though the particle cloud. remember: all motion is relative. stationary stars and moving camera, or stationary camera and moving stars, same diff.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

Appreciate the replies guys. Gives me a bit to think about. biggrin.png

The instancing tutorial given above is informative but i noted they were discussing DX11. Does this translate over to DX 9 at all?

For more on my wargaming title check out my dev blog at http://baelsoubliette.wordpress.com/

Yes there is instancing in dx9
Always use msdn for microsoft related technologies. They have really good documentation and strong community

http://msdn.microsoft.com/en-us/library/windows/desktop/bb173349(v=vs.85).aspx

What would be the difference between just using straight up pixel particles for stars as opposed to instancing? Or would instancing be the pixel particles? (the examples I've seen using particles just create a particle engine and typically will just toss out white particles as stars without using any instancing)

For more on my wargaming title check out my dev blog at http://baelsoubliette.wordpress.com/

If you intend on drawing an explorable star field, especially in XNA, mesh instancing is definitely the way to go.

Mesh Instancing

Mesh instancing works by storing a mesh on the graphics card only once (If you think about it, why bother having many copies of a mesh you will be reusing, it's inefficient, memory wasteful, and could actually act as a bottleneck when drawing many copies). Coupled with something called an instance buffer (bit like an IndexBuffer that stores an array of structs that describe position, scale, and rotation for each copy),

You simply call GraphicsDevice.DrawInstancedPrimitives once each draw cycle and the graphics card takes care of drawing all of the copies.

The benefits are obvious, you can draw thousands of copies of the same mesh and yet only store 1 copy of the mesh on the graphics card. As the instance buffer can be dynamic (only if you need), this enables the ability to animate instances (copies) as seen in particle system examples. Also offloading this sort of task to the graphics card is particularly useful in XNA as it helps get round the overhead .Net throws at you.

Cameras

In regards to cameras, it's important you get a good understanding of how matrices work in XNA. The view matrix for example represents how the user views the world, which means you only have to alter the view matrix to move, twist, turn etc.. through your star field. As you are using XNA, Riemer has an excellent tutorial on this sort of camera that I think would be of benefit, even though the site is old, I thoroughly recommend you give it a go:

> http://www.riemers.net/eng/Tutorials/XNA/Csharp/series2.php

Further Reading

Funnily enough Microsoft have provided a number of excellent code examples that show you how to perform instancing in XNA, so here's a few links to ones I think are most relevant to your goals:

> (Mesh Instancing Example) http://xbox.create.msdn.com/en-US/education/catalog/sample/mesh_instancing

> (Particle System Example) http://xbox.create.msdn.com/en-US/education/catalog/sample/particles_pipeline

Also to answer your question about 'straight up pixel particles', yes I can imagine a way doing something like that could be possible with shaders, but it's a very complicated way of accomplishing what you get easily with mesh instancing, I recommend you give what works a go first to build your confidence in this field.

Good luck, and keep us in the loop with how you get on :)

Aimee

We are now on Tumblr, so please come and check out our site!

http://xpod-games.com

This topic is closed to new replies.

Advertisement