Difference between revisions of "Project6F15"
(→2. Flag (40 Points)) |
(→4. Optional: Animated Flag (10 Points)) |
||
(14 intermediate revisions by one user not shown) | |||
Line 7: | Line 7: | ||
==1. Sky Box (30 Points)== | ==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. [http://www.f-lohmueller.de/pov_tut/skyboxer/skyboxer_3.htm Here is is a nice collection of textures for sky boxes]. | + | Start with your code which includes camera movement, ideally with the mouse, but if you didn't do that the keyboard shortcuts will suffice. |
+ | |||
+ | 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. [http://www.f-lohmueller.de/pov_tut/skyboxer/skyboxer_3.htm Here is is a nice collection of textures for sky boxes], and [http://www.custommapmakers.org/skyboxes.php here is an even bigger one]. | ||
Draw a cubic sky box and make it big enough to exceed the size of the viewing pyramid. | Draw a cubic sky box and make it big enough to exceed the size of the viewing pyramid. | ||
Line 38: | Line 40: | ||
==2. Flag (40 Points)== | ==2. Flag (40 Points)== | ||
− | Generate the 16 control points for a cubic Bezier patch | + | Generate the 16 control points for a cubic Bezier patch, and position them so that they describe a patch which looks like a flag, bent by the wind. Make the flag parallel to the x-y plane so that it is oriented vertically. |
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. | 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. | ||
Line 48: | Line 50: | ||
Enable at least one light source and position it so that it nicely illuminates the patch from the front. | 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 [[Media:ucsd-logo.ppm | this | + | Add a texture image to the flag, which stretches across its entire area. Download [[Media:ucsd-logo.ppm | this UCSD logo]] 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 <tt>glTexCoord2f</tt> command. The bottom left corner of your flag should have texture coordinates (0,0), the top right corner should be (1,1). |
+ | |||
+ | '''Grading:''' | ||
+ | * -10 if there is no texture | ||
+ | * -10 if normals don't exist or are incorrect | ||
+ | * -5 if there are no polygons, just points | ||
==3. GLSL (30 Points)== | ==3. GLSL (30 Points)== | ||
+ | |||
+ | Write GLSL vertex and fragment shaders and enable them for the flag (5 points) to achieve two effects: | ||
+ | |||
+ | * The black pixels of the logo should be transparent, so that the sky box is visible through them. (10 points) | ||
+ | * The white pixels of the logo should get colored with the interpolated normals for the pixel, just like the per pixel colors from problem 4 in assignment 3. (15 points) | ||
+ | |||
+ | Support a keyboard key of your choice to toggle the shader on or off. | ||
==4. Optional: Animated Flag (10 Points)== | ==4. Optional: Animated Flag (10 Points)== | ||
− | + | The extra credit consists of two parts: | |
+ | |||
+ | * Instead of just one patch, generate 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 between them so that there won't be a crease. (5 Points) | ||
− | * Use sine and cosine functions, or | + | * Use sine and cosine functions, or develop your own algorithm, to move the control points of your patch to simulate a flag waving in the wind. Here's a nice [http://gaelduplessix.github.io/cloth-simulation/ example of a beautifully animated flag from CSE 169, written in WebGL]. (5 Points) |
Latest revision as of 12:11, 13 November 2015
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)
Start with your code which includes camera movement, ideally with the mouse, but if you didn't do that the keyboard shortcuts will suffice.
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, and here is an even bigger one.
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, and position them so that they describe a patch which looks like a flag, bent by the wind. Make the flag parallel to the x-y plane so that it is oriented vertically.
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 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. The bottom left corner of your flag should have texture coordinates (0,0), the top right corner should be (1,1).
Grading:
- -10 if there is no texture
- -10 if normals don't exist or are incorrect
- -5 if there are no polygons, just points
3. GLSL (30 Points)
Write GLSL vertex and fragment shaders and enable them for the flag (5 points) to achieve two effects:
- The black pixels of the logo should be transparent, so that the sky box is visible through them. (10 points)
- The white pixels of the logo should get colored with the interpolated normals for the pixel, just like the per pixel colors from problem 4 in assignment 3. (15 points)
Support a keyboard key of your choice to toggle the shader on or off.
4. Optional: Animated Flag (10 Points)
The extra credit consists of two parts:
- Instead of just one patch, generate 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 between them so that there won't be a crease. (5 Points)
- Use sine and cosine functions, or develop your own algorithm, to move the control points of your patch to simulate a flag waving in the wind. Here's a nice example of a beautifully animated flag from CSE 169, written in WebGL. (5 Points)