fragment

fragment is  a project  to understand  normal mapping,  or "Dot3  bump mapping"
The projects goal is to simulate an urban environment and enhance it with textures
that have  normal or bump  mapping.  I wrote this  program in  C++ and GLSL for
Professor  Wood's Intro  to Computer Graphics class  at Cal Poly San Luis Obispo.


normal mapping

You might ask yourself, "What exactly is "Normal Mapping"?" Its basically a technique used for
faking the lighting of bumps and dents. It is used by programs to add details without the use of
more  polygons.  A  normal  map is  usually an RGB  image that  corresponds  to the X, Y, and Z
coordinates of a surface normal from a more detailed version of the object.



















    regular image of corrugated steel                                           normal map of corrugated steel


shaders

Shaders are sets of software instructions used to calculate any rendering effects on graphics
hardware  with a high degree of  flexibility.  They are typically used to give developers more
direct control of the graphics pipline. GLSL (OpenGL Shading Language) is a shading language
that allows developers implement shaders without having to use assembly.

fragment and vertex

I jumped into this project having little to no knowledge as to how shaders functioned in Opengl.
I was quick to realize the importance of computing lighting calcuations per fragment (the needed
information for drawing a single pixel) rather than per vertex. With fragments one can change
the shading effects for each pixel on a face rather than just the face. This is crucial for Normal
Mapping. In the end I generated a GLSL vertex shader and a GLSL fragment shader to facilitate
my normal mapping. The vertex shader calculates the information gathered at each vertex, does
calculations, and passes this gathered information to a corresponding fragment shader. The
following images show what they achieve.



















            image without shaders                                                                    image with shaders


fragment

fragment is the name of my program. The name stesses the importance of computation per fragment
for realistic images. After computing my vertex and fragment shaders I decided to put them to the test
by creating an urban environment. This environment consists of 11 buildings, property walls, and a loft.
The following are images that I found during the debugging stages of my fragment shader.




















    normal maps in my environment                                                    computed light vectors





















         computed diffuse light                                                                computed specular light


 

usage

Initializing fragment loads you into the center of a 100 x 100 unit world. Initially normal mapping
is turned off and you are free to explore the environment. By pressing 'n', however, one enables
the vertex and fragment shaders responsible for normal mapping. When normal mapping is enabled
you can see how light is interacting with the faces, parapets, and roofs of buildings and property
walls. Additionally you can press 'l' to jump to the loft there one can see a moving light that is
supposed to simulate day to night.

keys

(Note: The case doesn't matter)
A - Moves to the left
S - Moves backward
D - Moves to the right
W - Moves forward
L - Moves you to the loft
R - Resets back to initialization
N - Activates Normal mapping
Q - Quits
Up Arrow - Moves the light forward
Down Arrow - Moves the light backward
Left Arrow - Moves the light to left
Right Arrow - Moves the light to the right

screen grabs

The following images show how normal mapping affects my environment.
























































































































































































































































































































































 

sources

NeHe: OpenGl Article 321/ Filter Forge- Filter Library
Wikipedia: Normal Mapping
Lighthouse 3D GLSL Turorial
oZone3d.Net Tutorials - Bump Mapping using GLSL
Bump Mapping Using CG