PROJECT 1 - CS 594 - GPU PROGRAMMING 

ARUNAN RABINDRAN


The Brick Shader Project

                                This brick shader is based on the example in Chap 6. of the Orange book with some minor changes while making the pattern look correct on a cube. The code is in C++ using OpenGL/SDL libraries to be run in linux. An object loader obj.[ch]  (www.evl.uic.edu/rlk/obj/obj.html) has been used to load objects into the scene.


A . Getting a brick pattern on a cube using GLSL.   

 Soln.: The window is created using SDL and a cube is drawn using GL_QUADS option within a glBegin() and glEnd(). The OpenGL extensions for GLSL are declared in the code as per requirement. Typical functions include glCreateProgramObjectARB() , glUseProgramObjectARB() etc. The shader programs are read into strings and are compiled within the program.

B. Fill top and bottom with mortar, make the pattern look right on the sides & avoid aliasing problems

 Soln.: Making the original code's uniform variable MCPosition a "vec3" instead of a "vec2" and including the Z co-ordinate for the computations. Similar calculations of the row and column of the bricks and smoothstepping (to avoid aliasing) over the shift from brick color to mortar color are done separately for the XY and YZ planes in the fragment shader. In the vertex shader, the normals of the top face and bottom face are identified and the position value of y is set to zero to make sure they are filled with mortar.

C. Place a toon shaded object above it and get it to spin along with the platform

  Soln. : The object used here is the bust of Venus.

(object downloaded from http://www.cis.uab.edu/info/grads/hux/Data/obj.html) . It is toon shaded using standard colors and made to spin around along with the platform.

D. A light source which can be moved using the keyboard

  Soln. : Using SDL_Event and SDL_KEYDOWN, the movement of the light has been designated. The Up/Down arrow keys move the light in the Y direction, Left/Right arrow keys move the light in the X direction and the PgUp/PgDown keys move the light in the Z direction.

E. An additional shader in the scene

  Soln. : For the floor and the Venus model, a stripes shader has been implemented. This is based on the procedural texture shader example in the Orange book, Chap. 11. Pressing the "<" and ">" keys on the keyboard will switch the shaders. The output was not the intended one on the floor. But, when the same shader was applied to the bust, a very interesting effect was observed. A kind of metal sheen was observed when the stripes shader was applied to the model of Venus after tweaking the uniform variables a bit.


CODE: 

     View

           C++ file   <brick.cpp>

           Brick Shader   <brick.vert>   <brick.frag>

           Toon Shader   <toon.vert>   <toon.frag>

           Stripes Shader  <stripes.vert>  <stripes.frag>

           Makefile   <Makefile>

     Download

  brick.tar.gz (all files required to run this project)    


ADDITIONAL FILES/LIBRARIES required :

         SDL runtime and Developmental Libraries: www.libsdl.org

         Obj.[ch]: www.evl.uic.edu/rlk/obj/obj.c     www.evl.uic.edu/rlk/obj/obj.h


SCREENSHOTS

The brick platform with the toon shaded bust of Venus.               The same model applied with the stripes shader.

 

     THE SHADER ON THE MODEL CAN BE SWITCHED USING THE   " > "   and    " < "   keys.