Project6F15

From Immersive Visualization Lab Wiki
Revision as of 23:56, 6 November 2015 by Jschulze (Talk | contribs)

Jump to: navigation, search

Contents

Project 6: Flag

This project covers textures, Bezier patches, and simple GLSL shaders. The goal is to create a sky box, populate it with a Bezier patch that looks like a flag, and render the flag with a shader.

It is due on Friday, November 13th at 2:00pm and will be discussed on Monday, November 9th.

1. Sky Box (30 Points)

Create a sky box for your scene with a flag. A sky box is a large, square box which is drawn around your entire scene. The inside walls of the box have pictures of a sky and a horizon. Sky boxes are typically cubic, which means that they consist of six square textures for the six sides of a cube. Here is is a nice collection of textures for sky boxes.

Draw a cubic sky box and make it big enough to exceed the size of the viewing pyramid.

Make sure single-sided rendering (triangle culling) is enabled with these lines somewhere in your code to ensure that you will never see the outside of the box:

glEnable(GL_CULL_FACE); 
glCullFace(GL_BACK); 

Use the following settings for your texture after your first glBindTexture for correct lighting and filtering settings:

  // Make sure no bytes are padded:
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

  // Select GL_MODULATE to mix texture with polygon color for shading:
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

  // Use bilinear interpolation:
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

To familiarize yourself with texture mapping in OpenGL, we provide a sample program, which loads a PPM file and uses it as a texture for a quad. If you decide to use one of the above referenced sky box images, you will have to convert them from JPEG to PPM format. The free 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.

2. Flag (40 Points)

Generate the 16 control points for a cubic Bezier patch. Put them all in the x-y plane (vertical), since the patch is going to simulate a flag.

Tessellate the patch out of GL_QUADS: use uniform sampling to calculate 3D points on your patch on a regular grid. We suggest using around 100x100 quads to produce a smooth surface.

Connect the points with GL_QUADS in counter-clockwise order to form a surface, and calculate normals. Make the quads white and give them material properties of your choice.

Tip: You can compute normals as follows: Given the Bezier curve (x(t),y(t),0) in the x/y plane, you first compute the tangent vector (x'(t),y'(t),0). The corresponding 3D normal vector is then (-y'(t),x'(t),0), which you rotate around the y axis similar to the vertices. Don't forget to normalize the normal vectors.

Enable at least one light source and position it so that it nicely illuminates the patch from the front.

Add a texture image to the flag, which stretches across its entire area. Download this UCSD logo image in PPM format, which can be read with the code in the above mentioned sample program. Compute and set texture coordinates in a range of 0 to 1 for the vertices of your mesh with the glTexCoord2f command. Note that this range needs to extend across both patches: the bottom left corner of your flag should have texture coordinates (0,0), the top right corner should be (1,1).

3. GLSL (30 Points)

4. Optional: Animated Flag (10 Points)

  • Piecewise Bezier patch: instead of just one patch, use two side by side, or more if you wish. This way you will have more control points to create a more realistic flag. Make sure the patches have C1 continuity so that there won't be creases between them.
  • Use sine and cosine functions, or others, to move the control points of your patch to simulate a flag waving in the wind.