Space Simulator Rewrite via Unity

I’ve switched to Unity 3D, both a game engine and game development environment for my humble Space Simulator hobby project.  Thus far I’m most impressed with the speed that Unity allows me to realise ideas and focus on what is more important – what the game is about. Far more sensible than spending time in other 3D APIs trying to implement a mini-map which may break in the next release of the API.

Unity’s asset and scene browsers allow you to organise your project logically and visually.  Setting up a scene is an absolute joy as opposed to attempting the same in code.   Files that have been created externally in say Blender, 3ds Max or Photoshop for example do not require subsequent import steps, Unity immediately displays changes.

Unity Pro also comes with some nice features such as:

  • Pro Image Effects including shadows; screen-space ambient occlusion (SSAO); bloom
  • Occlusion culling
  • Extended light-mapping (radiosity)
  • Deferred rendering with unlimited lights
  • HDR
  • A pretty dark-grey theme

I did feel guilty about the idea of using a tool such as this but that was quickly laid to rest.  For instance, we use nHibernate, StructureMap, Entity Framework, ASP.NET MVC and IDE’s such as Visual Studio and Xcode so the concept is not new.

Why re-invent the wheel?

You Mean I’ve Been on the Dark Side All Along?

This is how I felt earlier this week after my initial forays into OpenGL, an open standard graphics library for multiple platforms.  From the books I was reading, I had come to realise that XNA is perhaps an immature API from both age and sensibility viewpoints, particularly where one is concerned with cross-platform and backwards compatibility and DirectX was just too hard.  I was already aware of the last point from personal experience.

I quite like how OpenGL has its extension system to expand the API without breaking other peoples code.  XNA and DirectX could learn a lesson here.

The XNA team have had a history of breaking backwards compatibility for “reasons” of motivation.  There were major breaking changes between XNA 3 and XNA 4.  The future of XNA to me is uncertain.  Microsoft’s next OS Windows 8 has XNA no where to be seen. XNA can be found on Windows Phone 7 devices but they are quite rare.  There is XNA on XBOX for end-users, but it has fewer features than what a proper XBOX game has access to hardware-wise. XNA was not the first Microsoft managed DirectX wrapper.  Before XNA there was MDX and sadly it went the way of the Dodo bird.

Just a few lines is all it takes to display a 3D window

OpenGL is reportedly easy to learn and thus far I agree with what I have been told.  Just a few lines is all it takes to display a 3D window.  It’s also good to know that no bloatware, no mammoth class libraries, no over-the-top OO-style programming – just pure, nice and clean c-style methods.   Contrast this with DirectX – now I would like to think I know something when it comes to COM, but trying to learn DirectX is quite challenging.   DirectX did come out later with c++ helper classes but they were perhaps rather limited and let’s face it – too late!

XNA is a lot easier than DirectX but its way harder than OpenGL, however XNA is slightly bloaty compared to OpenGL.  Plus unlike XNA, OpenGL doesn’t have ridiculous legal restrictions on what you can do or how you distribute your application.   Want to give your buddy your game to try out?  He may need Visual Studio 2010; XNA Game Studio installed; and know how to compile your program.   Not fun.

…we still have point sprites on OpenGL using the same modern-day video card!

The worst bit about learning XNA, was how unprofessional some of the key representatives and tutors were on certain forums and blogs.  No, these were not fan forums.  Forum manners were atrocious; people with perceived ulterior motives; and some cases of propaganda.  One was to do with the elimination of point sprites from the API, another over not to use the FBX file format and the bizarre recommendation for people not to use sky domes.  Funny, we still have point sprites on Windows via OpenGL using the same modern-day video card!   Even iPads can use point sprites via OpenGL ES.  Sure, point sprites may be old hat but we were lead to believe that modern hardware doesn’t support it when the truth is is that latter DirectX doesn’t.

The point is, if my legacy app wants to use some ancient deprecated feature, the API should damn well let it have it, even if it means it runs like a pig.  This is why OpenGL is so much better.  OpenGL is kinder to you – it gives you the opportunity to run your legacy app whilst allowing you to gradually upgrade to newer discipline.

You were told to do things a certain way in XNA either with no explanation, or if one was given, was perhaps a half-truth in hind-sight.  I was reminded of how I felt when I first heard of OpenGL back in the days of Windows NT 4 and basically dismissed OpenGL most likely due to at the time being influenced by others in the know.  Back then, I suspect I didn’t hear both sides of the story, like the point spites half-truth.

Now I don’t profess to be an expert in XNA, let alone DirectX, but my experiences in both of these has made me come to the realisation that I have more important things to worry about – what my application is about and how the tools or APIs can help me.

Hello OpenGL, so nice to be in the light with you!

Golly…Macs Really Do “Just Work”!

I was recently lucky enough to grab myself an iMac; in that time it has solved more problems than the time I have spent trying to solve a single problem on Windows.

Computer Specs

Memory Windows= iMac =4GB
CPU Windows=Intel Core 2 Extreme Quad @ 3GHz,  iMac=2.8GHz Quad-Core Intel Core i5
Video Windows=dual nVidia 8800 GTX,   iMac=ATI Radeon HD 5670


Before

Here is a list of my prior issues:

  • iTunes on PC and generation 1 Apple TV would “forget” their network connection
    • meaning my Apple TV could no longer sync/stream TV shows and movies from my PC
    • typically you buy on the Apple TV and after watching it is “archived” on your PC to make room for other purchases
    • I had lost a few purchases because of this.  Apple does not allow you to download to Apple TV again
  • Could not connect to a Canon MX850 printer via the network if it was connected to one PC via USB
    • basically allows you to share the printer over a single USB cable instead of a network cable
    • USB allows you to do certain things network cable cant
  • Lacie 4big Quadra 4TB RAID “big blue button” not recognized
    • allows for quick backup
    • Windows Backup is inefficient, slow and poorly designed
  • Access to Apple’s MobileMe email via Microsoft Outlook/Windows Live Essentials IMAP is incredibly slow – 5 seconds to delete a message
  • Opening the majority of any document takes considerable time on Windows
    • PDF
    • videos
    • Word/Excel documents
  • MSN Messenger takes considerable time to load; consumes excessive computer resources
  • Games such as the recent Civilization V consume excessive resources; takes considerable time to load considering nature of application – “its no Crysis!”
  • Windows Phone developer registration is more complex than applying for a home mortgage.  Took approximately 7 days to complete including various to and throw e-mails to Microsoft
  • Visual Studio has historically shown that with each new version requires a level of magnitude more computer memory and CPU resources.   VS is very expensive to buy for the Pro version. Express as a tool for serious development is questionable

After

  • Apple TV and iTunes on iMac just work; do not forget each other
  • Canon MX850 was automatically detected over wi-fi when plugged into Airport Extreme Base Station USB socket
  • Lacie 4big Quadra 4TB RAID was automatically detected and iMac kindly asked if I wished to use it for TimeMachine
    • Pressing big blue button on Lacie launched the brilliant TimeMachine app
    • TimeMachine is fast, intuitive, reliable
  • Apple’s iMail automatically configured e-mail server settings just by me typing in my @me.com address
    • iMail is fast
    • Like the central inbox
  • iMacs have a Preview application that very quickly opens a document for reading rather than loading bloatware Acrobat, Microsoft Word, Excel or similar
  • MS Messenger for iMac (via Office Mac) is much like pre-Windows Live Essentials meaning it doesn’t have the annoying ads but more importantly, uses less computer resources like memory and CPU in wlcomm.exe
  • Civilization V for iMac loads considerably quicker and exits to mac desktop much faster than Windows
  • Apple’s Mac Developer MacOS/iOS registration completed in 12 hours
  • Apple’s Xcode IDE is only $5.00 and uses minimal CPU and memory
  • Though Apple may make use of seemingly vertical standards such as Bonjour, historically it can be shown that Apple is more likely to adopt more popular standards with more realized use cases than say MS.  Calendering is a good example.

In summary, in only a short time does one really appreciate the high quality of the iMac, but also comes to the realization that pretty much everything PC is by way of poorly designed, badly integrating bloatware produced by capitalist-corporate-hugging software houses.   Take Microsoft Office 2010 is not only bloated but is also unintuitive and bloated; similarly for VS2010 as mentioned.

Don’t Move Your Viewpoint–Move the Universe Instead

In my space simulator project I wanted to model the Solar System but sadly this led to a rather annoying limitation because of restrictions of single-precision floating point. Flying about near “Earth” and the moon seemed OK but flying to Jupiter proved another story. If I tried to place say Jupiter at a scaled-distance from my in-game “Sun”, flying my ship to the Jupiter region caused all sorts of floating point truncations which were very much visible in ship rotations – it all became quite “jumpy”.

After a bit of reading by posts from other devs in my predicament, it seemed that the best approach was not to move the in-game first-person camera based on ship motion but rather to always keep the camera at (0,0,0) and to move everything else instead! In other words – you don’t move, the Universe does. Reminds me of a Greg Bear novel. Winking smile

Also, it makes no sense at this stage to store everything in absolute coordinates when you are dealing with the very large.  I think that storing everything relative to it’s immediate stellar parent makes more sense.  e.g. planets to stars, moons to planets and so-on.  By using octrees I can partition objects relative to the node in which they live thus cutting down large values.  e.g. at least one of the Jupiter nodes should contain the planet and all its moons while other nodes just take into account the planet.

So with this in mind I:

  1. placed the scene origin (0,0,0)
  2. placed the sun at the origin
  3. distributed the planets and moons scaled down and relative to each octree node
  4. placed the camera at some nice location
  5. translate octree nodes based on the camera’s logical position (move the planets not the camera)
  6. when rendering, just draw those models in octree nodes that intersect with the view frustrum
  7. eventually this can lead to dynamic scene content streaming based on the contents of an octree node

Anyway here’s a video.  It’s a test video where the maximum viewable distance is shorter than normal hence the planets vanishing only to be replaced with “crosses” so as to indicate “not viewable”.  If an octree node is too far away it turns blue.

XNA Planet Custom Shader

Well I’ve been working on making my planet shaders to be something a bit more colourful.

Day and Night

First of all I wanted to map two diffuse textures that are alpha blended depending on whether the planet’s side is in the Sun’s shadow or not.  When it is you’ll see the city lights twinkle on.

Atmosphere

Next I wanted to do some sort of atmospheric effect.  This was tricky and I’m still not absolutely happy with it – I think I need to read more on subsurface scattering.  Geometry-wise, it’s just a slightly larger sphere.  To shade it the atmospheric shell only renders when the surface normal is nearly perpendicular to the eye – in other words it only shades around the edges of the planet.  The dot product is raised to the 4th power or so to be used during the calculation for the alpha value.  The atmosphere is also emissive so as to illuminate when in shadow.

2010-12-18 vanquish planet atmosphere 1

2010-12-18 vanquish planet atmosphere 2

2010-12-18 vanquish planet atmosphere 3

2010-12-18 15-35 vanquish planet atmosphere

XNA Cruiser? One “Bump” or Two?

I just love pipelines and Lumonix Shader FX makes no exception.  Yesterday I started off with a rather humble shader but today let’s beef it up a bit with a bump map to give it more of a 3-D look.  Here is the shader as seen in 3DS Max and Shader FX:

image

…and here it is in my space simulator:

image

That’s looking a bit better, though I must admit it needs a bit of colour and perhaps some glass effects – something for a future project. We noobies have to start somewhere.

Be Gone Wireframe – Hello Space Cruiser!

Vanquish 2010-11-27 15-44-45-87Today I spent time on my scene mechanics and imported a new space ship model to replace the test ring place-holder that I was using for the autonomous steering behaviour programming.  It served it’s purpose by indicating the steering, velocity and normal vectors but I know those around me were wanting to see a spiffy model. Anyway I found a rather nice free 3DS model by Mace24de (thanks buddy) on TurboSquid. Loading this into Max it was just a case of giving it a good paint job via Lumonix Shader FX via an interactive pipeline building process. Gotta love Shader FX. 

image

As you recall in a previous post, Shader FX is a must have for the generation of HLSL GPU shaders in the form of .FX files for use in the likes of XNA.  I’ll just do something fairly simple for now though – a diffuse texture map with a touch of glossiness should be a good start.  Later I’ll plonk in a normal map to make it more interesting.  Here’s a shot of Shader FX in 3DS Max.

image

…now let’s apply that to our model via Tools/Apply to Selection in Shader FX:

image

That’s more like it. Now let’s export the shader for XNA. In Shader FX choose File/Export FX…

image

Select XNA from the appearing dialog.  Make sure you pick Y-Up too – that is a requirement for XNA.

image

Remember that the XNA shader must be a different filename to the one being used in 3DSMax.  I like to merely give the XNA files a “XNA” suffix.  A no brainer Winking smile

image

…export your model. Make sure just your model is selected, no lights/cameras/etc. please unless your pipeline can handle that. Choose File/Export/Export Selected in 3DSMax:

image

Export as a FBX using Autodesk’s FBX export tool (its a free download from their site). My settings is pretty much the defaults except I’ve deselected cameras, animations etc. for now as I can’t handle them anyway). We don’t want cameras or lights because we’ll be doing that in game.

image

Eventually this gets into my game using my custom content importer pipeline for FBX that reattaches textures, FX etc. to achieve the following result. I only have to include the .FBX file in my Visual Studio project – there is no need to directly specify the FX, textures or other files because my custom pipeline finds them by reading the info in the original FBX file.  This is handy because I can leave shared art on a different drive and use it in other projects.  Yippee!

Here we are just to the side:

Vanquish 2010-11-27 15-31-53-11

 

Coming in for the kill!

Vanquish 2010-11-27 15-44-45-87

 

From above:

Vanquish 2010-11-27 15-47-24-01

Working on the HUD for My Space Simulator

Much of the work for my space simulator has been happening behind-the-scenes so I thought it would be a good idea to add a few spiffy elements to jazz up the user interface and the scenery.  One thing I noticed was that my planet and moons were being illuminated by an invisible light source!  So I have whacked in an actual Sun model and moved my light source to be at the same location – obvious I know.  I found a rather nice earth texture, Bump map and specular map.

To top it off, I thought I’d put in a red spinning targeting indicator something based on one of my favourite scenes in Star Trek II – the Wrath of Khan.  Though mine is a bit sound-challenged.

Anyway, check out the new video at my YouTube channel:

Targeting demo

 

I think I might find a nice 3D model  for the enemy ship because rings are all well and good but are not particularly thrilling. Winking smile

Teaser Videos of My Space Simulator

I thought I’d share some sneak videos of my space simulator in progress, the bulk of the work for these were done months ago before I hurt my hands from being fully from doing too much of computer, Xbox, and certain touch devices.

Anyway, here is the video (hi-def version available to!):

demo 1

 

Some point to be aware of:

1. The ship is obviously moving way too fast for now.
2. "Jupiter" is actually the Earth with a Jupiter texture from JPL (I was eager to see what Jupiter looked like in the simulator) Winking smile

3. Scale isn’t quite right.  XNA users single precision floating point which is insufficient for our needs in terms of the solar system, let alone the stars that will be using in the simulator. I’m hoping to use double precision just for the are areas that require it.

Now please bear with me because you must remember that I am a bit of a game programming caveman that has been thrust into contemporary technologies and practices; so needless to say that I am a bit overwhelmed with not only all of the APIs that one must consider, but also the amount of responsibility the game programmer has nowadays.  Things were so much easier back in the 80s when we thought it was pretty cool to have a game with 16 colours at a massive 320 x 200 screen resolution.  🙂 I thought I was pretty schmick at doing artwork back then, but today I realise that the 4 bits per pixel and narrow chromatic spectrum of microcomputers of old merely obfuscated my feeble artistic talents. 😉

This is why I’m doing a game/simulator hobby in 3-D because the 3-D engine does most of the "artwork" and "colouring in" for me.  The fact that it is a space simulator makes my job is easier still because there are multitudes of free textures from the likes of NASA/JPL available for free to me to use in my projects.  There are also plenty of free 3-D models for me to use, backspace (some even with textures) so all that is left is really are shaders and even then there are plenty of those to be found.  To be honest, I know my limitations and have no illusions of creating something that looks as spiffy as Crysis, FSX, Oblivion or Fallout 3.

Last weekend I got rid of the visually-challenged star field skybox and replaced it with data based on the Hipparcos European space satellite.  I’m only using a small subset of around 10,000 stars and rendering them as XNA point sprites, scaling them depending on their magnitude and tinting them based on their colour index. At the moment I’m drawing them on a normalised sphere at a constant radius from the camera to get around the depth buffer problems for now but eventually I’ll have them as double precision floating point plotted in Cartesian coordinates rather than the Equatorial Coordinate System.  This will allow the pilot to go on an exciting journey to the star of his or her choice.

Later, I think it will be rather schmick to tie in the latest discoveries from the HD exoplanet database so not only will you be able to go to the star, but also to get a rough impression of where the planet is in relation to the star.  Of course, I most likely will have to use artistic licence for the visual appearance of the exoplanet.

XNAV, Don’t Leave Earth Without It

imageWhilst tinkering with my space simulator project, I started to think:

What sort of electronic navigation system would you use in space?  Would you have some inertial-based system as in the KA-50 helicopter?  Would you triangulate your position by tracking known stars?  Or maybe a really long piece of string and a protractor?

I didn’t have the foggiest idea. So Googling around I found many references to designs that referred to something called X-ray Navigation or XNAV. [1] [2]

image

Basically XNAV uses one or more x-ray emitting pulsars depending on your navigation needs.  Pulsars are basically stars that have gone BOOM and reduced themselves to a tiny neutron star which just happens to be spinning. An x-ray beam is emitted (Figure 2-6 [1]) in-line with the magnetic poles. Astronomers have found that pulsars are quite abundant in the measurable universe and that the spin of the pulsar is unique.  This uniqueness of the pulsar spin and resulting “flash” or “pulse” as the beam sweeps past you allows you to determine the source pulsar by measuring pulse intervals.

By using 3 pulsars, you can accurately triangulate your 3D position in space in the same way your car GPS can – albeit the latter in 2D only.

Just one pulsar please

Microcosm writes that a single pulsar is all that is needed for a satellite orbiting the Earth to accurately correct its trajectory since the satellite is changing position significantly with respect to the Earth.  Travel between planets usually requires at least 2 pulsars because the travel vector may not be significant with respect to the pulsar to deduce positioning. [2]

Other uses for XNAV include the ability to correct the ship’s clock based on timings from pulsars.

Problems exist for XNAV before it can be implemented such as issues resulting from General and Special Relativity since the vehicle is moving.  Darn.

Thank goodness my simulator will have the Acme Widget XNAV Extension 5000 which gets around such annoyances.


[1] Sheikh, Suneel Ismail, “The Use Of Variable Celestial X-ray Sources For Spacecraft Navigation”,  http://hdl.handle.net/1903/2856, Copyright  © Digital Repository at the University of Maryland

[2] P. H. Graven1, J. T. Collins1, S. I. Sheikh2, J. E. Hanson3, “Spacecraft Navigation Using X-Ray Pulsars”, Microcosm, http://www.smad.com