Game Engineering || – EAE 6320 – Assignment_08

The main objective of this assignment is to create builders for loading the binary shaders and effects during runtime. So to achieve this we had to create Effect Builder and Shader Builders .

The Effect Builder basically generates a binary format of an asset file . I have named the asset file effect.lua . The effect.lua basically contains the path of the shader file which is the for the vertex and the fragment shader.

For the Shader Builder I have created two shader builders which is VertexShaderBuilder and FragmentShaderBuilder. So I went with the option of creating two shader builders because it was less time consuming option at the time . The job of the shader builder is to generate the binary format of the compiled shader depending on the OpenGl or Direct3D platform.

My effect file format looks like the picture below and contains the path of the shaders.

bandicam 2015-11-02 12-50-55-728

So basically we just add a NULL character at the end of the fragment shader path and vertex shader path when we write to the binary file . I find this better than counting the characters everytime the path gets updated. You can spot the two null characters which look like “00” in the image below which show the Null characters at the end of both the shaders . On the right hand side you can see the path which is readable.

bandicam 2015-11-02 12-54-50-320

My updated AssetsToBuild.lua now contains the Effect Builder, VertexShaderBuilder and the FragmentShaderBuilder. The AssetToBuild.lua picture is as follows:

bandicam 2015-11-02 13-35-48-601

The release and debug version of the vertex shader for Direct 3D are shown below. You can see that the Debug Version of the Vertex Shader is a lot bigger than the Release version . This is because it contains some unnecessary information such a o_color, o_position etc . The release version is a lot shorter as it contains only the important necessary information for running the game.

Release Version of Vertex Shader (Direct 3D)

bandicam 2015-11-02 13-11-21-821

Debug Version of Vertex Shader (Direct 3D)

bandicam 2015-11-02 13-11-33-580

As you see in the picture below the Release Version of Vertex Shader for OpenGL basically has the Direct 3D part stripped off from the Vertex Shader and the comments are removed. Again the reason for comments to be removed is to reduce the file size.

Release Version of Vertex Shader (OpenGL)

bandicam 2015-11-02 13-20-57-053

In this assignment I ran up with a weird bug which was causing some
random patterns for the Direct 3D Release Output. I was not able to figure out what was causing the problem. But after debugging the problem with John Paul we figured that I had made some rookie mistakes and we found some hardcoded values for Direct3D platform which were causing the problem, that I had forgotten to update after reading the binary mesh file . But it was good that we fixed those problems, otherwise they would lead to more problems when doing 3D in the future assignments . So I was able to get those bugs sorted out. The bug looked like the image below:
bandicam 2015-11-02 15-56-06-406

Time taken for assignment was 15 hours. The assignment was not hard but it took some solving the weird bug .

You can download the Zip File of Assignment_08 from the following link to get the square output. Use the arrow keys to move the red square.

Direct3D_Release_08

After downloading the link run Game.exe.

Semester 3 Thesis – 5

So we are close to the IGF deadline and my task is currently to work on the particle effects. So basically when the wand magic effect or the arrow will hit the collider or the obstacle I need to generate or instantiate a hit effect.

 

So you can see the above video to get an idea of the effects that we will use for the hit effects. So for now I am going to use one of the effects from the pack and then we will see how it looks during the gameplay testing.

Semester 3 Thesis – 4

To give an update on the sound the effects are working great. The transition from the one area to another is sounding good.

So i have scripted and designed an audio system that works on trigger boxes, audio mixers and sound interpolation. As soon as the blind player comes close to the beach part our island he starts to hear the sound of ocean waves which progressively increases as he moves closer to the water. This is done using the logarithmic roll off of the sound. So the script detects the player’s position relative to certain audio sources using Vector3.Distance() and then the logarithmic interpolation of sound takes places. If the blind player is in the valley he hears the wind gushing which gives him a perception that he is in a valley or mountain environment. At one point the player can hear two or more audio sources depending on his location. If he just enters the forest area from the beach then he can hear the birds but he can also ear a bit of the ocean waves which gives him feedback that he is leaving the beach are and entering the forest.

Programming this was tricky at certain areas since I had to program distortion when the audio source was on the other side of a barrier like a hill. So if the sound source was coming from the other side of the hill, the script will first detect the barrier and introduce an audio occlusion in the sound. This is again to give a sense of perception to the blind player that there is a barrier in the middle.

So i had to include the audio occlusion for the following scenario:

Sound_diffraction_paths

Game Engineering || – EAE 6320 – Assignment_07

The main focus of this assignment is to move the red square or rectangle game object on the screen through the keyboard input. For the Input movement I used John Pauls code for Input Controls

bool UpdateEntities_vector()

This particular function uses the cVector from the Math library which was provided . So I just added the Time and Math as existing project.

So the red square gameobject moves on the screen using the arrow keys. The following images show the red square movement by using arrow keys.
bandicam 2015-10-20 16-08-46-774
bandicam 2015-10-20 16-08-56-874 bandicam 2015-10-20 16-08-58-600

 

To move the rectangle on the screen we can either update the vertex data or we can update the uniforms. The first method is not favorable as discussed in class because we have to update the vertex data every frame. So locking updating and unlocking the buffer is not an optimized way and so we use the method of updating the uniforms. Uniforms remain constant through one frame so it is more optimized.So we are simply modifying vertex shader to take a variable and modify the offset of the mesh.

Basically the triangle 1 on the left and triangle 2 on the right share the same mesh . So if you modify the mesh file it should be reflected on both.We also need to render a rectangle. So I now have a total of three game objects. Probably using a list in the future would be better.

It took me around 17 hours to finish this assignment because I made a couple of structural changes which added unnecessary complexity and so it took longer to complete. Its probably better to have a list of GameObjects in the future as we will have more of them,

You can download the Zip File of Assignment_07 from the following link to get the square output. Use the arrow keys to move the red square.

Direct3D_Release_07

After downloading the link run Game.exe.

Semester 3 Thesis – 3

So now that I am done with the wand system, I need to work on the sound AI.

Since our game involves binaural audio, programming the audio AI is crucial for the game as we figured during the team meeting. Since the blind person has no visual cue about what is happening in the environment, it was important to script the sound events which have environment sounds in order to paint the visual image of the environment.

For now I am going to arrange the different sound audio source and do the research of audio mixers. After getting an idea of that I will basically script the behavior to interpolate between the sound sources.

Some good examples that I have come across are while playing witcher the environment sounds have a good mix . I like the behavior when the sound changes during danger events. Will try to incorporate that in the game.

Semester 3 Thesis – 2

This is the update after two weeks for the electric beam effect . It looks great so far and I am happy with the results. There are a few bugs that need fixing though. It looks like the video shown below .

Looks like the picture I had posted of dragon age. It is yet in buggy state. The beam should destroy a bit faster and there seems to be a lag between the current position and the previous position. Will need to do some more research on that but it looks great so far.

Game Engineering || – EAE 6320 – Assignment_06

The main objective of this assignment is to create a binary version of our human readable mesh file. The reason we are doing this because this reduces the file size and significantly improves the runtime loading.

We have to make a couple of changes to the Mesh file . We basically have to move the code which reads the Lua file and migrate it from the Graphics project to the MeshBuilder. The reason we do this is so that the builder can covert the lua mesh file to the binary file.

bandicam 2015-10-06 11-07-31-514

The above image shows the binary file in a hex reader. The structure is the same as we discussed in the lecture. The first 4 bytes have the number of vertices. The next 4 bytes have the vertices. The next 12 bytes are the vertex struct and after that is the indices array.
The size of the binary is only 80 bytes which is significantly lower than the file of the mesh file which is 346 bytes .

The important thing to note and take care of is that the number of vertices needs to come before the vertices or in the other words the number of elements in an array must come before the array. The is because we need to know the number of elements to read before we actually start reading the elements. This is done so that there is clarity in the type of data that we are reading and also the number of elements that we are reading.

The following image shows the way I extract the information from the Binary File :-

bandicam 2015-10-06 12-00-18-570

The 3 advantages of the binary file format are:
1) Like I mentioned in the start , the reason we are converting the lua to binary file to reduce the file size which improves the runtime loading since no parsing is needed after loading the data from the file.

2)The file size of the binary is significantly lower than the lua file which is only 80 bytes as compared to 356 bytes of the lua file.

3) Another advantage is that we only need to order the data correctly in the corresponding memory blocks and read them in the read them in that correct order.

The binary have significant advantages as discussed above but they are hard to decipher and the lua mesh file are undoubtedly the better human readable formats. So it is better to keep them especially during debugging situations.

The next part of the assignment was to encapsulate the shader’s into the GraphicEffects class like we did for the case of Mesh in order to make it platform independent. I made the structure similar to the Mesh file structure.

Overall the assignment took me around 10 hours to complete . I learnt a lot about binary files and their purpose while working on this assignment. It was fun to finally understand and decipher the binary files which were a complete mystery to me before. I also read the email regarding the project dependencies and I have made changes to the project dependencies.

You can download the Zip File of Assignment_05 from the following link to get the square output.

Direct3D_Release_06

After downloading the link run Game.exe.

Game Engineering || – EAE 6320 – Assignment_05

The main objective of this assignment is to add the Assets as well as the Shaders from the lua file called AssetsToBuild.lua rather than adding them in the custom build step.

So instead of adding the individual shader files and the mesh files in the custom build step of the BuildAssets.lua and adding it in the command line  we just add “$(BinDir)AssetBuilder.exe”.
The “AssetsToBuild.lua” file basically contains information like the building tool , the source and the destination path that will be used. The main advantage of this process is that it makes it simpler and sleek to add new mesh files. So we only need to worry about editing the mesh files and we do not need to be concerned about adding it in the custom build step properties.

Screenshot for assignment_05

The following is the picture shows me debugging the MeshBuilder .

Debug Pic

So my new BuildAssets and AssetsToBuild lua files reside in the Scripts in the Solution . I have decided to keep all them in Scripts so next if I have to change the source or target or add shader and mesh files it is convenient for me to change and remember where to change it which is in the scripts.

lua file 05 pic

So the following picture shows my Custom Build Step . As you can see there is more clarity in the Command Line than before since we do not need the individual shaders and assets like before.

custom build pic

Here are the pic of the project dependencies that I have set .

AssetsBuilder pics

The following shows the project dependency for BuildAssets.

BuildAssets

 

The AssetBuilder depends on the BuilderHelper,Lua,Generic Builder,MeshBuilder and Windows. The AssetBuilder depends on the BuilderHelper for all the utility functions .  I have made the BuildAssets to depend on all the builders since it is using the builders to build the assets which are in the AssetsToBuild.lua file.

Overall this assignment was better than the last one . It took me 10 hours to finish it . Since I spent more time on the last assignment to structure the code it was easier to integrate the Builders on this assignment.

You can download the Zip File of Assignment_05 from the following link to get the square output.

Direct3d_Release_05

After downloading the link run Game.exe.

 

Game Engineering || – EAE 6320 – Assignment_04

The main goal of Assignment_04 was to combine the 4 shader’s which were the 2 for hlsl and 2 for glsl and make them into two shader’s  by using the the platform specific preprocessors and also to structure and read the vertex/index data from the lua file.

I decided to name the two new shaders as vertex.shader and fragment.shader. This is because the names are clear and easy to understand and identify making it easily readible. So basically instead of writing two separate hlsl and glsl shaders for Direct3d and OpenGl, we combine both the vertex shaders into one shader file called vertex.shader and we combine both the fragment shaders into one shader file called fragment.shader. We separate the platform specific code by using the platform specific preprocessor macros for Direct3D and OpenGL.

We also had to make the corresponding changes in the BuildAsset properties in the custom build step.  We also had to make the appropriate changes in the Graphics.gl.cpp and Graphics.d3d.cpp.

bandicam 2015-09-22 15-23-37-923
My mesh file picture is shown as follows:
The name of my mesh file is rectangle.mesh . I am choosing this name as it suggests that it a mesh which contains the shape of a rectangle. I will mostly be naming my mesh files based on the shape.

It starts off with the return statement. I am creating an array of vertices vertices and indices. For each vertex there is a position and a color. This is indicated by “pos” and “color” in the lua file which is quite clear and human readable. For the position we have the x and the y co-ordinates which is why you can see two values for each pos. For the color of each vertex I have 4 values which indicate red,blue,green and alpha . The reason I passed 4 values including the alpha is so it gives me an extra option to adjust the opacity. I think this format was like the one we discussed in class and its easy for me for understand and  integrate with C++.

final

 

As far as the winding order goes I chose to use the order which Maya uses. As far as the discussion in class I was convinced and find the OpenGL(anti-clockwise) winding order a better option since Maya also uses the same format, so it will be easier to visualize it if I need to debug it.

As I already mentioned I chose to use 4 values for the colors which represent red,blue,green and alpha. I think every artist and engineer is familiar with RGBA values and it also allows me to tweak the opacity in the lua file which I why I am choosing

The extension I chose is a .mesh file because it represents a mesh and the convention that I am planning to stick to is to name the mesh depending on the shape. Since our mesh represents a rectangle shape I am choosing to give it a name rectangle.mesh.

I never though that names used in the mesh file was so important and I was convinced by the discussion in the class that it is important to make it human readable. I think the simplicity is the ultimate form of sophistication. Any mesh file which is easily readable and clear will look as though the person has given a good thought process behind the design. It is also important to consider what you feel is comfortable and readable for yourself. Also in future I feel that for the vertex we only need to use x,y or x,y,z  position and the color but this thought may change. There are other things like normals which we might need to calculate for lighting but it is mostly used for computations and may not be required to be passed to the lua file. So its better to keep it as simple as possible.

Overall this assignment took me around 20 hours to complete. Making changes to the shader and making the lua File were relatively simple and took me around 3 hours. But integrating the lua file with C++ took a lot of time for me. OpenGL part was relatively easier for me. But Direct3D was challenging which required a lot of debugging for me and watching the values on which I had to spend a couple of hours. This assignment was pretty challenging but I learnt a lot.

You can download the Zip File of Assignment_04 from the following link to get the square output.

Direct3d_Release_04

After downloading the link run Game.exe.

Game Engineering || – EAE 6320 – Assignment_03

The main objective of this assignment is to create a vertex buffer to store the unique vertices of any shape and create an index buffer which depicts how the vertices are connected to each other thereby reusing the vertices . The reason we separate the vertex and theindex data is for efficiency reasons. The vertex is basically a struct of two floats and we use uint8_t to store the color. So it is a lot heavier than an index. An index is a GLUint for OpenGl which is quite light. And so we we are ultimately passing smaller data to the GPU thereby improving the efficiency. We are also storing only the unique vertices and passing only 4 vertices in the draw call rather than passing 6 vertices as we did in the last assignment.

assignment_03

Since we are only storing the unique vertices the total number of vertices that were used to make the square were 4 and the the total number of indices used in this square were 6. So basically we store the vertices in the vertex buffer and the indices in the index buffer . These indices in the index buffer refer to the vertices in the vertex buffer in the the order (clockwise for Direct3d / anti-clockwise for OpenGL) they would be used to draw the triangle.

So as I mentioned above the advantage of splitting the vertex into vertex buffer and index buffer is that we need to store only the unique vertices for each shape and we can use the index buffer which is much lighter than the vertex structure to depict how the vertices are connecting to each other. Due to this we can reuse the vertices and we do not need to include again them for a particular shape like we did in the earlier assignment. Hence we are passing smaller data to the GPU for the draw call and so it is better optimized.

So for the Mesh system I decided to create a struct and I decided to make it a part of the Graphics class . The reason I decided to put it in Graphics is because my Mesh contains Graphics specific data for OpenGl and Direct3d which is appropriately selected using the preprocessor  macros depending on the configuration selected. Also I have my sVertex struct in Mesh which contains two floats for x and y and a uint8_ts for the color hence it only makes sense to place the mesh in the Graphics Engine because it contains the Graphics specific data.

The reason why it is better to have a shared interface for different platforms which have a different style of implementation is that you can write common code for both the platforms and you don’t have to worry about difference between the different platform specific code. Hence it allows you to write common code for both the platforms .

So I made two parameterized constructors for Mesh which are platform specific . I am passing the 3 pointers for Direct3D in the parameterized  constructor and one for OpenGL .

The declaration of my DrawMesh function looks like
void DrawMesh().
It is called on both both the platforms as s_Mesh->DrawMesh();

The way I create pointer “s_Mesh” for Direct3D and OpenGL is as follows and give it NULL reference :
eae6320::Graphics::Mesh *s_Mesh = NULL;
Then I use s_Mesh to call the parameterized constructors for both the platforms and also get the device for the case of Direct3D. And ultimately I call the DrawMesh() function.

So as we discussed a couple of methods in class like globals, parameterized constructor and context, I was currently using the method of the parameterized constructor.

So it took me 12 hours to work on the assignment . Going through the reading material took me 2 hours . Implementing the colored square via Vertex and Index Buffer took me around 2 hours. I took the remaining time to finish the single interface for drawing Mesh.

You can download the Zip File of Assignment_03 from the following link to get the square output.

Direct3d_Release_03
After downloading the link run Game.exe.