Difference between revisions of "Project6Fall14"
Line 28: | Line 28: | ||
glEnable(GL_CULL_FACE); | glEnable(GL_CULL_FACE); | ||
glCullFace(GL_BACK); | glCullFace(GL_BACK); | ||
+ | </pre> | ||
+ | |||
+ | Use the following settings for your texture after your first <tt>glBindTexture</tt> for correct lighting and filtering settings: | ||
+ | |||
+ | <pre> | ||
+ | // 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); | ||
</pre> | </pre> | ||
Line 64: | Line 78: | ||
f) Make sure your control points still work as before and allow changing the shape of the object. ('''5 points''') | f) Make sure your control points still work as before and allow changing the shape of the object. ('''5 points''') | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Revision as of 03:25, 24 November 2014
Contents |
Project 6: Simple Water
This project is on Bezier patches, texturing, and environment mapping with a GLSL shader program. The goal is to create a Bezier patch, make it resemble a water surface with small waves, then put it in a textured environment cube and render its surface with environment mapping.
It is due on Friday, December 5th at 3:30pm and will be discussed in CSB 001 on Monday, December 1st at 5pm.
1. Make a Bezier Patch
Generate the 16 control points for a cubic Bezier patch. Put them all in the x-z plane (horizontal), since the patch is going to simulate water.
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. Give the quads a color and material 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.
2. Add an Environment
Embed the water patch in a sky box. A sky box is a large box which is drawn around your entire scene and which your scene is inside of. The walls of the box have pictures of a sky and perhaps imagery at the 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 around your patch by generating five sides of a cube (all but the bottom - the bottom side will be replaced by your patch) out of large textured GL_QUADS. Position and scale the box so that the patch is at its base, and it snugly hugs the patch.
Make sure single-sided rendering (triangle culling) is enabled with these lines somewhere in your code to ensure the box never occludes your patch:
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);
3. Use Environment Mapping
Add shaders to render your patch with environment mapping, using the sky box textures as your cubic environment map.
Support the 'e' key to turn environment mapping on and off.
4. Animate the Patch
Use sine and cosine functions to move the control points of your patch up and down, to simulate a water surface.