Let men burn stars

As promised last post, here’s a brief dev diary entry on creating random starfields and nebulas. After generating a passable looking planet the next step is to generate some cool looking  space for the planet to exist inside, and for that you need a couple of things.

 

Firstly you need a starfield. for this I created a spherical point cloud of star sprites centred about the camera. Getting a good even distribution of stars was a little trickier than I first thought it would be but I found a good algorithm for evenly distributing points about a sphere as shown below

 

StarParticle* p = 0;
HR(field->VertexBuffer->Lock(0, 0, (void**)&p, D3DLOCK_DISCARD));
for (int i=0;i<starCount;++i)
{
    StarParticle sp;
    float u = (((rand() % 10000)/(float)10000) - 0.5) * 2.0;
    float theta = ((rand() % 10000)/(float)10000) * 2 * D3DX_PI;
    
    float distance = (rand() % (int)(maxDistance-minDistance))+minDistance;
    //uniform distribution of points about a sphere http://mathworld.wolfram.com/SpherePointPicking.html
    sp.Position.x = (minDistance+distance) * sqrt(1-pow(u,2)) * cos(theta);
    sp.Position.y = (minDistance+distance) * sqrt(1-pow(u,2)) * sin(theta);
    sp.Position.z = (minDistance+distance) * u;
    sp.Size = (float)starDesc.Width * (1-(distance/maxDistance));
    p[i] = sp;
}
HR(field->VertexBuffer->Unlock());

 

I also generate the star sprites procedurally by setting a size and start color in the center of a square, then as distance from the center increases, exponentially decaying the opacity. This produces sprites that look like this

 

image

 

When put together you get something like this (Note: I render the starfield’s into a cubemap skybox so that there’s no need to regenerate the skybox every single frame)

 

image

 

Now this is all well and good, but it does look very dull, and its also very hard to orient yourself as there are no recognizable landmarks. To fix this I added a number of extra detail layers. The first of these was two smooth background noise layers to add some lightness and variety to the background.

 

image

 

While this looks a little better its still very dull so I added a few layers of ridged Perlin noise to simulate gas nebula clouds (you can create ridges in noise by picking an offset and subtracting the raw noise value from that offset, bigger or smaller offsets create different ridging patterns). I also added some post-process bloom to give the sky a little more glow.

 

image

 

Finally I added a few layers of brighter stars of different colors and extra background star layers that were masked such that they were most visible around the nebula clouds to give the appearance of greater star density in the nebulas.

 

image

 

The results aren’t going to fool anyone into thinking its a Hubble photo, but I think they do look quite good. One thing that I haven’t yet implemented is a random palette picker to pick varied, yet complimentary colors for the nebula clouds to further increase variety. The palette picker can wait however as the next entry will be on the subject of generating random asteroid fields :)

Building steam with a grain of salt

Its been an insanely long time since this website has had an update, but I guess its better late than never. Anyways, about 3 months ago Junkship underwent a significant design refresh that was prompted by a few key factors. The first of these was the realization that as a small indie team, the scope and in particular the content creation required for the original Junkship concept was not really feasible. The second factor was a general disillusionment with hand crafted narratives and stories in games, and the desire to try a novel approach to narrative, and the third and final factor was an awesome game concept demo by Luke Smith that signalled a new and interesting direction that we could take Junkship in.

While I’m not going to go into any detail as to the specifics of the new gameplay (much of it is in flux anyway), one new aspect is that the game world will now be much more of a sandbox with an emphasis on procedurally generated content. The advantage of this are twofold, a sandbox arrangement allows the player the freedom to create their own narratives and stories, and procedural content allows the experiences of the player somewhat unique as well as reducing the content creation workload for us :)

So in order to facilitate this vision I’ve started off down the path of generating procedural space environments, and in fact the purpose of this post is to show the progress I’ve made thus far. The end goal is to procedurally generate solar systems with tens of planets, hundreds of moons and many thousands of asteroids, each of which have settlements and trade routes etc between them. While this is a fair way off, this end goal is simply the aggregation of a number of base content generators (a starfield generator, an earthlike planet generator, a rocky planet generator, an asteroid field generator, etc.)

I decided to start with the task of writing a generator for procedural earthlike planets. The basic idea was to use improved Perlin noise to generate a heightmap, which combined with a color gradient and a known sealevel I could produce a decent approximation of a planet with water oceans and continents. Below is the first iteration of this idea. To produce the terrain I used two layers of blended noise, the first was for the base continent terrain, and the second was a layer of ridged noise to produce mountain range like features. I also settled on using HLSL shaders on the GPU to do the heavy lifting as far as generating the terrain as the CPU proved too slow (10 seconds + per planet on the CPU compared with milliseconds on the GPU).

09-09-2011

While the above screenshot is all well and good its got a long way before it looks properly earthlike. The next step was to calculate terrain normals from the generated heightmap to allow bumpmapping, as well as calculating specular terms for the water and terrain. Generating the normal map was relatively simple given that I already had all the height data and just had to record the height differences between adjacent texels to get what I wanted. The hardest part getting the bump mapping to actually work was due to me foolishly recording the bumpmap vectors in world space rather than the usual tangent space.

19-09-2011

After producing a bumpmap like the one above (I also included a specular map in the alpha channel of the bumpmap, which you can’t see in the above image) I could now produce planets that looked like the one below.

20-09-2011

The main problem I now had to overcome was to make sure the terrain had realistic variations in color. After staring at pictures of earth for hours I identified a few main techniques I could use in order to improve the terrain. The most obvious addition I could make was to ensure that the poles and areas with high altitude were snowy (and have a high specular value for more shininess). A more subtle variation on this is that forests and jungles are more common at lower altitudes and closer to the equator, with deserts being more common at higher altitudes and more extreme latitudes. Finally I could also vary terrain color based on the steepness of the terrain itself. By using two square color gradient textures and sampling/blending between them using the heightmap/normal map/texel latitude I was able to produce much better looking terrain.

22-09-2011

The main feature I was now missing was clouds. I implemented these using two noise fields which I would additively blend together using a varying offset to simulate changing clouds over time. Getting the noise to look right was relatively easy, however I found the clouds really didn’t look right until they cast shadows on the terrain below them, once I did this the results were really good (especially when you see them changing with time).

03-10-2011

One last thing I wanted to add was city lights on the night side of the planet (assuming of course that the planet is inhabited) to do this I used another noise map similar to the cloud layer and prioritized the intensity to areas more typically inhabited (i.e. near the coast and in the more comfortable latitudes).

04-10-2011

After putting it all together…

1-11-2011

Satisfied with the results so far, my next challenge was to generate random starfields and nebulas (of which the previous screenshot shows an early version), but that will have to wait for another post.

Creating empathy

Here's a few thoughts of mine regarding player empathy in games. Its an old essay but I had forgotten about it until today when I did a clean out of my documents folder.

If a player is not involved in the emotional experience of a game and is instead seeing through to the machinery holding the game together, their actions become focused on beating the game and maximizing benefit to the character in the short term while disregarding the experience as a whole. The irony of this situation is that a linear medium can offer a greater emotional involvement as the player is railroaded into a particular experience. However this ignores the greatest aspect of interactive storytelling, namely for the player to shape the story as they see fit.

Due to the difficulties involved in creating truly meaningful non-linear storylines, designers cheat by commonly creating a set number of points in a story which diverge from the main story arc and give the illusion of non-linearity. However if the key decision points are noticeable by the player then the player will objectively weigh the decisions at a mechanical level removing them at an emotional level. For example given the choice between an easy and a hard path, players will often avoid the harder path, even if it means going against their opinions regarding the in-game events. As a designer it should be the goal to get the players involved in the story to the point where their emotions blind them to their "gamer sensibilities" in order to get them to take that hard path because they think its the "right" thing to do given the context of the story.

One way to stop the player viewing non-linear progression as a mechanical choice is to disguise the choice in such a way that the player cannot objectively make a choice outside of the context offered by the storyline itself. Simply put, if the player doesn't see a "this makes my character evil +1" type decision they are more likely to make a decisions based at a truer emotional level. So what tools does a designer have available to them to aid in this process?

One such approach taken by Indigo prophecy is a time based approach. Dialog in Indigo prophecy is time based, the player has a limited time to make a decision on what to say, meaning they can't dwell on the consequences of their decisions and instead have to make instinctive decisions. This time based approach to revealing a players personality could be extended further to events in the game world, for example: As a character in a collapsing mine shaft you are escaping with two other NPC's. up ahead is a T intersection, one NPC goes one way, one NPC goes the other... who do you follow, if you hesitate you die - therefore you must make a spur of the moment decision.

The other approach is one taken by Final Fantasy VII with the gold saucer "date" sequence which I dub the "accumulative" approach. Throughout the earlier parts of the game the player is presented with a large number of seemingly unimportant decisions that are used by the game to evaluate which NPC you like the most. Then at the date scene that "favored" NPC takes part with you in a "date". This effectively reveals a players true preference through decisions which the player does not link to any important consequence, so they make them instinctively. Then at the point where a large decision has to be made, the game makes the choice based on the past decisions, denying the player an opportunity to jump out of character.

These two approaches work at very different time scales, and are useful for different situations. However the "accumulative" method is far more subtle and due to the fact that the decisions are spread throughout the game, the player cannot just reload and try the other option (which is possible with the timed decision approach). For this reason the accumulative method should be employed in situations where the player is most likely to try and "game" the system, as it essentially forces them to do what subconsciously they actually want to do. However, the accumulative method should be used with caution as the designer has to be sure that the intermediary decisions actually reveal the players mindset and preferences, otherwise the crucial decisions made by the game will appear frustrating or arbitrary to the player.

Asymmetrical gameplay

Okay, So I was watching the Zero punctuation left4Dead review the other day, and at one point Yahtzee mentions that while waiting to respawn as a special zombie in the humans vs zombies gameplay mode, he'd like to play as one of the normal zombies in the intervening time. This got me thinking, wouldn't it be interesting if Valve released a free demo of left4Dead in which you could only play as the cannon fodder standard zombies in the game, so without buying the game you could still get a taste for the game, and at the same time you would be making the game more entertaining for people who actually bought the game.

Generalizing this idea wouldn't it be interesting if more games were released with a free version which unlike standard demo's allows you to take part in multiplayer action with people who bought the game, but you get to play in a less glamorous or entertaining role. Another example, World of Warcraft (or pretty much any other MMORPG for that matter) could release a free version where people can log in and play as monsters in the gameworld, obviously there's no collecting items or stat progression to the monsters they play, but they get to fight players and paid subscribers get to have a greater challenge than fighting just the AI in PvE mode.

This could be a lucrative idea for certain games as you are essentially using the free players to provide a better experience for paying players, adding value with little expenditure on the developers part.

Massively singleplayer online-ish RPG's

I had a thought recently, I'm not sure how original it is, but I thought it would make for interesting reading and a much needed update to the blog.

First a bit of background, In most modern MMORPG's you have 'instanced' dungeons which are parts of the world which exist outside the shared space of the rest of the world in which only a small number of players can participate, pretty much a small single player game embedded within the greater multiplayer game.

So essentially the idea I had was this, turning the instanced dungeon idea on its head, wouldn't it be interesting for a single player game to have multiplayer 'instances' to make the single player game's public areas seem a bit more lively?

So we have a traditional single player game, but in certain areas of the gameworld are shared spaces (such as a futuristic space market where spaceships and ship components are bought and sold), where other players playing the same single player game can wander around this market and buy and sell items from AI shop keepers and also see and interact with other players.

Ok, so without too much thought a few problems with this idea come to mind, the first and most obvious of these being that if all the players are playing as the hero in the story, wont these public areas look pretty strange with a bunch of identical hero's running around, all trying to save the universe?

Well yes that would pretty much shatter any suspension of belief among the player that they were a unique and special hero. However what if we bring a few of the ideas from the previous blog post regarding subjectivity into the mix. Just because I am the hero on my own PC, doesn't mean that other players have to see me as the same character, why couldn't I appear as a random space pirate to them and vice versa. so now all the hero's around me can be viewed from my perspective as a bunch of regular NPC's wandering around and from the other players' perspective, I too am just another pleb going about my daily business.

Okay so lets assume that other players appear to me as normal people, it would be pretty weird for them to start talking about how they were on a quest to save the universe from tyranny as well. So its obvious that we're going to have to limit the interaction between the players in these instanced multiplayer areas if we want to maintain any sort of suspension of belief or cohesion in the story. It makes sense therefore to limit the possible interactions to those that benefit from having real people taking part in these areas instead of AI's and removing the interactions that spoil the story's continuity. This is a pretty fine balancing act because if we remove all meaningful interaction there's not much point in allowing multiple people to share the same space anyway right?

So lets go back to the space market example, what benefits do we get in this scenario from having real people wandering around this market as opposed to NPC's? Well the other players could be buying and selling items to the various shopkeepers in the market, adding an interesting supply and demand mechanic to the market, some shops with in-demand products will have queues outside, while other stalls will not be so prosperous, essentially the human element will add to the dynamism and unpredictability to the market that could not be modeled as well purely though AI.

The main downside of having real people in this market however is that you don't want to know that the intergalactic badass standing next to you only has half an hour left to play before his mum forces him to go to bed, or that the space ranger at the weapons store has to leave the keyboard because its his turn to do the dishes, it ruins the singleplayer illusion.

So bringing these points together we want to allow players to interact in such a way as to make the commerce aspect of the market more interesting, while limiting what they can communicate to each other directly, so why don't we transform the market somewhat so that the majority of the trading of items isn't done between the player and AI stores, but players trading with other players. The communication between players is limited to an interface which shows which items that player wants to sell, or are wanted to buy, and a means of haggling, bargaining, and bartering for items. Now we have a situation where there is a very compelling dynamic market in place due to the human interaction rather than the static economy of a more traditional singleplayer market, and since communication is limited to the commerce interface, the story's continuity can be maintained.

Unfortunately there is one problem with the multiplayer instances idea, in that most singleplayer games have limited replayability, so over time the number of real people playing the game is going to decrease meaning this market could get pretty empty a few months after the games release. The only real solution to this is to pad out the NPC's with AI's when real players aren't around to occupy the market. Sure its not ideal, but the whole idea of the instances idea is that its simply a nice extra, not a fundamental aspect of the game, its nice to have, but its absence shouldn't spoil the game.

I think this idea has some merit and we're now starting to see the addition of online dynamic content to single player games e.g. in Spore you can see creatures created by other users populating your single player game world. I think this is just the tip of the iceberg, single player gaming will always have its place but can be enhanced through the use of clever integration with online features.

Read more