From Immersive Visualization Lab Wiki
Revision as of 13:48, 2 November 2018 by Jschulze (Talk | contribs)

Jump to: navigation, search


Project 3: Textures, Scene Graphs and Culling

In this project you will need to implement a scene graph to render an army of animated robots with textures on them.

The total score for this project is 100 points. Additionally, you can obtain up to 10 points of extra credit.

We recommend the following approach for the timing of your work:

  1. You can start with part 1 immediately: We've already covered texturing in class, and will cover its implementation in discussion on Oct 24.
  2. Parts 2-4 require a scene graph. It will be covered in the lecture on Oct 23.
  3. Part 5 (Culling) will be covered in lecture on Oct 30 and also in discussion on Oct 31.

1. Textured Robot Torso (30 Points)

The first step of the project is to create a textured robot torso, which you will later use as part of your robot.

Start with code that uses your trackball code, and modify it so that trackball rotations control the camera instead, so that trackball rotations control the camera's direction vector - the camera stays in place. (If you don't have trackball rotation code, keyboard controls will suffice.)

Thanks to our tutors Weichen and former tutor Yining, you have the following robot parts to choose from: head, body (torso), limb, eye, antenna. You will find the OBJ files in this ZIP file. Each vertex has not only a 3D coordinate and a normal associated with it, but also a texture coordinate. This allows you to map textures to the surfaces of the robot. Note that unlike the previous obj files in the course, each face has different indices for v/vt/vn. So you are going to need to update your parser accordingly, when you add texture support. (You many want to check Wikipedia for more information about *.obj format) One of ways to deal with the different indices is to re-order (and duplicate) the v/vt/vn data when parsing so that their indices align. The following code might be helpful:

// Assume that you parse indices of v/vt/vn into different std::vector (vertex_indices_, normal_indices_, uv_indices_)
// input_vertices, input_normals, input_uvs are raw input data from *.obj files
// vertices_, normals_, uvs_ are aligned data

for (unsigned i = 0; i < vertex_indices_.size(); i++) {

Load in the robot body with its texture coordinates. Then apply a texture to it. You can use any (non-offensive) image you find on the internet, or use a picture from your own collection. Best is to trim and resize the image to a size of 512x512 pixels.

Load the image into your C++ code. We provide sample code which loads a PPM image file and uses it as a texture for a quad. If you decide to use an image in a format other than PPM (eg, JPEG), you need to convert it to PPM first. The above mentioned image processing tool IrfanView for Windows will do this for you. Alternatively, you can use a third party library such as SOIL to natively load JPEG images, or other image formats.


  • -3 if texture is not entirely correctly rendered, ie. skewed or stretched

2. Scene Graph Engine (15 Points)

To create a robot with multiple moving body parts (head, torso, limbs, eyes, antennae), we need to first implement a simple scene graph structure for our rendering engine. This scene graph should consist of at least three nodes (5 points for each): Node, Transform and Geometry. You are free to add more scene graph node types as you see fit.

  • Class Node should be abstract and serve as the common base class. It should implement the following class methods:
    • an abstract draw method: virtual void draw(Matrix4 C)=0
    • an abstract virtual void update()=0 method to separate bounding sphere updates from rendering
  • Transform should be derived from Node and have the following features:
    • store a 4x4 transformation matrix M
    • store a list of pointers to child nodes (std::list<Node*>)
    • provide a class methods to add a child node (addChild()) to the list
    • its draw method needs to traverse the list of children and call each child node's draw function
    • when draw(C) is called, multiply matrix M with matrix C.
  • Geometry should be derived from Node and have the following features:
    • set the modelview matrix to the current C matrix
    • an initialization method to load a 3D model (OBJ file) whose filename is passed to it (init(string filename). Your OBJ loader from project 2 should work.
    • have a class method which draws the 3D model associated with this node.

3. Walking Android Robot (20 Points)

Now that we have the scene graph classes, it is time to put them to work. Build your own robot using the addChild methods. Use at least 3 different types of parts for your robot (e.g., body, head and limb). In total, your robot needs to consist of at least 4 parts, 3 of which need to be moving independently from one another and they need to be connected to the 4th part. One of the robot parts needs to be the textured torso which you created in part 1 of the project.

Here is an example of a robot with two antennas, two eyeballs, one head, one torso and 4 limbs (2 legs and 2 arms), before applying a texture:


Use your creativity to build the most creative robot in class! The 5 most creative robots in class are going to get extra credit, after a vote on Piazza.

Once you've created your scene graph, you need to get your rendering engine ready to recursively traverse the scene graph for rendering by creating a root node of type Transform and calling its draw() function with the identity matrix as its parameter.

Animate the robot to make it look like it is walking, by changing the matrices in the Transform nodes. Walking in place is fine, the robot does not need to actually move forward.

4. Robot Army (15 Points)

Construct a scene which consists of a large amount of robots, at least 100. The robots can all be identical clones.

  • Distribute the robots on a 2D grid (i.e., place them on a plane with uniform spacing). For 100 robots, use a 10x10 grid.
  • Enable the animation for all the robots so that they look like they are walking.
  • Enable your rotation and scale routines (keyboard or mouse) to allow rotating the grid of 3D objects and zoom in or out.

This image illustrates the grid layout of the robots (background image not required):


5. Culling (20 Points)

Implement object level culling, to allow the existence of thousands of instances of your robot, without having to render them all at once.

Determine the parameters for a bounding sphere (Vector3 for its center point, and a radius) for each of your robots, which contains all parts of the robot. Add an option to toggle the rendering of the bounding spheres on or off with a keyboard key. You can render the spheres by using the sphere OBJ from project 2. Other ways of rendering spheres are also acceptable. (5 points)

Notes: You do not need to find the tightest possible bounding spheres. Just make them as tight as you reasonably can. Estimating the bounding sphere size is fine. You don't need to have a separate bounding sphere for each animation step - one that encloses all steps is fine.

Add view frustum culling using the bounding spheres of the objects. If the bounding sphere of an object is completely outside of the view frustum, the object should be culled (not rendered). Your culling algorithm should make use of a utility function to test whether a bounding sphere intersects with a given plane (the planes of the view frustum), or whether the sphere is entirely on one side of the plane. Enable a keyboard key to turn culling on and off. (10 points)

Increase the amount of robots by orders of magnitude, by creating a larger array of them. A good portion of the array should be off screen for the culling to be effective. Display the number of robots that are visible in your text window (standard out), and make sure that by turning culling on this number goes down when part of the robot army is off screen. (5 points)


  • Lighthouse3D has an excellent description of how to calculate the view frustum plane equations.

6. Extra Credit (Up to 10 Points)

  • Debug Mode: Implement a demo mode in which you zoom the camera out (increase the FOV by a few degrees) but do the culling with the original FOV, so that one can see when the robots get culled. Allow toggling between demo mode and normal mode with a keyboard key. (5 points)
  • Hierarchical Culling: Create a hierarchical culling algorithm by storing bounding sphere information at every level of the scene graph, so that you can cull an entire branch of the scene graph at once. Structure your scene graph so that you have multiple levels (for instance, by subdividing your army into four quarters, and create a node above each quarter army. Show how many times you were able to cull based on the higher level bounding spheres by displaying the number in the text window. Use differently colored spheres for the different levels of your culling hierarchy. (5 points)

7. Creativity Contest (Up to 5 Points)

We're going to have a contest for the top 5 most creative robot creations. Submit a JPEG image or GIF animation of your robot to Piazza by the deadline of the homework project (2pm Friday 11/2). Instructions will be posted on Piazza. To create a GIF animation you can use this converter. To convert any image file format to a GIF image, we recommend IrfanView. The top five most voted for robots are going to get extra credit.

The winner of the contest will get 5 points of extra credit. The second will get 4 points, third gets 3, fourth 2, fifth 1 point. This extra credit is on top of the regular extra credit so one can theoretically get 115 points for this homework project.