Sunday, October 28, 2012

Project 2

Objective: Create an openGL implentation that will load GLSL shader files as well as wavefront(.obj) files and apply them appropriately.

As with the first project, C++ will be used mostly with much more C this time around.

Thoughts: It seems as if we could come up with a solution that will load the files that we want from a menu that we can create through openGL, rather than load them from the command line which would create a hassle when it comes time to switch out models or shader files. 

Like with the first project, all the code can be found on my public Github repository located at:  

https://github.com/popasquat89/ME4573.git

The files contained within the project include:

image.h && image.c && 
obj.h && obj.c &&
plane.h && plane.c && 
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

shaderloader.h && shaderloader.cpp: The shader loader was built to load in the different shader files, whether those be vertex or fragment. 

main.cpp - Main file of the program, implementing all glutMethods which are declared as prototypes at the top. Also accomplishes much more which will be explained more in detail below.

brick_fragment.glsl && brick_vertex.glsl: These two shader files are combined to create a brick look on all loaded objects.

colors_animation_fragment.glsl: This fragment will create a speaker that will hop and bounce around, very cool effect.

flatten_fragment.glsl && flatten_vertex.glsl: This will simply flatten out the model while having a color changing effect depending on where the user is viewing from.

wave_fragment.glsl && wave_vertex.glsl: This will create a wave effect on all models that are being rendered.


Process: Now that we have explained what each file is used for, let us now go more in depth and explain the process behind all of these files and how they are linked together.


Like any other program, we start out in main, where we will initialize all of our glut methods that will do the work we assign to their method.

By default, the program will start off with the jet being loaded and the plane being rendered. If one should want to change what model is being loaded, or if they would like to stop displaying all models, they would right click and use the "Swap Models" option which will give them any option they should desire.



The way that I have accomplished this is through case statements in the display function. Should a user want to choose a model a scenario is assigned to the scenario variable with 4 different flavors.

The plane is same concept but since it is manipulated on its own, a simple bool sufficed in order to tell the function to render the plane or not.

Shader Process:

When the user decides that he or she should want to apply a shader program the models, it is just as simple as the previous step. The user should right click and choose which program they would like to run.




The way that this is accomplished is through the proper use of case statements through the openGL menu that one can build. Once a user clicks on the shader program, it is sent to a case statement which will load the proper files needed for the program through the use of the createProgram() method. 

The createProgram() method is responsible for all of the following:

  • Creating an instance of ShaderLoader and loading the file in.
  • Compiling the Shader files
  • Calling checkCompilationStatus() to check for errors on the compile.
  • Linking the Shader files to the program;
  • Returning the program.
One all of this has been done, it is as simple as calling glUseProgram() and retrieving all the Uniform Variables from the Shader Program.

Once the program is being used, a couple of the Shader Programs have it to where we can adjust certain values that belong to them. We will explore this greater in detail soon enough.

Should the user want to stop displaying the Shader Programs, I have built in the option to reset everything to its default state. This can be done by Right Clicking, then selecting the "Reset" option.





As I change gears into explaining the Shader Programs more in depth, I would like to first explain a key method in this program which has been set up as a timer for a couple of the Shader's.

In the idle function, you may notice that I have used the <time.h> in order to update my timeFactor variable which plays a key part in the functions that rely on time. The code is very obvious for the timer, but what you may also notice is the part where I have used if statements in order to see which shader is being run and update that time variable specifically. This is very important, as multiple shaders use this variable, without it, they would not be moving ever.

Lets now look into each shader specifically, excluding the ones that were included in class. (Brick and Wave)

The colors_animation_fragment is a boombox that will jump around from time to time updating with the timeFactor variable and the mouse function. The basics of this fragment are not basic at all, it was downloaded off of a heroku GLSL sandbox and is quite complex. I will try to explain as best as possible. 

The first thing that has to happen is the drawing of the figure itself which is done with float vectors as well as using functions like pi which is defined at the top. Once we are drawn, it comes down to the time as well as beat function which is controlled by time. 

toon_fragment && toon_vertex: This is another downloaded that is pretty simple. The vertex file will calculate the normal that is declared as a global variable for both the fragment and vertex, then transform the position. Then the fragment file has the job of coming up with the colors and the intensity of those colors. 

flatten_fragment && flatten_vertex: These are two that will combine to flatten the objects that are currently loaded and make them look wavy. The vertex does the manipulation of the object by multiplying the Z coordinate of the gl_vertex by a special sine function. The fragment will give the flattened object a different look when the user changes the camera around.


ScreenShots: 









Keys:

"w" : Move forward
"s" : Move backwards
"a" : Move left
"d" : Move right
" " : Move up
"c": Move down

CONTROL+MOUSE: Move Spotlight
SHIFT+MOUSE: ZOOM 

/* Only for when Brick Shader is active */
"h": Change brick color - add
"u": Change brick color - subtract


/* Only for the Shader's relying on time */
"i" : Increase time added to timer
"k" : Decrease time added to timer
"j" : Increase time frequency
"l" : Decrease time frequency










No comments:

Post a Comment