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.
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.
My updated AssetsToBuild.lua now contains the Effect Builder, VertexShaderBuilder and the FragmentShaderBuilder. The AssetToBuild.lua picture is as follows:
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)
Debug Version of Vertex Shader (Direct 3D)
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)
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:
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.
After downloading the link run Game.exe.