Homework 4 Overview
In this project you will add more realism to a high resolution model of a buddha statue, implement per-fragment lighting, shading, texturing and shadows
Homework 4 Preparation
You can get the starter code and use it to get started [ Starter Code ] .
- Understand how to load textures using the libbmpread library: In this project you will load textures in the bmp file format and use them to texture parts of your scene. The following [ Visual Studio solution ] contains a working program that reads in and displays a bmp file usain_bolt.bmp using the libbmpread library. To start off, download the Visual Studio Solution, compile it and run it. I have tested it and it works in the Zoolab.
To read in the usain_bolt.bmp file, the program uses the [ libbmpread library ] which is a tiny, fast bitmap (.bmp) image file loader. Specifically, libbmpread is implemented as two files bmpread.c and bmpread.h which have been included in the Visual Studio starter code. bmp file loading functions and data structures are then used in the starter program to load the bmp file. Study this example focusing on how the bmp files are being read in. You can also get more documentation on the libbmpread library website [ Here ] .
- You should render a Buddha statue spinning continously in the XZ plane like in a showroom. Behind the Buddha, render 2 walls and a floor. i.e. the Buddha should be hovering slightly above the floor and away from the two walls. Basically, in the figure below (right), replace the table, teapot, lamp shade and rectangular object on the floor with a Buddha statue below (left). Render the Buddha as a solid model. Apply per-fragment (Phong) lighting and smooth shading. You can get this Buddha PLY file here [ Buddha Statue PLY ]
![]()
![]()
Homework 4 Specifics
The specific features you will implement in this homework are:
- Implement a spotlight: The spotlight is like a cone and light only reaches objects inside the cone. Objects outside a certain angle, called the cutoff angle, phi, gets no light (only ambient component). Make the cutoff angle a variable that can be controlled with a keystroke
- Texture the floor plane with grass and walls with stone: Texture map some grass onto the floor of your scene to make it look like grass is growing. Use the following grass texture [ grass.bmp ] Make it look like the walls were made of stone by texturing both walls using a stone texture [ stones.bmp] Use the libbmpread library above to read in your bmp texture files. Do not try to stretch these small textures over a large floor (or walls). Map each texture to the bottom left corner of the floor (or walls) undistorted and then use the appropriate parameters to repeat the texture to cover the entire floor. The example program in Appendix A.8 on page 638 of your text gives the complete working code of a program that does texturing.
- Shadows: Implement shadows. Section 4.10 of your textbook describes a simple technique to render shadows using projection. Implement this shadow algorithm such that the shadows of the Buddha are projected onto the floor plane and walls, and updated continuously as the Buddha spins.
- Fog: Implement fog that obeys Beer's law. i.e. intensity of light diminishes exponentially with distance.
- Environment Mapping: Add in reflective and refractive environment mapping using cubemaps to your scene. The example in section 7.9 (page 393) of your text presents a complete working example of a reflection map. The class slides present how to implement refraction. Use the following cube map with its [ cube map sides in 6 images ] as your environment map. For reference purposes, the complete environment map looks like this:
Below is an example image of a cow with reflection and refraction effects. Note that your images should contain the Buddha statue NOT the cow
![]()
Summary of Your program behavior
Control your scene using the following keystrokes.Notes: No OpenGL fixed function commands (glBegin, glVertex, etc) or immediate mode drawing commands should be used in your program. All drawing should be done using shaders, retained mode, Vertex Buffer Objects, and glDrawArrays similar to the code in your textbook (and in your previous projects)
- Key A: Toggle shadows ON/OFF. When ON, the shadows show up and when OFF the shadows do not show up.
- Key B Toggle ON/OFF between a scene with grass texture on floor and stone texture on the walls and a plain wall (no texturing). When ON, the floor is textured with grass and the walls are textured with stone. when OFF the floor and walls have no texturing, displaying a gray floor and blue walls.
- Key C: Toggle reflection ON/OFF. When ON, the buddha PLY is drawn with reflection. When OFF, the buddha PLY objects is drawn with no reflection (rendered as a solid model with per-fragment lighting). Select an appropriate shininess (reflectivity) for the buddha model.
- Key D: Toggle refraction ON/OFF. When ON, the buddha PLY is drawn with refraction. When OFF, the buddha PLY file is drawn with no refraction ( rendered as a solid model with per-fragment lighting). Select an appropriate refractive index for the buddha model.
- (Key 'E'): Draw a box around each mesh showing the extents of each mesh. This keystroke should be a toggle button. If the extents box is not drawn, hitting E draws the extents box. If the extents box is already drawn, hitting E erases the extents box. Even though the mesh rotates about the Y axis, the extents box should not. It should be stationary around the mesh. If the mesh's width and length are different, you can just use the greater of the two dimensions as for your extents.
- (Key 'P'): Increase spotlight cut off angle (increase cone angle) by a small amount
- (Key 'p'): Decrease spotlight cut off angle (decrease cone angle) by a small amount
- (Key 'S'): Increase the shininess of the Buddha (specular exponent) by a small amount
- (Key 's'): Decrease the shininess of the Buddha (specular exponent) by a small amount
- (Key 'I'): Increase the index of refraction of the Buddha by a small amount
- (Key 'i'): Decrease the index of refraction of the Buddha by a small amount
- (Key 'F'): Increase the fog by a small amount
- (Key 'f'): Decrease the fog by a small amount
Submitting Your Work
Make sure to double-check that everything works before submitting. Submit all your executable and source files. Put all your work files (Visual Studio solution, OpenGL program, shaders, executable and input files into a folder and zip it. Essentially, after your project is complete, just zip the project directory created by Visual Studio. Submit your zip file using InstructAssist at [ https://ia.wpi.edu/cs543/ ] . Do not email me your program or submit it via dropbox. To make your submission smaller, delete the \ipch folder in the visual studio. On recompilation, Visual Studio will regenerate this folder without problems.
Create documentation for your program and submit it along with the project inside the zip file. Your documentation can be either a pure ASCII text or Microsoft Word file. The documentation does not have to be long. Briefly describe the structure of your program, what each file turned in contains. Explain briefly what each module does and tie in your filenames. Most importantly, give clear instructions on how to compile and run your program. MAKE SURE IT RUNS IN THE ZOOLAB before submission. Name your zip file according to the convention FirstName_lastName_hw4.zip