PlatformWin32 LanguageC++ GraphicsOpenGL/GLSL
This project represents a real-time enhanced bump mapping shader that simulates visual parallax. I developed the shader using OpenGL and GLSL. Parallax bump mapping is a modification of a standard bump mapping procedure that more effectively creates the optical illusion of a textured or irregular surface on a truly flat object. The procedure is accomplished by manipulating the texture coordinates of an object at a per-pixel level before applying the texture. The texture coordinates are manipulated in order to simulate the effect of visual parallax.
There is an inherent error that is created when applying an image of a 3-dimensional object to a 2-dimensional surface. The image that represents the real surface is flattened to fit the shape of the polygon. When the eye vector intersects the surface of the polygon, the texture coordinates at that point refer to a point directly above the polygon's surface. However, since the real surface would not be flat, the first point of intersection between the eye vector and the actual surface feature could be either closer to or farther away from the point on the polygon's surface. This shader attempts to correct this error by applying an offset to the original texture coordinates to bring them in line with the real surface intersection point.
The offset at each point is determined by using a height map that corresponds to the simulated surface in the texture map. Areas that are higher than the polygon surface will have their texture coordinates shifted one direction in the texture map, while areas that are lower than the polygon surface will have their texture coordinates shifted in the opposite direction in the texture map. The height map stores floating point values in the range from 0.0 to 1.0, so the height must first be scaled and biased to match the dimensions of the real world surface. The scale is determined by the material and represents the ratio of the surface bumps to the overall size of the surface itself. The scale and bias factors can be modified and used to customize the parallax shader to the specific material being represented.
The amount of parallax effect at each surface point is dependent upon the viewing angle and will change as the position of the viewer changes. In order to calculate the proper amount of offset, the calculations must take place with respect to the current point at a per-pixel level. This requires the use of tangent space, and all vectors and positions used in the calculation must first be converted to this coordinate system.
After calculating the perturbed normal by following a standard bump mapping procedure, the parallax mapping is calculated as follows; 1) the height map for the surface is sampled using the current texture coordinates as a look-up value, 2) the retrieved height value is then scaled and biased according to the bumped material's dimensions, 3) the view vector, which has already been converted to tangent space, is multiplied by the new height value in order to determine the offset for the texture coordinates, and 4) this offset is added to the original texture coordinates, and these new coordinates are used to texture the surface.