Out: Oct 21. Due: Nov 4.
In your second assignment, you will create a simple OpenGL renderer on the GPU. While GPU rendering is not as faithful as raytracing, it is extremely efficient and used everywhere from laptops to cellphones and even web browsers. While you will not create a complex renderer, your code will introduce you to the practice of working interactively with GPUs.
You are to perform this assignment using C++. To ease your development, we are providing a simple C++ framework to represent the scene, perform basic mathematical calculations, and save your image results. The framework also contain simple test scenes to judge the correctness of your algorithm. These test scenes are build straight into the app. Just running the application will render the test scenes included, that you can compare to the correct output images we supply. To build the framework, you can use either Visual Studio 2013 RC on Windows or XCode 5 on OS X. We will use external libraries to help us interact with the system, including GLFW for window management and GLEW to simply access to OpenGL on Windows.
We suggest you use our framework to create your renderer. We have removed from the code all the function implementations your will need to provide, but we have left the function declarations which can aid you in planning your solution. All code in the framework is documented, so please read the documentation for further information. Following is a brief description of the content of the framework.
In this homework, scenes are simple. A
Scene is comprised of a
Camera, a list of
Meshes and a list of
Camera is defined by its frame, the size and distance of the image plane and the focus distance (used for interaction). Each
Mesh is a collection of triangles and quads, centered with respect to its frame, and colored according to a Blinn-Phong
Material with diffuse, specular coefficients. Each
Mesh is represented as an indexed polygonal mesh, with vertex position normals and texture coordinates (for now, please ignore this last vector). Each
Light is a point light centered with respect to its frame and with given intensity. The scene also includes the background color, the ambient illumination, the image resolution and the samples per pixel.
In this homework, model geometry is read from RAW files. This is a trivial file format we built for the course to make parsing trivial in C++. This geometry is stored in the
We provide very simple interaction for your viewer. Clicking and moving the mouse lets you rotate the model. You can switch between models using
] and save all images for the models with
s. If you want to save, please restart the program to avoid issues.
You are to implement the code left blank in
shader_fragment.glsl, to implement the following features.
Initialize OpenGL shaders (
shade.cpp#init_shaders). Initialize OpenGL shaders from code files and check that they compile and link.
Draw surfaces with OpenGL (
shade.cpp#shade). Bind uniform variables and vertex attrobutes to the shaders to draw all geometry.
Project vertex positions (
shader_vertex.glsl). Project vertex position to the screen to form shapes. Also pass world-space position and normals to the fragment shader.
Compute fragment colors (
shader_fragment.glsl). Compute fragment colors by implementing ambient light and Blinn-Phong shading with points lights.
OpenGL/GLSL is a large API for programming interactive graphics applications. It is used on all platforms making it the lingua franca of interactive graphics. It is a large API with a design comprised by backwards compatibility. Furthermore, changes to the API in recent years make writing code and getting help from the web cumbersome. To try to be as compatible as possible, we use OpenGL 2.1 / GLSL 1.20, an old version that should run on all desktops and laptops today.
We strongly suggest that you follow the tutorial given in the lecture notes rather than attempting to learn all the API. You are not the learn all of it, in fact you should learn the smallest amount possible. The idea is to give you a gentle introduction to OpenGL and make you understand the interplay between CPU/C++ and GPU/GLSL. For OpenGL/GLSL documentation seach the web, especially at www.khronos.org/.
We suggest to implement the renderer following the steps presented above. Start simple, by just passing vertex attributes, mesh frame and camera inverse frame and projection. Then pass the vertex attributes to the shader and draw triangles and quads. Modify the vertex shader to compute the proper project of the mesh vertex positions. You should now see a white image with proper shape silhouttes. Now, go ahead and get lighting right by passing the other params and getting the fragment shader right.
This time scenes are slightly more complex and loaded each time at start up. To speed up debugging, you should comment out the complex scenes. As a rule of thumb, the larger scenes are last.
Please upload your code as well as the images generated as a .zip file on moodle.