Part B (60 marks)
In this assignment you will be writing several di erent shaders in a C-like language known as the OpenGL Shading Language, or GLSL for short. A shader is program that decides the colour of each pixel rendered for an object.
Your Programming Task. Your task is to implement the following shaders. Each type of shader will be discussed in either class or tutorial to provide you with what you need to start. Figure 1 shows how the results should look like.
[10 marks] Ambient, di use, and specular lighting using the Gouraud shading model. shaders/gouraud vert.glsl, shaders/gouraud frag.glsl
[10 marks] Ambient, di use, and specular lighting using the Phong shading model. shaders/phong vert.glsl, shaders/phong frag.glsl
[10 marks] Ambient, di use, and specular lighting using the cel shading model. Cel shading is not a well-de ned term by itself, and may refer to various kinds of shading techniques emulating cartoons. You’ll implement the most basic form of cel shading by giving a posterized look to the object. shaders/cel vert.glsl, shaders/cel frag.glsl
[10 marks] UV texture mapping. With a given texture image and a model with de ned texture coordinates, you need to write the shaders to display a textured model. Note that the provided texture will only look reasonable on the sphere model.
shaders/texture vert.glsl, shaders/texture frag.glsl
[10 marks] Halftone shading. The halftone technique simulates continuous tone using a grid of dots that vary in size to depict di erent tones.
shaders/halftone vert.glsl, shaders/halftone frag.glsl
[10 marks] X-Ray shading. The opacity of the rendered fragment decreases as you move further away from the edge of the object’s silhouette, producing results that look like X-Ray images. shaders/xray vert.glsl, shaders/xray frag.glsl
Bonus [10 marks] For bonus points, you have to implement one of the following shading/mapping techniques. Points will be awarded on the basis of technical competence, creativity, ingenuity, and aesthetic appeal of the result.
Cook-Torrance re ectance model. The Phong model covered in class is not the only re ection model employed in computer graphics. The Cook-Torrance model is another common example.
Hatching. Hatching is commonly used in pencil, charcoal, and pen and ink sketches to create tonal and shading e ects. In your shader program, you can approximate tone by varying the density of linear hatching and/or the number of lines used for crosshatching. You can also try hatching in general contours, instead of straight lines.
Painterly rendering. Implement a painterly rendering technique of your choice. You can try to mimic impressionist brush strokes, water colours, knife painting techniques, coloured pencils, etc.
shaders/bonus vert.glsl, shaders/bonus frag.glsl
Helper Code. You are provided with an environment for developing shaders that runs in a modern web browser. Start by opening up a terminal window, and navigating to the folder A2. Then, type out the following command
$ python server2.py
assuming the default python installation is python2 (this is true for CDF machines), or $ python server3.py
if the default python on your machine is python3.
In any modern browser, then navigate to http://localhost:8000. You should see text boxes displaying the code of the currently selected shader, a viewer window, and UI tools to select the shader, material colours, light position, and the displayed shape (see Figure 2). The instructions are guaranteed to work on CDF machines. However, having Python and a modern browser (latest Chrome, Firefox, Edge, etc.) installed are the only requirements if you choose to run it on your own machine.
(a) Gouraud shading (b) Phong shading (c) Cel shading
(d) UV texture mapping (e) Halftone shading (f) X-ray shading
(g) Bonus shaders: Cook-Torrance model and cross-hatching
Figure 1: Sample results for the programming tasks. Note that your bonus shaders may look wildly di erent from the examples shown here and may still be deemed correct if you follow a reasonable algorithm.
Figure 2: Snapshot of the display window.
Note for Windows: The same commands will work for command prompt or PowerShell on Windows computers. Make sure that you’ve added the python installation folder to the system PATH.
You may edit the shaders by modifying the source code found in the shaders/ directory. After you’ve made a change to a shader le, press the Reload Shader Code button to load and run the new code.
Note: You should not modify any of the provided code other than the les in the shaders/ directory.
Turning in your Solution to Parts A and B. Your PDF le for part A and your submission for part B should go inside the same folder named A2 in a tgz le. All your code should remain in the directory A2/shaders. Note that this le should not be thought of as a substitute for putting detailed comments in your code. Your code should be well commented if you want to receive full (or even partial) credit for it.
To pack and submit your solution, execute the following commands from the directory containing your code (i.e., A2/shaders).
$ cd ../../
$ tar cvfz a2-solution.tgz A2
Submit your assignment using the submission script on the course website.