Assignment 7 introduced uniforms. Uniforms are constants that serve as input variables to shaders which allows us to change the shader output during runtime. This assignment required us to put multiple meshes on the screen and be able to move them around individually. To do this I created a RenderObject which encapsulates the effect, mesh and a position offset.
Uniforms allow us to modify the outputs of the vertex shader. In this assignment this lets us move a mesh on the screen. The alternative to this is to modify the vertex data, as in move ALL vertices of a mesh on the CPU and then send them to the GPU. This is very expensive when the meshes are larger. The GPU is a parallel processor. It is designed to perform the same instruction on multiple data in one step, also called SIMD. Therefore it is almost free to run a simple shader to modify many vertices at once.
Originally I wanted to refactor the system a little more, introduce a game entity and create a proxy on the Graphics side to keep the data as separate as possible. This is so that if I want to move the Render to a different thread, I want to avoid introducing dependencies between render and simulation. But alas, I didn’t have much time right now and went with compromise that works.. for now.
Screenshot of this assignment:
Controls: Arrow keys to move the rectangle. Esc to quit.