Objective: Use the OpenGL library along with the GLSL language to create a implementation of Tangent space normal mapping and Spotlight Projective Texture Mapping.
Initial Thoughts: Implement the spotlight first, then work back to get the tangent space mapping working correctly.
Files:
image.h && image.c &&
obj.h && obj.c &&
plane.h && plane.c &&
obj.h && obj.c &&
plane.h && plane.c &&
math3d.h && math3d.c
view.c && view.h
viewglut.c && viewglut.h
gl.h : All of the files mentioned before here are credit to Robert Kooima, each one can be considered a crucial part of the project. For more information please see http://csc.lsu.edu/~kooima/util3d/index.html
main.cpp : Main file where all the implementation of the glut functions as well as main logic is located. The program is started without the need to command line arguments.
shaderloader.h && shaderloader.cpp : This file was used in the last program but has been modified significantly in order to fully handle the shader files from compile to linking. This also has the ability to load textures from simply passing the file name. It then will generate the textures and bind them.
thirteenBoxFragmentShader2.glsl && thirteenBoxVertexShader.glsl: These are the shader files that have been implemented for the tangent space normal mapping.
Process: Now that we have explained all the files, let us explore more into depth of what is happening in the guts of the program.
As always, we start out in main with our initialization of all glut methods as well as initializing all others.
As with the last program, this program has a menu bound to the right click. (Note that the projective texture mapping spotlight is not working. After much work, I called my losses and moved on to the tangent space normal mapping of the thirteen box)
The thirteen box mapping is done as was explained to us in the description of the project. I load the textures and calculate all the bump mapping in the shaders using the "tangent" vertex attribute that is bound to the glBindAttribLocationARB(program, 6, "tangent"); which is done all before linking of the program.
The main purpose of the vertex shader in this situation is calculating the eye vector and the light vector with the tangent being taken into account.
It then comes down to the fragment shader to receive the sampler2D textures that have been bound inside the C++ code. We bind the locations then access them in the fragment shader through the uniform sampler2D api. The fragment shader then has the job of calculating the bump and all the fragment colors.
Once this is all done we must make sure to clean up after so that the texture is not projected onto any other models or anything else in the scene.
This is simply done in the format :
get uniform location;
bind program; //This is done through our shaderloader, which holds our program at all times.
use uniform api to tell shader where the textures are located;
set the active texture;
bind a texture to that active location;
render object;
unbind program; //Also done with shaderloader
The above "pseudocode" is done within our glutDrawFunc().
Unfortunately, the spotlight projection is something that I could not get accomplished. If I had to take a guess I would say that I am not taking the right approach with loading the matrices, I know that we are trying to use a sampler2Dproj and instead of using just .xy we use .xyzw.
Screenshots:
This is one of the mess up with the models, the textures show up as black and dont load, havent quite gotten to the bottom of this.
keys:
All bindings follow the viewglut.c except for panning the light.
Pan Light: ALT+CLICK