Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


Creating 3D Moveable Starfield in XNA


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
17 replies to this topic

#1 IcedCrow   Members   -  Reputation: 264

Like
0Likes
Like

Posted 11 July 2013 - 08:04 AM

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/

Sponsor:

#2 Migi0027   Crossbones+   -  Reputation: 1914

Like
0Likes
Like

Posted 11 July 2013 - 10:04 AM

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


Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to kill everyone you meet, ohh, AND STEAL ALL ZE TRIANGLES FROM ZHEM!

#3 IcedCrow   Members   -  Reputation: 264

Like
0Likes
Like

Posted 11 July 2013 - 10:31 AM

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/

#4 Migi0027   Crossbones+   -  Reputation: 1914

Like
0Likes
Like

Posted 11 July 2013 - 10:40 AM

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 :)


Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to kill everyone you meet, ohh, AND STEAL ALL ZE TRIANGLES FROM ZHEM!

#5 Norman Barrows   Crossbones+   -  Reputation: 2204

Like
0Likes
Like

Posted 11 July 2013 - 10:45 AM

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 1988"

 

rocklandsoftware.net

 


#6 Norman Barrows   Crossbones+   -  Reputation: 2204

Like
0Likes
Like

Posted 11 July 2013 - 10:55 AM

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 1988"

 

rocklandsoftware.net

 


#7 IcedCrow   Members   -  Reputation: 264

Like
0Likes
Like

Posted 11 July 2013 - 11:26 AM

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?


Edited by IcedCrow, 11 July 2013 - 11:28 AM.

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

#8 imoogiBG   Members   -  Reputation: 1217

Like
0Likes
Like

Posted 11 July 2013 - 04:00 PM

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


Edited by imoogiBG, 11 July 2013 - 04:00 PM.


#9 IcedCrow   Members   -  Reputation: 264

Like
0Likes
Like

Posted 11 July 2013 - 07:23 PM

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/

#10 Tarika   Members   -  Reputation: 481

Like
0Likes
Like

Posted 11 July 2013 - 09:19 PM

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


#11 IcedCrow   Members   -  Reputation: 264

Like
0Likes
Like

Posted 11 July 2013 - 09:23 PM

Appreciate the links.  I have used riemer's site a bit.  He has some good starting points though his code is outdated and doesn't compile so you have to fix it a little as it was designed to run in older versions of xna.  

 

His xwing example is one of the camera angles i'm going for (the other being the cockpit view which is basically a first person camera)

 

A lot to read a lot to take in but that's the fun of it!

 

I will look into mesh instancing first.  My prototype right now just uses a skybox with a starfield texture painted over it but as the game is more sandbox, I'd like to actually have stars that are stars on the screen as opposed to just particles i randomly throw out there.


Edited by IcedCrow, 11 July 2013 - 09:27 PM.

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

#12 BrentChua   Crossbones+   -  Reputation: 1066

Like
0Likes
Like

Posted 12 July 2013 - 01:11 AM

This is really just a side comment but a few things comes into mind.

 

* If the stars surrounding appears to be moving like a passing-by effect, that would mean your ship is moving really2x fast! Will your ship be moving in light-speed or warp speed all the time? 

 

* If you're moving towards a start, what happens to that star when you get too close to it? Will it still be just a dot in your screen even though you're just a few meters away from that star?



#13 BrentChua   Crossbones+   -  Reputation: 1066

Like
0Likes
Like

Posted 12 July 2013 - 01:18 AM

What if you'll have a dynamic skybox. For each frame, you render your skybox cubemap in a separate scene that just contains the star field. Let's use a 2D star field for example. You can separate the starfield in 2 sections. The front and back which can only move horizontally and the left and right side that can only move vertically. That way i think you'll solve your problem having a dynamic starfield moving while you travel and also preventing the second problem of "tiny" stars staring in front of your face.



#14 IcedCrow   Members   -  Reputation: 264

Like
0Likes
Like

Posted 12 July 2013 - 06:46 AM

The stars should not appear to get closer to the ship at all.  Most of the game will take place in "realspace" which will have the ship moving at roughly 500 m/s.  The sun in the system will be the origin and it will be possible to fly into the sun, but at 500 m/s that would take an awfully long time to get to the sun.  (It may just be that I render the sun as a static object in the game depending on location in the system)

 

Based on that, a textured starfield I think would be pretty workable and realistic since the stars should just move right left and up and down, not coming at the player.

 

During translation to the warp the cock pit closes down and the warp is done without visuals (i'm probably going to add some hellish glows ala warhammer 40k but that's still pending)

 

I like the idea of textured starfield map simply because it requires the least amount of code... you paste it to the skybox.  

 

Possible issues with this:  i want each system to appear different, and not just arbitrarily different.  

 

I like how EVE does it where each point of light is actually a system.  I think that's more or less rendering a star on the backdrop in the same absolute location to the world though which I also think is very doable.


Edited by IcedCrow, 12 July 2013 - 06:47 AM.

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

#15 Norman Barrows   Crossbones+   -  Reputation: 2204

Like
0Likes
Like

Posted 12 July 2013 - 04:21 PM

if the vehicles are basically sub-light speed only, use a skybox/skysphere, instanced meshes for rock/debris flying by (gives good sense of speed and motion), and simply draw nearby systems (textured spheres, or 3d billboards at low LOD) . perhaps change up the skybox texture depending on the general area of space they're in, if the "game world" is that big. SIMTrek drew nearby stars, planets, moons, star bases, etc. the "world map" had 10,000 star systems in it.

 

As i recall, in wing commander, they usually had at most one big planet nearby, which would make sense for that type of vehicle simulator. Space is BIG! <g>.


Norm Barrows

Rockland Software Productions

"Building PC games since 1988"

 

rocklandsoftware.net

 


#16 IcedCrow   Members   -  Reputation: 264

Like
0Likes
Like

Posted 12 July 2013 - 04:27 PM

Very big :D

 

Definitely pursuing the skybox right now.  Researching how to work with instanced meshes.  I have used VertexBuffers before and it seems that those may be similar... still haven't made the connection yet though.

 

Was going to billboard nebulae and gas clouds and then particle the systems they can travel to (so that they can have a label attached to them by the nav HUD)


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

#17 Norman Barrows   Crossbones+   -  Reputation: 2204

Like
0Likes
Like

Posted 13 July 2013 - 03:42 PM


Researching how to work with instanced meshes.  I have used VertexBuffers before and it seems that those may be similar... still haven't made the connection yet though.
 

 

basically you'll have a VB,and possibly an IB to go with it, then you have an "instance buffer", with a whole bunch of world transform matrices in it. the shader applies the transform to the original mesh (the VB) then draws it. then applies the next transform in the instance buffer to the original mesh and draws another copy. and so on for all your instances.

 


Was going to billboard nebulae and gas clouds and then particle the systems they can travel to (so that they can have a label attached to them by the nav HUD)

 

if the "world"  (galaxy?) is large, you'll want a "world map" with star systems etc, and an "active targets list" that you page star systems into and out of as they come into and go out of range. then just draw your active targets. planets and such aren't really particle systems, they're more like world objects, like a big ship or starport. 

 

now for the REAL challenge:

 

how on earth are you going to draw what it looks like when they get shot down and fly through the atmosphere and crash land on an alien planet? if you draw a planet, they're going to want to land on it. you know how player's are, they want to be able to do everything. <g>.

 

drawing atmospheric reentry is one of the big challenges in space flight sims.

 

And yes, i'm just kidding. Almost no space sim does this due to the difficulty.


Norm Barrows

Rockland Software Productions

"Building PC games since 1988"

 

rocklandsoftware.net

 


#18 IcedCrow   Members   -  Reputation: 264

Like
0Likes
Like

Posted 14 July 2013 - 08:30 AM

That my friend is on my list of things to do lol.  There is a game I found on STEAM called Evochron Mercenary which lets you do just that, though I am not a fan of how the overall look is landing on the planet.

 

For right now you will not be able to land on the planet.  But it is something I want (atmospheric dogfights) and the ability to land.  


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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS