End of June Update

HELLO!

 

It seems like I am spending more time with organic lifeforms then the cybernetic ones lately.  I haven’t found a good chance to sit down and play around with Unity/Maya.  I find myself getting distracted and meeting with friends and time eludes me.

 

However I have made it back at some random hours in the night and instead of passing out I write a random blog post about something I found interesting.

 

In terms of what I accomplished this month… I got a good amount of gaming done.  I beat Mass Effect 2 again to prepare for ME3 playthrough and I recently re-acquired Resident Evil 5 and I’ve been having loads of fun re-living the fun late night co-op missions me and my old high school friends made.  I ended up skipping on the gym today so I would find time to write this blog, and its already almost 9pm :O.  Time flies when you are having fun :D.

 

The plan for tonight is to polish up two blog posts, set up Unity and go back to some Javascript tutorials.  Lets see how July works.  Hopefully I’ll get more time to do Game Dev and less time for People Dev.

 

Also ESPAINA~~~~~~!!!!!!!!!!!!!!!!!  Suck it Italy.

Unity Adventures 101: Untitled Unity Game

OLA!

Overview

I won’t lie, the last month and weeks went by so quickly.  I had hoped to have some heavy leeway into Javascript and have begun some Unity tutorials by now.  I blame Skyrim and my friends.

The plan is by the weekend of June 22, I will have done enough of Unity and Javascript to have some base work for this game.  The next step is Maya modelling stuff.  Then if this project takes too long and drags on to August, I will place it on hold.  Since I need to become familiar with Ogre 3D.

Also I “downloaded” Rosetta Stone and I am learning French properly.  When I see some Frenchmen in MIGS I will be able to network with them in the suave French language.

The reason why this process is taking longer is because I don’t want to half-ass this project since it’s personal, and I want to learn EVERYTHING.  Learning takes time, mistakes and alcohol.

The Game

THE GAME, many of you will know that I am horrible at making names for things.  My first year character’s name was Hunter Hendricks/Hendrixs/Hendriks.  My inspiration for making this game came from a couple of places.  I want to make a game that revolves around meaningful user input.  Apart from Skyrim, I managed to finally beat Dead Island (DI).  When you slice or shoot zombies in DI, you pick where you attack with serious thought because of the stamina bar.  Also, its pretty awesome to see a slow-mo zombie arm slice off.  I liked the body decaling they had on each zombie.  If I sliced a foot, flesh tore of that area.  The other area of inspiration I had was from the Metal Gear Solid: Rising trailer, where Raiden was cutting that watermelon.  I decided to make a game where you could have the awesome combat of Dead Island, with the out of combat and interactive slicing of that MGS:R trailer.

The setting and other game elements haven’t been completely finalized, because I haven’t decided on a good enough theme and setting that I would like to place this game in.  Even if the mechanics and dynamics are fun, the aesthetics is really what completes a game.  Angry birds is essentially projectile motion, but because of their theme, it’s become an incredible success.  Among other things.

The current base idea for this game is to play in the first person wielding a sharp weapon.  For now it will be a PC only title, but the end goal is to put it on the iOS and Android.  The player uses one button to slice and the other to block.

I was thinking about having base quick slice attacks, where the player unleashes a short flurry of blows to the enemy that damages them.  If the player holds down and drags the mouse in a slicing pattern, then they unleash a more powerful attack that can cut of body parts.  The last attack will be a slow motion slice combo where the player draws a slicing pattern on the screen and the character will slice in that pattern.  All these skills can be upgraded for a better outcome.

The slo mo slice can only perform 1 slice during the first level, but at max it breaks down the pattern into many more small lines.  For example, if I draw a triangle pattern at level 1, the algorithm will only sample 2 points in that  pattern and create 1 slice.  At level 3, it would break it down into 3 line segments and use those for slicing apart the enemy.

So that’s the base idea I have so far.  I will be adding more game design stuff while I continue to learn Javascript and Unity.  ITERATIVE GAME DESIGN!

Making a Game With TV Elements

Hello!

Overview

It seems like it has been a while since my last real post.  I pretty much took last week of to play video games and this week I started work.  However when I am not doing boring stuff at work I spend my time thinking about this game I am currently working on making.  The development has been slow because of other stuff going on, but its about to pick up this month.  I just need to get a solid background in Unity and Javascript so I am not a total noob when it comes to making the game.

I came across an idea a while back about why TV is so popular and what makes games popular.  How to create some sort of synergistic approach to this that would make people want to play games more, for reasons they love TV.

I realise that this new Microsoft “SmartScreen” idea about having a tablet while gaming/watching TV shoes is a pretty interesting idea that tries to combine the two in a decent way, but its putting to much emphasis on the TV side.  Here are some of my Notes.

Notes

Idea

  • Using TV characteristics while making a game
    • TV is Scheduled, broadcast and passive
    • Games are dynamic user defined experiences
  • Combine the scheduled broadcast of TV with the dynamic real-time elements of a game?
  • Turn on the TV and colours blast in your face with the dynamic real-time elements of a game?
  • The game is running when you are not playing, when you are playing your are advancing the story, like an MMO?
  • Different things happen in the game when you play at different times
    • Prime time: Big bosses come out
    • Midnight: rare and weird stuff happens

Advantages of TV

  • Advantages of TV: Passive
    • People can watch the program and it requires no use input from the player.
  • Advantages of TV: Scheduled
    • You know when something will happen, but you don’t know what will happen.
  • Advantages of TV: Broadcast
    • This information is not only shown to you, its not personal.  It is a public broadcast.

Advantages of Games

  • Advantages of Games: Dynamic
    • The game state is always changing depending on your input.  It varies from person to person.
  • Advantages of Games: Personal
    • Your user experience is different from some other person, what you do is entirely up to you during the game.

Combining Both Elements to Create a Game

The best part about TV is having some realization of what will happen.  You know on some channels what will happen, but you can also flip through channels and find something random that you like.  The other advantage is the sheer number of people TV has access to and the variety of content.  The broadcast might be similar to an MMO, but initializing a broadcast is as simple as turning on the TV but initializing an MMO requires turning on the game, downloading an update and so on.  People of the 2012’th generation are to damn impatient to wait.  At least the common consumer is.  We want information and our entertainment fast, the more manual set-up required the likelihood of them using that product goes down.

The best part about games is their dynamic and personal experiences.  Games would be boring if they were so linear that every player had the same experience while playing, then it would fail to entertain you in the way a game should.  On a side note, it is impossible to generalize about all the games in the industry because of the sheer number of games out there and there are thousands of different types that make an exception for each rule.  An assumption going fourth is that games are a system of play where the outcome is decided by the player, the system may have rules.  The aesthetic would be end desired emotional response from the Mechanics and Dynamics of the game.  The mechanics are the base components of the game that are needed to make the game played (game algorithms, game engine, game bits and parts, rules).  Dynamics are the mechanics in motion, the result of the player interacting with the mechanics.

While I love TV shows, this medium can never fully entertain me.  Sure I love Game Of Thrones, Battle Star Gallactica, Firefly, Mad Men and laughing with the cast of Community.  What if during the commercial break I could play as a warrior in a Game Of Thrones battle episode? Or if I could fly a viper ship in a Cylon attack during an episode of Battlestar Gallactica.  What if you could download an official application on your phone that gets updated at the beginning of every episode that will allow you to play mini-games that relate to that episode?

Conclusion

I saw an interesting statistic the other day, “111 million people watched the Superbowl, we share gaming experiences but the scale on which we do is infinitesimally small compared to TV.”  Granted that I doubt 111million are going to be playing a video game at the same time, and getting around 2-3 million (Average view count for viewers on major TV shows) players on a game would be the next step for this industry.  Lets just hope its not another COD clone.

There used to be a great game 1vs100 on Xbox live, which was a brodcast fun game that allowed you to play with tonnes of people for free.  I’d like to see more games like that pop up on the next gen consoles.

The one thing I wanted to take away from this “brainstorm” was the idea of making a game run 24/7 regardless of user input, however when the user decided to enter the “game” they would be engrossed in an ever moving and changing world.  Sounds a lot like an MMO, but I am trying to look at more ways to make them seem more different.

Thanks for reading
– Moose OUT

Level Up: Aftermath

Hello!

I am writing this after commuting home from the Level Up convention/award ceremony/event.

It was truly a great and interesting event for a number of reasons.  I did not plan on going until I saw that our Game Design class was cancelled at night.  At this point the only thing stopping me from going was my own laziness.  I tried to grab my other group members to join me, but I only managed to get Kevin.  Probably the best one to bring anyway.

While we never had any intention of showing of our game, or worked on it exclusively for Level Up, as soon as we got there we began debugging.

At this point out game had no sounds, no HUD and an imbalanced game system.  We did not have our blacksmith master menu system that would allow the player to level up their items and complete side quests.  We just had several battles linked by using a little rotating exclamation mark.

We had left with Gary’s group and managed to get to the convention by 3pm, from then till 5pm Kevin and I were debugging.  I was fixing the shader lighting and Kevin was balancing the game to showcase.

We essentially prepared for a huge Q/A session to gather a whole bunch of data.  I wish we had put more effort into getting a HUD into the game. Regardless of the HUD I learned a lot of stuff about the game that I would not have been able to find out through normal testing.

What needed to be fixed

Aside from the obvious points of making the game look prettier by adding higher resolution textures, HUD/GUI and the rest of the shaders.  We noticed that the collision system was a bit wonky and people were having issues with depth perception.  There needed to be a greater collision response for the player since most of the time people were asking “am I even killing this monster?”  Also the AI were updating way to fast and were very difficult.  People were getting cornered and died fairly quickly.  We need to allow the players to exit the battle and upgrade their equipment rather then re-spawning them in the same level.

The great thing was that there were a lot of artsy girls and male programmers along with some gamers who tested our game.  I noticed that some guys were very aggressive and tried to parry and dodge while moving back an attacking.  Many inexperienced gamers just stood there, got surrounded and managed to die.  Granted when Dr. Nacke and Dr. Hogue tested our game they both had issues with the HUD and the obvious problems.

I also noticed that some people were having issues with the camera movement.  We need to slow down the intensity of the camera movement since some people ended up staring down into the ground because the camera acceleration was to fast for people with slower reflexes.  It would be good to have the player adjust the camera acceleration to their preference in the final version.

When people were in the forest area, they would walk around aimlessly and end up having a horde of enemies chase them while they ran backwards and attacked.  The forest area should have regions where only some beasts spawn and they patrol that area.  Many times people spawned and were surprised that a wolf began chasing them.  We need to have better and smoother transitions between levels that give players a safe zone that they can chill back in.  Players need to make the decision to enter a dangerous area and provoke an enemy attack.  Rather then having the AI walk towards you in a line, they should recognise that they are colliding with each other and push away to corner the player.  The AI need more behaviour that will allow for a more robust battle system then just the player running backwards and attacking.

Overall, we need to give the player more and better feedback during gameplay.  We need to place our HUD into the game to tell the player how much stamina and health they have left.  We need sounds to show the location of the enemy, and tell if they are hitting an enemy.  We need to add more AI behaviour instead of endless seeking.

Lessons Learned

We went there with a 2 man team from a group of 6 people.  We went in unprepared with little expectations.  By this time next year, we should have our game completed and use this event to test our game out with a different crowd and have several different versions to test different things.  There were different types of people that played our game and it was evident in the way they played it.

For example:

  • Experienced gamers adapted very easily to the WASD controls and managed to survive for a while
  • In-experienced gamers got completely destroyed and would have preferred a controller layout with simpler buttons
  • Players had to bend down or kneel on the floor and were in a very uncomfortable position playing the game, giving a negative feel to the game already

Next time we should prepare a variety of versions of our game with different control layouts and a proper chair and screen for them to play it on.  Also polish.  Our game needs to be very polished.  By this time everything should be implemented, and we are just performing balance and fun testing.

Is this level to hard? Do we need to increase our collision response? Should you be sprinting faster? Do you need more stamina?  We should be finding the answers to these questions in preparation for the final GameCon.

Final Notes

Overall it was a good event and I did learn a lot.  I got to bond with some fellow classmates from all years of the program.  We debugged and found errors in our game and code.

Some of the attendees offered awesome advice and seeing them play the game and enjoy it regardless of the state it was in really made me happy.  Considering this was an unfinished game, I just wondered how much better it could have been and I deeply regret not preparing a better version for this day.

People were really impressed with just the fact that we built out game from the ground up not using anything.  Some people even had a hard time believing us that we were not outsourcing anything by using external programs like Havok for physics.  This probably made me the most proud to be apart of UOIT Game Development.  That and the fact that one group that was using Unity Toon shading had several members who had no idea how to do edge detection and did not know what the Sobel Operator was.

I am looking forward to going to more of these events in the future and creating better polished games in the near future.  Time to get some sleep. GOOD NIGHT!

Thank your for reading,
– Moose

Game Opinion: DLC

Hello!

Kevin recently told me that he wrote a blog relating to on-disk DLC and why that is a bad thing.  I on the other hand think that it is a good thing in many cases.

But first lets go over how the game production works.

DLC Production

Publishers are not releasing DLC on the disk for genuine bad reasons to take the consumers money and run away with it.  Instead they have data that proves that after every passing week, players are less interesting in buying DLC for the game title.

On Disk DLC

So while they have a huge team working on the core game they normally have a team on the side working to create DLC so that it is ready for launch.

In fact having a team working on DLC while the core game is being made can only make the quality of the DLC better.  Since many people don’t understand how games are developed, they don’t understand completely what “On-disk DLC” means.  If I were to create a character as a DLC item, I would have to redo all the character and squad selection menus and user interfaces for that character to be available in the main game.  So the core team developing  the game must prepare for these changes.

Also there are tonnes of games out there to be played.  Once we complete our games we normally move onto the next game.  We rarely ever hear about DLC, stop playing our current game and go play that DLC.  Instead we say, “oh, that looks interesting, once I am done with this game I might check that DLC out.”

Aside from that, the shelf life for software titles is very short.  It is better to have the option of DLC if you are an early adopter so you can buy that item while the disk is still in your console.  If you are the type of person who buys a game early on, beats it and then trades it in to get the most of your money back then early DLC is geared toward you.  EA is notorious for locking out online content for people who buy used copies of their games, forcing them to buy an online pass.

Games also go through a period of certification where once content is released for a console it must be verified.  During this period the development team has little to nothing to do.  Also if games are focused on a certain release date to maximise profit then their development team would have completed the game early and would also have nothing else to do.  During this idle period they are normally commissioned to build DLC while their core title is awaiting certification from the console manufacturer.

Despicable Money Grab

Aside from great content being built that is worth your money to purchase and deliberate publisher tricks for you to but other useless items to get a cheap in-game item.

This is like buying a happy meal to get a gun in Mass Effect.  Or buying a new mousepad to unlock a character.

When Assassins Creed Brotherhood came out they had a great Facebook game that you could play before the release of the core game to unlock items in the real game.  This was a free social game that had a lot of in game lore and content that was a nice lead into the full game.

When publishers start putting in game items with useless other counterparts is when DLC becomes a useless money grab.

Summary

Overall at its core this is discussion is if we either have the DLC on day 1 to play it, or we wait 3-6 months later and end up not playing it at all.  In any case, the price of video games have been $60 for several years now.  The quality of the games released has significantly increased over the years yet the price has remained the same.  If many consumers can afford paying $60 for a AAA title, then $15 extra for some worthwhile content is not a huge deal.

Fallout and Oblivion had amazing DLC that really extended the game and Shivering Isles was more of an expansion then DLC.

I personally don’t have a problem downloading content for a game I really like.  With Mass Effect 2, there were several pieces of DLC that released once I finished playing the game that I never got around to playing.

Game Opinion: Game Stories

Hello!

Overview

Today we are going to look at 3 types of stories and three games that show case these types of stories very well in my opinion. (Beware of Spoilers)

  1. Skyrim – fragmented player centric story
  2. Mass Effect – player choice driven
  3. Assassins Creed – linear story

Skyrim

While I personally have not beaten this game, I have spent several hundred hours combined playing Morrowind, Oblivion, Fallout 3 and Fallout: New Vegas.  Those games have similar types of story mechanics.

The fantasy games like Morrowind, Oblivion and Skyrim give little to no information about the player to leave it ambiguous enough for the player to fill it with their imagination.  Ambiguousness is key in these types of stories because the player can be anything from a warrior to a mage and a lizard man to a furry cat like race.

Fallout on the other hand does provide some history as to who the person was.  Fallout 3 you play as the hero from birth up until maturity.  Once you reach maturity to leave the safety of your underground vault to explore the Washington wasteland.  This game is more about taking a character given to you and moulding it the way you want to.  This is similar to Fable’s story progression.  You are a hero and you can either be bad or good.  Fallout uses a karma system to do this.  However the karma system didn’t have a huge impact on gameplay.  In Fable your entire persona would be modified depending on your choices.

The story in these games are fragmented and sporadically placed.  You always have a main quest objective, but whenever the player is exploring they have a chance of starting a new quest line.  That is the greatest thing about this style of telling a story.  Its more immersive because the player is in charge of completing tasks.  In other RPG’s there are little quest statements that pop up and you must read and accept that quest.

Bethesda has made their quest system very dynamic and open.  Sometimes you hear about a quest just by listening to an NPC conversation.  If someone asks you to go pick up some useless item for them and you don’t want to, you can literally kill that NPC and end that quest line.  There is a lot of freedom given to the player in this type of story telling.

Mass Effect

Mass effect is known for its speech choice interactions.  The player is in a social interaction with an NPC and they choose what to say.  The game categorises the players choice in a karma system but they have Paragon and Renegade in place of positive and negative.  Paragon would be the good intentions that are fairly selfless and morally correct.  Renegade are more selfish and immoral choices.

The game does offer some grey areas that are not paragon or renegade choices.  Later versions of the game have special scenes where the player is in a quick time event where they must quickly decide to do a paragon or renegade action.

The quick time events are a good way of advancing the story since they have the players first initial response that is most genuine.  If someone is really annoying you, and you are trying to a nice person and do paragon actions yet you flick the right trigger to slap them in the face, it brings out your true emotions.

Mass Effect doesn’t give the player a huge role in determining the story, but the player does get to pick what path to take to reach the end of the game.  Over the trilogy the choices the player makes have greater consequences.  Some choices only effected the way some NPC’s viewed your character later choices affect the lives of hundreds of people and the extinction of some races.  Even some of your crew members lives are at risk if the player picks a wrong choice.

This type of story telling is good when the game has a good story and world that the game designer wants to immerse the player in without using a completely open world.  Many players who play open world games spend more time playing around in the sandbox then caring about the story.

Assassins Creed

This game offers a really interesting storyline in the first game that looses its meaning after the 3 sequels.  They integrate their story in real world events questioning the way we look at the things around us.  The plot becomes somewhat controversial not using the standard good vs evil approach.  Instead they use the Assassins vs Templars approach.  The Assassins fight for free will and oppose a ridged system of development for humankind.  Templars believe that order is the only way for our species to realise its ultimate potential.  The series is all about two shadow organisations fighting over centuries.

Assassins Creed is really good at setting up a epic story that has a lot of depth and creates several questions in the players head as to what is going on.

Granted that the first game had very linear and unchanging gameplay but they had a story with great depth and was epic enough to build an entire franchise out of it.

Thank you for reading
– Moose

Shaders 103 – Lighting

Hello!

By now you should know what shaders are, and how they work.  You should also know how to integrate them into your code.  Since I have spent a lot of time putting lighting and what not into our game, I have become a bit of an expert with it.  So today I am going to go over how to do some fragment based lighting.

Changes from OpenGL and Movement Matrices

While I didn’t do the lighting in our game last semester, you can’t take old OpenGL code with lighting and a whole bunch of glTranslate and glRotate calls and expect it to work.

The first thing we are going to have to do is build a whole bunch of matrix functions that build a perspective, look at, rotation, translation, multiplication, invert and transform matrices.  When you download the CG API some of the sample code does have these functions build in, but they expect you to know what they do and how they work.

Here is how we will now be rendering objects instead of using the ‘gl’ draw calls.

/*** Render brass solid sphere ***/

setBrassMaterial();

/* modelView = rotateMatrix * translateMatrix */
makeRotateMatrix(70, 1, 1, 1, rotateMatrix);
makeTranslateMatrix(2, 0, 0, translateMatrix);
multMatrix(modelMatrix, translateMatrix, rotateMatrix);

/* invModelMatrix = inverse(modelMatrix) */
invertMatrix(invModelMatrix, modelMatrix);

/* Transform world-space eye and light positions to sphere's object-space. */
transform(objSpaceEyePosition, invModelMatrix, eyePosition);
cgSetParameter3fv(myCgFragmentParam_eyePosition, objSpaceEyePosition);
transform(objSpaceLightPosition, invModelMatrix, lightPosition);
cgSetParameter3fv(myCgFragmentParam_lightPosition, objSpaceLightPosition);

/* modelViewMatrix = viewMatrix * modelMatrix */
multMatrix(modelViewMatrix, viewMatrix, modelMatrix);

/* modelViewProj = projectionMatrix * modelViewMatrix */
multMatrix(modelViewProjMatrix, myProjectionMatrix, modelViewMatrix);

/* Set matrix parameter with row-major matrix. */
cgSetMatrixParameterfr(myCgVertexParam_modelViewProj, modelViewProjMatrix);
cgUpdateProgramParameters(myCgVertexProgram);
cgUpdateProgramParameters(myCgFragmentProgram);
glutSolidSphere(2.0, 40, 40);

Now this may seem like a lot, but it is necessary for working with shaders.

The beginning where we call the setBrassMaterial() function is where we set the objects parameters.   We will get to that a bit later.  For now think of it as your glColor call.

The first part where we create the matrix using a simple rotation and translation matrix is fairly simple.  You would just pass on those parameters as if you were doing a normal glRotate or glTranslate call.  You can replace these with variables so you can move these.  For now this object is stationary so we do not need it to move

However the next part is where you  multiply them to get your modelMatrix and invert it to get your final matrix.  This is so we can calculate lighting with respect to the sphere object.  We then update our eye and light Cg parameters that we will see later.

The last bit of code creates the modelView matrix and actually draws the sphere.

Using Materials

The book uses this method of creating functions that set the emissive, ambient, diffuse, specular and shininess values.  Like this:

static void setBrassMaterial(void)
{

const float brassEmissive[3] = {0.0, 0.0, 0.0},
brassAmbient[3] = {0.33, 0.22, 0.03},
brassDiffuse[3] = {0.78, 0.57, 0.11},
brassSpecular[3] = {0.99, 0.91, 0.81},
brassShininess = 27.8;

cgSetParameter3fv(myCgFragmentParam_Ke, brassEmissive);
checkForCgError("setting Ke parameter");
cgSetParameter3fv(myCgFragmentParam_Ka, brassAmbient);
checkForCgError("setting Ka parameter");
cgSetParameter3fv(myCgFragmentParam_Kd, brassDiffuse);
checkForCgError("setting Kd parameter");
cgSetParameter3fv(myCgFragmentParam_Ks, brassSpecular);
checkForCgError("setting Ks parameter");
cgSetParameter1f(myCgFragmentParam_shininess, brassShininess);
checkForCgError("setting shininess parameter");

}

So this function just sets the colour of each of the light parameters that we want.  Using this we can make several material functions for different objects and control them independently in whatever way we want.  You can make a character, enemy and level material.  Right before you load your character, you can make their lighting bright so that they stand out.  For enemies, you can give them a bit of a red highlight to show the player that they pose a threat.

What to Initialise

Now we are in our initCg() function let us break it down into a vertex and fragment area.

Vertex Initialisation

myCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);
cgGLSetOptimalOptions(myCgVertexProfile);
checkForCgError("selecting vertex profile");

myCgVertexProgram =
cgCreateProgramFromFile(
myCgContext,              /* Cg runtime context */
CG_SOURCE,                /* Program in human-readable form */
myVertexProgramFileName,  /* Name of file containing program */
myCgVertexProfile,        /* Profile: OpenGL ARB vertex program */
myVertexProgramName,      /* Entry function name */
NULL);                    /* No extra compiler options */
checkForCgError("creating vertex program from file");
cgGLLoadProgram(myCgVertexProgram);
checkForCgError("loading vertex program");

#define GET_VERTEX_PARAM(name) \
myCgVertexParam_##name = \
cgGetNamedParameter(myCgVertexProgram, #name); \
checkForCgError("could not get " #name " parameter");

GET_VERTEX_PARAM(modelViewProj);

This is a fairly simple vertex initialisation.  The main point is to see that we are passing the modelViewProj matrix.  If you go back up to our draw code you can see where we update myCgVertexParam_modelViewProj parameter.

Vertex Shader Code

void v_fragmentLighting(
float4 position : POSITION,
float3 normal   : NORMAL,

out float4 oPosition : POSITION,
out float3 objectPos : TEXCOORD0,
out float3 oNormal   : TEXCOORD1,

uniform float4x4 modelViewProj)
{
oPosition = mul(modelViewProj, position);
objectPos = position.xyz;
oNormal = normal;
}

You can still see that this vertex shader is still simple.  We take our model view matrix and multiply that by our position and output both our position and our object position.

Fragment Initialisation

#define GET_FRAGMENT_PARAM(name) \
myCgFragmentParam_##name = \
cgGetNamedParameter(myCgFragmentProgram, #name); \
checkForCgError("could not get " #name " parameter");

GET_FRAGMENT_PARAM(globalAmbient);
GET_FRAGMENT_PARAM(lightColor);
GET_FRAGMENT_PARAM(lightPosition);
GET_FRAGMENT_PARAM(eyePosition);
GET_FRAGMENT_PARAM(Ke);
GET_FRAGMENT_PARAM(Ka);
GET_FRAGMENT_PARAM(Kd);
GET_FRAGMENT_PARAM(Ks);
GET_FRAGMENT_PARAM(shininess);

/* Set light source color parameters once. */
cgSetParameter3fv(myCgFragmentParam_globalAmbient, myGlobalAmbient);
cgSetParameter3fv(myCgFragmentParam_lightColor, myLightColor);

This not the full code for the initialisation.  This smidgen of code contains the new parameters that we will be passing into our fragment shader to compute our lighting.

Fragment Shader Code

void basicLight(
float4 position : TEXCOORD0,
float3 normal   : TEXCOORD1,

out float4 color : COLOR,

uniform float3 globalAmbient,
uniform float3 lightColor,
uniform float3 lightPosition,
uniform float3 eyePosition,
uniform float3 Ke,
uniform float3 Ka,
uniform float3 Kd,
uniform float3 Ks,
uniform float shininess)
{
float3 P = position.xyz;
float3 N = normalize(normal);

// Compute emissive term
float3 emissive = Ke;

// Compute ambient term
float3 ambient = Ka * globalAmbient;

// Compute the diffuse term
float3 L = normalize(lightPosition - P);
float diffuseLight = max(dot(L, N), 0);
float3 diffuse = Kd * lightColor * diffuseLight;

// Compute the specular term
float3 V = normalize(eyePosition - P);
float3 H = normalize(L + V);
float specularLight = pow(max(dot(H, N), 0), shininess);
if (diffuseLight <= 0) specularLight = 0;
float3 specular = Ks * lightColor * specularLight;

color.xyz = emissive + ambient + diffuse + specular;
color.w = 1;
}

This code takes in our parameters that we pass in our C++ code to compute emissive, ambient, diffuse and specular lighting.  Emissive and ambient are fairly easy to compute, however diffuse and specular require some more work.

Emissive Light

Emissive is the light that is emitted or given off by a surface.  This can be used to stimulate glowing
Equation: emissive = Ke
Ke is the materials emissive color

Ambient Light

Ambient or ambience is light that has bounced around from different objects.  This can be used to make your environments better.  You can have a grey ambient for smoggy cities or a nice bright yellow ambient for forests and nature environments.
Equation: ambient = Ka * globalAmbient
Ka is the material’s ambient reflectance
globalAmbient is the color of the incoming ambient light

Diffuse Light 1

Diffuse light is reflected off a surface equally in all directions.  Even if an object has small nooks and crannies, the light will bounce of its rough texture
Equation: diffuse = Kd * lightColor * max(N dot L, 0)
Kd is the material’s diffuse color
lightColor is the color of the incoming diffuse light
N is the normalised surface normal
L is the normalised vector toward the light source
P is the point being shaded

Diffuse Lighting 2
Specular Light 1

Specular lighting is light scattered from a surface around the mirror direction.  It is only seen on very shiny and metallic materials.  Unlike the above types of light, Specular depends on where the viewer is looking at for it to work.  It also takes into account how shiny a surface is.
Equation:  specular = Ks * lightColor * facing * (max(N dot H, 0))^shininess
Kd is the materials specular color
lightColor is the color of the incoming specular light
N is the normalized surface normal
V is the normalized vector toward the viewpoint
L is the normalized vector  toward the light source
H is the normalized vector that is halfway between V and L
P is the point being shaded
facing is 1 is N dot L is greater then 0 and 0 otherwise

Specular Light 2

Then you add all the lights together and that is lighting in a nutshell.

Fragment Lighting

Thank your for reading,
– Moose

Galvados: The Pillar of the Roman Empire

Galvados: Roman Warrior

Time Period and Place

During the Ancient Roman era in 1st Century B.C. during the reign of Julius Caeser, Galvados lived.  Galvados went from a slave in the gladiator arena to a decorated bronze knight of the Roman Republic.  Galvados rose to fame during the Gladiator War (Third Serville War) where he fought against the slaves and Spartacus.

Interview Questions

What is your Name? Gender? Race? Religion? Age?

Lentulus Batiatus my lanista named me Galvados after I saved his life.  I am a Thracian born in the land of Thrace on 90 (B.C.).  I lost faith in the gods after I killed one of them.

You seem like a man of few words, am I right?

*Grunts*.

Were you a slave? Which God did you kill?

My tribe was ambushed by Glaber and I was sold to Batiatus after I killed 40 Romans in the arena.  I ended the life of Spartacus.

Spartacus was not a god to many people, was he not a fellow Thracian and a brother in the Arena?  Why did you not fight alongside your gladiator brethren during the war?

Spartacus was a god to the slaves.  He tried to train skimpy slaves to wield sticks while fighting against Romans covered in iron.  I had won my freedom in the arena and Crassus offered to train me as a centurion to later become a Legatus.  I fought in the front lines while leading my men to push Spartacus toward the mountains in Petelia.

Last events of the war in 71 BC
What year is it now? What are your plans now that the war is over?

It is 50 (B.C.) and I have been asked to watch guard over Gaius Julius Caesar.

What about your parents and how you were growing up, did you struggle and if so in what way?

*Grunts then laughs*.  You really know nothing of Thracians do you.

Well then, how would someone stereotype you at a glance?

My bronze armour.

Where did you get the armour? It seems custom made.

I told Crassus that I wanted to fight alongside my men.  He did not want me falling in battle and ordered several Blacksmiths to create this suit of armour.  The large two handed sword was forged a by a master blacksmith and he named it Nerio after the goddess of war.

What about the Helmet? I have been told that you never take it off.  You are even wearing it now.

I lost my identity the day I became a slave.  The man you see in front of you now is a Roman warrior.  My face was that of a slave.

You seem lonely, do you have a significant other? Best friends?

Glaber took my wife as his house slave when he invaded my tribe.  He killed her when I was still in the arena after I threw a spear at him as he sat in the imperial box watching my fight.  I killed him during an ambush by Spartacus and his men on Mount Vesuvius.  Spartacus let me leave unharmed.  You could say that Spartacus was my only friend.

I am interested in you relationship with Spartacus.  He was your friend and a brother in battle.  You say you ended his life, but his body was never found?

Spartacus and his men are dead.  We are members of the same barbaric tribe that is near its extinction.  The relationship we have is the same as you and other people of your race.  Is this an interview about me or Spartacus?

You, I am sorry.  What is your economic situation?

Money is not something I value.  I worked under the richest man in Rome (Crassus).  As long as my armour does not rust and my sword is sharp I will be a happy man.

What was your relationship with Crassus?  How has his death affected you these past 3 years?

Crassus saw my skill as a man-slayer after I almost killed my doctore (gladiator teacher).  He saw to it that I had my freedom and I was looked after.  After his death I guarded his sons until the Republic asked me to help Julius Caesar.

Crassus ruled with an Iron fist, he revived decimation and punished his troops.  He ordered the crucifixion of over 6,000 slaves to teach Rome from ever rebelling again.  Other people saw him as a tyrant, what do you say now?

I am not other people.

What about the decimation, having troops kill their own comrades?

We won the war, even when we were outnumbered by the slaves.

Where does your allegiance lie? Can you be trusted by your friends? What are your vices?

Right now I fight for the Roman Republic.  The men under my command can trust me.  Friends and women just make men weak.

You seem like you live for battle, do you enjoy killing other men?  What gives you contentment?

I enjoy the thrill of fighting.  Slashing a man’s chest to see his intestines bleed out is gratifying.  I miss the roar of the fans in the arena when you decapitate your enemy.

I guess that means that you do not fear death?

I fear I will not die a noble death.  If a man is able to best me in combat, he is worthy to take my life.

What is one secret about you that no one knows about you?

*Grunts*.  This interview is over.

Biography

  • Given Name: Galvados.  Meaning: Protector.  Comes from the word galvanization
  • Birth Name: Aspios.  Meaning noble, power, grace, beauty, strength and freedom.
  • Born: Thracian/Thrace
  • Current Location: Rome
  • Age: 40
  • Height: 6′ 0″
  • Weight: 240lbs with armour 300lbs with sword 325lbs
  • Religion: None
  • Hair Colour: Brown
  • Skin Colour: Light Brown
  • Eye Colour: Unknown
  • Language: Latin, Greek and Thracian Language

Strengths

  • Super human strength
  • Sword mastery
  • Champion of gladiator combat
  • Expert hand to hand combat skills
  • Insane endurance
  • Dominant personality during leadership
  • Powerful military leader
  • Intimidating presence

Weaknesses

  • Intimidating presence
  • Unknown identity
  • Not good with women and children
  • Barbaric personality
  • Armour makes him slower
  • Trouble with relationships and human contact
  • Blood thirsty
  • Years of war and battle will take a toll on his body and his mind
  • Fairly emotionless outside of battle

Personal History/Story Arc

Galvados was born in a barbaric tribe known as the Thracians.  A man’s strength in battle proved his worth as a human.  Weaker men were considered women and left to do feminine tasks.  Galvados became a great warrior by helping his fellow men protect the tribe against other barbarians.  He falls madly in love with a beautiful Thracian woman named Naevia.  She becomes his world shortly after their marriage.  Galvados was once an amiable man who cared about his tribe and its defence.  Only few knew him as ‘Aspios’, his birth name.

Map of Ancient Rome

During a large scale battle with another barbaric tribes, the Romans ambush the town absent of its warriors and drag the slaves over the Mediterranean Sea to Rome.  When Galvados accompanied by Spartacus and other Tracians arrive to their town they are ambushed by Gaius Claudius Glaber and his small army.  Tied up and placed on a boat headed straight for the Arena, Galvados and Spartacus’ lives were about to change.  Galvados and Spartacus were both concerned about their wives and grew a brotherly bond at this point.  They tried to fight their Roman captors and escape several times, but were only met with punishment by a whip.

When they arrived in Rome they were sent to the Arena to test their skills in combat.  Spartacus and Galvados fought side by side and took out a mix of 40 Roman warriors.  Glaber demanded they be executed but Batiatus wanted to purchase these slaves.  It is well known to many Romans that Thracians are barbaric individuals that hold honour in battle and answer to no one.  Training a Thracian is a near impossible task, yet Batiatus just purchased two of them.

While in Batiatus’ ludus (gladiator school), Galvados and Spartacus were trained by the doctore Oenomaus.  At the time the current undefeated champion was Crixus, he was one of Batiatus’ top gladiators.  Spartacus was a difficult man, and constantly fought with his captors and the other men.  Galvados on the other hand was eager to learn and fight.  He had heard of Gannicus, one of Batiatus old gladiators who was granted his freedom.  Galvados was told if he became the champion, he would be given his freedom so he could look for his wife.

Spartacus was in a similar predicament however, Batiatus told him that he would look for Spartacus’ wife in return for his obedience.  Batiatus on the other hand had found Spartacus’ wife and ordered her dead.  In one of Galvados’ previous battles, he saw Glaber watching and threw a spear towards him, missing by an inch.  Enraged Glaber killed  Galvados’ wife and sent the head to Batiatus.

One of the slaves in the house attempted to kill Batiatus, Galvados reacted quickly and saved Batiatus’ life.  Batiatus rewarded Galvados by naming him Galvados instead of referring to him as the Thracian.

When the time came, Galvados had bested Crixus in combat and his next match was one with his good friend and teacher Oenomaus.  Before the battle Spartacus had found out that Batiatus had killed his wife and wanted revenge.  Spartacus was planning a rebellion and wanted Galvados to help them.  Galvados refused and went on to fight his last battle.  During that battle Galvados bested Oenomaus and Batiatus pleaded to the Arena Master to spare Oenomaus’ life.

Marcus Licinius Crassus (General and Politician) was in the VIP crowd and saw Galvados match.  He granted his freedom and gave him a job.  Back at the ludus, Spartacus had found the head of Galvados’ wife and that Batiatus was hiding it from him.

At this point Spartacus had started his rebellion and later killed Batiatus.  Galvados was in Rome being trained as a Centurion and was being taught how to lead an army from Crassus.

A year passed and Spartacus was looting and pillaging while creating an army of slaves.  Galvados was sent by Crassus to eliminate Spartacus.  He was sent to work with a small unit to Vesuvius where Spartacus was hiding.  He was told to fight alongside Glaber’s men.  Spartacus had anticipated them and ambushed them.  Only Glaber and Galvados were spared.  Spartacus told Galvados about how Glaber killed his wife.  Galvados ripped Glaber apart and spread his body parts around Vesuvius.

Without anything to live for Galvados told Spartacus to end his life.  Spartacus convinced him to join their cause.  Galvados told Spartacus that he would not be able to win this war, and the only thing he could do was escape and save as many lives.  They then planned to retreat in a mountain pass where they would escape through a series of tunnels where a boat awaits to take them away from Rome.  Galvados volunteered to go back to the Roman army to help their plan.  Galvados returned to the Roman army with the news of Glaber’s death and the position of Spartacus’ troops.  He lead the attack killing many slaves and innocent men.

Galvados was slowly going mad.  First his enslavement, then the death of his wife and now the endless murder of many people.  The war was coming to an end and Galvados was becoming more and more robotic.  Crassus let him lead the battle ordering him to bring Spartacus’ head to him as a test of his loyalty.

During the battle, Galvados had cornered Spartacus and what was left of his men in the mountains.  Spartacus and his men began to escape as planned.  Galvados asked Spartacus to end his life in one final battle.  Spartacus refused.  Galvados mentioned that Crassus would probably kill him for not bringing the head of Spartacus.  Spartacus then began to carve out his flesh ripping out his slave mark along with his Thracian tattoo.  He dropped his bloodied skin on the lap of Galvados and left.

Galvados became a hero and the slayer of a God.  He received several accolades and gained to the rank of Legatus.

Defining Moments

  1. When Galvados became a slave he had forsaken his old identity.  He put on a helmet and became a ruthless gladiator.  He went from becoming a patriotic Thracian to a bloodthirsty monster who needed to kill for his freedom.  The only thing driving his rage was the idea that he would find and save his wife.
  2. Once Galvados entered Vesuvius with Glaber and he was ambushed by Spartacus was his last major defining moment.   He had always hated Glaber and once he found out he had killed his wife, Galvados went into an unstoppable rage.  At this point life was meaningless to him, yet Spartacus did not want him to die.  Galvados became a shell of his former self after this point.  He simply followed orders, like a robot.

Game Idea: Unnamed RPG

Overview

So I spent the last two weeks going over how I think RPG’s should be made in order to create a great user experience.  I talked about the difference between JRPG and WRPG and why I thought WRPGs are better.  To summarise, I think that WRPGs have better combat systems and more immersive  worlds as a result.  JRPGs have been focused on stories and the only great JRPGs that sell well in North America are the ones that try to copy some WRPG mechanics (Dark/Demon Souls, Monster Hunter and so on).

I have a game idea focused around a theme and a world that I have been keeping at the back of my head for a while.  Now that I have a blog and have some knowledge of Game Design behind me I think it would be a good time to start working on making this game a reality.

Game Idea

My goal for this game is to create a unique user experience.  The only time I find that I have a great RPG experience is when I play Bethesda RPGs like Fallout 3, Morrowind, Oblivion and Skyrim.  Why is this?  Their worlds are so large and offer so much freedom and randomness that as a player you actually feel like you are sculpting your own adventure.

Imagine a game like Dungeons & Dragons (Tabletop RPG).  While I have never played a game, the basics of the game are as follows:

  • Each player controls a single player
  • Players work together in a party of adventurers where each member has their own speciality (warrior, mage, healer, etc.)
  • Each player directs the actions of his or her character and its interactions with the other characters in the game.  This is done using verbal impersonation of the characters by the players, while also employing a variety of social and other useful cognitive skills, such as logic, basic mathematics and imagination.
  • Items required to play the game are the rulebooks, a character sheet for each player and a number of polyhedral dice.
You essentially sculpt your character to whoever you want them to be, then allow them to roam around in a world as you see fit.

While I obviously don’t have the time and resources to create a full 3D world as expansive as the Elder Scrolls and Falllout games, I do feel that this is a great idea, but not really a feasible one.  It is greatly out of scope for one person and is a bad way to start designing a game.  Games made by indie studios  should start designing their games through a unique mechanic or dynamic as opposed to a theme.

Since I am horrible at naming things I have yet to name the game or the setting.

Lore

The planet Earth has been around for about 4.54 billion years and humanity has been said to have originated about 200,000 years ago while reaching our behavioural modernity around 50,000 years ago.  Imagine a fantasy world where humans are not the only intelligent species around.  For the sake of this game, imagine a large province.

This province is populated by several races, some intelligent and some… not.  It has varying terrain like mountains, thick forests, dessert plateaus, large plains, swampy mangroves and tropical jungles.

  • Humans (60 year lifespan average)(Live in large cities around the plains):  The baby race.  Said to have evolved from monkey’s, humans still have similar characteristics to their primal counterparts.   The have only been around for a few thousand years but they are a nuisance to every other race.  They have short lifespans however their growth in one lifetime is huge.  They are very intelligent, being able to create massive structures and tools using the planet as their resource.  Humans have the physical capability to become great warriors and rouges.  Their intellect allows them to create objects that allow them to manipulate matter giving them artificial magical powers.
  • Dwarfs (200 years+)(Live in the Mountains): Dwarfs are very durable creatures.  It is said they had evolved from moles.  Dwarfs are very short creatures and great at operating in minimal sunlight.  They have great eyesight and smell.  Dwarfs are best known for their metal work.  They live and operate near mountainous terrain allowing them to gain easy access to minerals.  Dwarfs create large and intricate tunnels around the land to trade with other races.  They are rarely seen outside the mountains in the daylight.  Dwarfs make formidable warriors because of their metalwork and powerful bodies.
  • Light Elves (Over a 1000 years/Immortal)(Live in a floating city that hovers over the province): Light elves are the most unfriendly of the humanoid races.  They are a very powerful and mystical race that are able to channel energies unknown to other races.  This allows them to create unbelievable inventions and create different forms of matter.  Light elves have been rumoured to have evolved from butterflies which is why each light elf can fly.  Light elves are very independent creatures that despise humans and other races.  Light elves make powerful mages and healers because of  their mystical powers
  • Dark Elves (100 years+)(Forest): Dark elves are a race created by a cross breed between light elves and humans.  They were banished from the Light Elf world and settled in the forest where they created a small community.  They have a mix of the mystical Elf power but their human blood makes them mortal.  Due to the cross breed they have also lost the ability to fly, but in return they gain immense strength.

Those are the humanoid races.  Next come the more beast like races.

  • Orcs (200+ years)(Dessert): Orcs are huge red beasts that terrorise the province.  They live in a giant Pit in the dessert in the harshest conditions.  They are very primal in nature and only elect a leader by his power.  They venture into the jungles to scout for food. They are a mix of Alligators and Rhinos.
  • Trolls (100+ years)(Swamps):  Trolls are an aquatic race.  They are a more intelligent race then the Orcs, however they are still very primal.  They live in an underwater city surrounded by swampy mangroves.  Trolls look like a mix of Salamanders and Toads.
  • Goblins (50+ years)(Jungles): Goblins are tiny Orcs.  What they lack in strength they make up for in numbers.  Goblins outnumber every race put together and more. They lack a community and a leader, instead they live in packs atop the jungle trees.  Goblins are tiny and scrawny versions of Orcs.
Aside from those races, the world will be populated by other fantasy creatures that the player will be fighting with or teaming up with in the story.

The other main creature that will be in the game are dragons.  Unlike other games, dragons will not be some evil beings that must be slain.   Instead, these dragons are guardians.  Not much is known about these dragons and the only race that knows much informations about them are the Light Elves.  Dragons are elemental guardians that keep the balance of nature flowing.

  • Fire dragon: In charge of the land and swims in the molten lava underneath the earth.  It maintains the flow of lava to while preventing earthquakes and volcanic eruptions.
  • Wind dragon: Lives in the sky maintaining the weather.  It controls the flow of wind preventing whirlwinds and weather storms.
  • Water dragon: Maintains the sea current and prevents flash floods.
  • Earth dragon: Lives in the surface maintaining the forests and mountains.  The Earth dragon keeps the mountains full of minerals and the ecosystem healthy.
  • Light and Dark dragon.  These are ethereal dragons that watch over the province.  They are similar to the Yin/Yang where one is positive and the other is negative.  The Light dragon believes in the goodness of creatures while the Dark dragon believes that every creature is evil.
The purpose of the dragons is to maintain the balance.  When a creature upsets the balance the dragons fight and argue creating bad weather and all sorts of disasters.  Once the dragons fighting is over, they take action.  This normally means the full destruction of the race that is causing the imbalance.  Many years ago there were different races and creatures, and they were ultimately defeated by a genocide from the dragons.

Theme/Conflict

The mains underlying theme of the game should be global warming.  What I am going for with this game is to create a controversial plot that is different depending on how you play it.  The player will be able to start the game while playing with any race and he is influenced by the NPC’s to create a decision.  Rather then the Paragon and Renegade system in Mass Effect or the Fallout Karma system.  This system doesn’t have a bad or good scale.  Your actions are biased by the race you play.

  • Human: If you start out as a human, you will see that humans have no regard for the planet.  They have a military monarchy that governs their society.  There are also several guilds in the town that work independently from the royal military.  There are mercenaries, wizards, priests, and thief guilds.  Once your human character is built, you will have a choice to join an independent guild where you are free to do as you please under the teachings on that guild, or to join the royal army.  The royal army is a strict place where you will grow to be a powerful warrior with a lot of power but you will be focused on the betterment and growth of humanity.
  • Dwarf: Dwarves are hard workers.  As a Dwarf you have a choice to either become a noble blacksmith, miner or to join the Dwarven army.  Dwarves believe in nature and only taking what they need.  While their community has a similar monarchy like the humans, they are much more friendly to other races.  They do not wish to dominate, but to trade and be friendly with the other races.
  • Light Elves: To other races they are snobby and evil.  However they are only being protective of their planet.  They believe in taking and using the minimal amount of resources, and everything must be recycled and reused.  They see the other races as wasteful and greedy.  Elves are a very religious society and because of it they have insane magical powers.  They specialise in all forms of magic from destruction to healing.
  • Dark Elves:  They are a nomadic race that move around the forest living in-tune with nature.  Whatever they take they give back and try to follow the same standards as the Light Elves.  They do not wish to advance and evolve with technology like the Humans, but instead they wish to live their lives.  Dark Elves love to party, sing and dance.  They are a very timid and passive race.  However each Dark Elf has immense potential to be great warriors and mages.
  • Orcs: Their goal is to prove their power.  They will fight anyone and anything.  They are a very barbaric race where a mans battle strength is his life.  The women Orcs handle all the day-to-day jobs while the men go out to prove their strength and bring food.
  • Trolls:  Trolls value power, however they are a more organised race.  They don’t have much conflict with other races, as long as they don’t enter their territory.  Trolls are a very independent race that lack the intelligence to advance as quick as the humanoid race, but are not as barbaric as the orcs
  • Goblins: They are treated as the Orc’s “bitch” workers.  They work for the Orcs doing crappy tasks in exchange for protection and scraps of food.  The other goblins live in the forest constantly fighting with the Dark Elves.

Story

I am sure that I am confusing the reader as to what the game is.  For now I have set up the setting and the races as well as their personalities.  The point of the game is to play as one of these races experiencing different viewpoints in the same story.  The story will have similar ‘choke points’ but the outcome will vary leading to a different fallout.

The main story is that you play as one of the many races in this province.  You begin to work your way up to someone of value.  By completing sidequests and building your player character to a decent warrior.  Later on you find out that the Humans are advancing and trying to take over some more territory.  They begin to create alliances with other races to negotiate a peaceful outcome.  Depending on the players actions, they will either maintain a good relationship with the humans, or cause a war.

The war is interrupted by the entrance of several angry dragons.  These dragons are angry at the races for abusing the natural resources at a rate faster then it can grow back.  Depending on the outcome, your race with side with the dragons or fight them.

Once that choke point is completed the race will either be fighting with the dragons for the destruction of the incompetent race or be fighting for their survival.

This game is essentially a giant war game where you build allegiances or enemies.  As a player you can also defect from your race to join the other side.  If you are a Human in the mercenary guild and you have become its master, you are in total control over that guild.  If the Royal army declares war on the Light Elves you may side with the Elves and fight alongside them.

I feel that this makes the game more unique offering several different outcomes every time the player plays the game.  In the end the player can live in peace with the other races, but be in constant fear of the dragons, or the player can kill the dragons and survive without ethereal judgement but at the cost of random disasters.

Gameplay

I would like the game to play out like an action RPG similar to the ‘Tales of’ games.  When you see an enemy you either fight them in real time with a party of 3 other characters or get teleported to a battlefield where you fight a mix of enemies.

Final Notes

I have not focused to much on the gameplay because I feel that if I were to build this game I would not have the resources to create all the art assets myself.  Instead I would create a 2D sprite game to test out how the story and decisions work while playing around with the battle system.

Thank you for reading
– Moose.

Shaders 102 – Code Integration

Overview

Today I am going to talk about how to integrate shaders into your code.  Starting with the layout of a shader program and how to integrate it in your code.

Basic Shader Code

Here is a vertex shader:

//vertex shader from chapter 3 of the Cg textbook

struct C3E2v_Output {
float4 position : POSITION;
float3 color : COLOR;
float2 texCoord : TEXCOORD0;
};

C3E2v_Output C3E2v_varying(
float2 position : POSITION,
float4 color : COLOR,
float2 texCoord : TEXCOORD0)
{
C3E2v_Output OUT;

OUT.position = float4(position,0,1);
OUT.color = color;
OUT.texCoord = texCoord;

return OUT;
}

Breakdown

The program first begins with an output structure as follows:

struct C3E2v_Output {
float4 position : POSITION;
float3 color : COLOR;
float2 texCoord : TEXCOORD0;
};

Since we know that this is the vertex shader, and it has to pass values to the rest of the graphics pipeline, this is structure is just some of the values that our shader will be using.  By defining an output structure we can manipulate the items inside it.  Basically this is like a variable declaration for a function where we would be outputting position, color and texture coordinates.

Last week we talked about how Cg has vectors and matrices integrated into their variable declaration.

  • float4 position : is essentially =[x,y,z,w] where w=1.  If this was written in C++ it would be float position[4]={x,y,z,w}
  • float3 color : is similar to the vector above, but this is used to represent our colour channels =[r,g,b]
  • float2 texCoord : is our U and V coordinates in our texture = [u,v]
While this program does not showcase the matrix declaration of Cg, here are some examples
  • float4x4 matrix1 : this is a four by four matrix with 16 elements
  • half3x2 matrix2 : this is a three by two matrix with 6 elements
  • fixed2x4 matrix3 : this is a two by four matrix with 8 elements
If you wanted to declare a matrix with some values, you would do it like this:
float2x3 = {1.0, 2.0,
            3.0, 4.0,
           5.0, 6.0}

 


Next we have our entry function:

C3E2v_Output C3E2v_varying(
float2 position : POSITION,
float4 color : COLOR,
float2 texCoord : TEXCOORD0)

This is what defines our fragment or vertex program.  This is similar to the main function in C/C++.  What this is telling us, is that our shader is taking in position, colour and texture coordinates.  We know that our structure above has the same parameters as our input, so we know that we are going to be manipulating these parameters and then outputting them.

Last we have our function body:

C3E2v_Output OUT;

OUT.position = float4(position,0,1);
OUT.color = color;
OUT.texCoord = texCoord;

return OUT;

First we start of by creating our structure object called OUT.  This code really doesn’t do much but set values in the structure equal to the inputs and output them to the next stage in the pipeline.  The interesting piece of code is the OUT.position = float4(position,0,1) part.  This takes the incoming position with only two incoming parameters (x,y) and converts it into a float4 by giving the last two variables a 0 and 1 value to get (x,y,0,1).

3D Graphics Application Integration

Creating Variables

So knowing how that code works is great, however implementing Cg code in your C++ code is where I normally spend most of my time working with shaders.  The actual shader code is fairly easy to work with, but integrating it in your Graphics Application is where the real pain is.  The Cg book doesn’t really cover this explicitly, however it does have examples in the API in your /Program Files/NVIDIA Corporation/Cg/examples/ folder.

To start there are a number of things you have to declare, I normally do these as global variables:

static CGcontext myCgContext;
static CGprofile myCgVertexProfile,
                 myCgFragmentProfile;
static CGprogram myCgVertexProgram,
                 myCgFragmentProgram;
static CGparameter myCgVertexParam_constantColor;

static const char *myProgramName = "Varying Parameter",
*myVertexProgramFileName = "C3E2v_varying.cg",
*myVertexProgramName = "C3E2v_varying",
*myFragmentProgramFileName = "C2E2f_passthru.cg",
*myFragmentProgramName = "C2E2f_passthru";

Obviously the names of these do not have to be the same as what I have written, but the idea is to teach you what each one is.

The first part of creating the CGcontext is the part I know the least about.  I believe it is the part where you initialise the shader program.  So just be sure to ALWAYS do this.

The next part is creating your vertex and fragment profile.  This is another thing to always do.

The next two parts are where you are given a lot of freedom.  The CGparameter will vary from program to program.  These are essentially parameters that you take in your graphics application and send to your shader.  constantColor is just a variable that we can send to our shader to replace the colour of every pixel or vertex.  Later on I will post on how we can send in parameters like diffuse light color, light position, attenuation parameters and much more.

The last part is the program names.  This is where you define your main function for each shader and the name of their file name.  Common names for each are fragment_passthru or vertex_passthru.

Initialise Shaders

The next step is where you physically create the shader program.  Somewhere in your glut loop you should create a initCg() void function where you place all your initialisations.  The book places everything in main, which I find to be stupid, so don’t do that.  It creates a lot of hard to read clutter.

myCgContext = cgCreateContext();
checkForCgError("creating context");
cgGLSetDebugMode(CG_FALSE);
cgSetParameterSettingMode(myCgContext, CG_DEFERRED_PARAMETER_SETTING);

myCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);
cgGLSetOptimalOptions(myCgVertexProfile);
checkForCgError("selecting vertex profile");

myCgVertexProgram =
cgCreateProgramFromFile(
myCgContext,              // Cg runtime context
CG_SOURCE,                // Program in human-readable form
myVertexProgramFileName,  // Name of file containing program
myCgVertexProfile,        // Profile: OpenGL ARB vertex program
myVertexProgramName,      // Entry function name
NULL);                    // No extra compiler options;
checkForCgError("creating vertex program from file");
cgGLLoadProgram(myCgVertexProgram);
checkForCgError("loading verex program");

This code is fairly simple.  The beginning part creates the CgContext.  Then we create our vertex profile.  Lastly we tell the program where our Cg file is and the name of our entry function.  You would do something similar for the fragment shader.

The checkForCgError help your debug.  If anything goes wrong in the shader at that point, your cgError function will output an error code.

The other thing you can place in your initCg function is a GET_PARAM statement where you can pass variables to your shader program.

#define GET_PARAM(name) \
myCgVertexParam_##name = \
cgGetNamedParameter(myCgVertexProgram, #name); \
checkForCgError("could not get " #name " parameter");

GET_PARAM(modelViewProj);
GET_PARAM(globalAmbient);
GET_PARAM(eyePosition);

#define GET_PARAM2(varname, cgname) \
myCgVertexParam_##varname = \
cgGetNamedParameter(myCgVertexProgram, cgname); \
checkForCgError("could not get " cgname " parameter");

GET_PARAM2(material_Ke, "material.Ke");
GET_PARAM2(material_Ka, "material.Ka");
GET_PARAM2(material_Kd, "material.Kd");
GET_PARAM2(material_Ks, "material.Ks");
GET_PARAM2(material_shininess, "material.shininess");

The is an example of sending parameters directly to your entry function and to other structures you can make.  The first batch of code sends the modelViewProj matrix, GlobalAmbient colour and the eyePosition of the camera.  These would be items you list in your entry function input parameters.

The other batch of code is an example of you sending parameters to a structure called Material.  Material has emmissive, ambient, diffuse and specular lighting along with a shininess parameter.  This is helpful for creating virtual objects that reflect light differently so things can look like rubber or plastic.

 Enabling and Disabling

The last and simplest thing to do is to enable and disable your shaders during your OpenGL draw loop.

When you are drawing your objects, you need to bind your fragment and vertex shaders by:

//Enable Shaders
cgGLBindProgram(myCgVertexProgram);
checkForCgError("binding vertex program");
cgGLEnableProfile(myCgVertexProfile);
checkForCgError("enabling vertex profile");

cgGLBindProgram(myCgFragmentProgram);
checkForCgError("binding fragment program");
cgGLEnableProfile(myCgFragmentProfile);
checkForCgError("enabling fragment profile");

Once that is done you would go on with the rest of your draw calls and at the end of your draw loop you would disable them by:

// Disable Shaders
cgGLDisableProfile(myCgVertexProfile);
checkForCgError("disabling vertex profile");

cgGLDisableProfile(myCgFragmentProfile);
checkForCgError("disabling fragment profile");

Summary

That is pretty much a very basic description of how shaders are integrated into your C++ graphics application.

Thank you for reading,
– Moose