Assignment 3 - Draw Colorful Rectangle - Use LUA Tables and Materials
ZIP Link
Assignment3.zipWrite-Up
This assignment was labeled as "draw colorful rectangle on a black background." I am kidding a bit here, as there is more involvement than that.
We determined it takes two triangles to create a rectangle, so we used two triangles to create a rectangle, requiring us a to alter our code to include that for our triangle list and such.
We are now also going to use a Material file to load our vertex and fragment shaders. This will be explained in more detail in the Technical Write-Up.
This will also require using LUA tables to access our shader information. More of that described below.
Technical Write-Up
So, I was able to edit the current code and get it to draw a rectangle correctly.
The rectangle above is represented by four vertices which are being stored as four points. These points are shown in the image below. Each value, except (0,0), is being represented as a dot for its color as well.

The points are creating locations for the rectangle to be drawn.
The PIX software image below shows the points being drawn above.
It lists under the Events tab in the DrawIndexedPrimitive, that it is using triangles, using four vertices, and drawing two primitives (triangles). The Mesh tab and PreVS tab shows A view of what the triangle looks like, and lists the position of each vertex used.
The rendering process requires the index of vertices, and these values are passed to the vertex and fragment shaders. These shaders are used via material file, ".LUA", which is shown below. The ".MAT" was causing problems when I initially tried it. I may change it back for later builds.
The file format is set to be human readable, and has many comments to describe each section. It creates a Lua table which stores the vertex and fragment shaders paths. These are then used to create the material used for rendering via graphics code.
Please note, my Lua table uses specific names to find the vertex shader and fragment shader. If a new file is used, you may have define the variables being searched for as "vertexShader" and "fragmentShader".
Realized Learning Moments
When testing the project "UsingTables_inC"it wouldn't run properly. It took a long time for me to alternate the Debugging code to run out of "GameDir" not "ProjectDir". That fixed a few hours of feeling stupid, and let me review the actual code and follow it in Debug mode.
I was very confused by the location/access of this material file. It had to exist in the Authored Assets Directory, but be transferred to the Built Assets Directory. This would allow them to be accessible by the executable file. This would be included with the shader files. Trying to wrap my head around this concept didn't initially make sense.
The correct include method for both the LuaLib and it's .HPP file were difficult. Google searches helped fix the issue, for a library to use another library.
As far as the code that had to be edited for accessing the Lua Table of shader information, I used the accessing string format example, and it had a weird scoping issue. I had to place brackets around the function call, which fixed it. I will be looking into changing this back as well.
Time Used
Reading: 4 hours
Write-Up: 1 hour
Technical Write-Up: 2 hour
Coding: 5 hours (Ran into errors while testing example code - I included this as "Coding")



No comments:
Post a Comment