Difference between revisions of "Project6Fall14"

From Immersive Visualization Lab Wiki
Jump to: navigation, search
(Project 6: Textured Patch)
(2. Sky Box (20 Points))
 
(27 intermediate revisions by one user not shown)
Line 1: Line 1:
=Project 6: Silver Water=
+
=Project 6: Simple Water=
 
+
[THIS PROJECT IS UNDER CONSTRUCTION. PLEASE COME BACK LATER.]
+
  
 
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.
 
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.
Line 7: Line 5:
 
It is due on '''Friday, December 5th at 3:30pm''' and will be discussed in CSB 001 on Monday, December 1st at 5pm.
 
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==
+
==1. Bezier Patch (30 Points)==
==2. Animate the Patch==
+
==3. Add an Environment==
+
==4. Use Environment Mapping==
+
  
<--
+
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.
A surface of revolution is an object that is rotationally symmetrical around a central axis. The following picture shows approximately what is expected.
+
  
[[Image:sor-editor.jpg]]
+
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.
  
a) Start by drawing a GL_LINE from top to bottom in the center of your OpenGL window. This is your axis of symmetry. ('''5 points''')
+
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.
  
b) Generate control points for two connected cubic Bezier curves, and display the control points as GL_POINTS - you can create larger points with the <tt>glPointSize</tt> command. (If you max out the point size, use <tt>glutSolidSphere</tt>). All control points need to be located to the right of the axis of symmetry. Use different colors for the interpolating control points and the approximating ones. ('''5 points''')
+
'''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.
  
c) Connect the control points with straight lines. ('''5 points''')
+
Enable at least one light source and position it so that it nicely illuminates the patch.
  
d) Draw the cubic Bezier curves the control points describe in a different color than the lines: Evaluate at least 20 sample points (this needs to be a const value in your code that can be changed easily) along each Bezier curve segment. The two curves need to be C0 continuous at the junction point, but higher level continuity is not required for now. ('''10 points''')
+
==2. Sky Box (20 Points)==
  
e) Calculate the vertices for the surface of revolution by rotating the Bezier curve around the axis of symmetry in steps of at most 10 degrees (make this a const value that can be changed easily as well). ('''10 points''')
+
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. [http://www.f-lohmueller.de/pov_tut/skyboxer/skyboxer_3.htm Here is is a nice collection of textures for sky boxes].  
  
f) Connect the vertices with GL_QUADS in counter-clockwise order to form a surface, and calculate (normalized!) normals. Use a perfect bright white (<tt>glColor3f(1,1,1)</tt>) for the color of the GL_QUADS. ('''10 points''')
+
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.
  
'''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.
+
Make sure single-sided rendering (triangle culling) is enabled with these lines somewhere in your code to ensure the box never occludes your patch:
  
g) Enable at least one directional light source and position it so that it nicely illuminates the object. Use a light direction from above and behind the camera and slightly offset to the left. ('''5 points''')
+
<pre>
 +
glEnable(GL_CULL_FACE);
 +
glCullFace(GL_BACK);
 +
</pre>
  
h) Allow the user to move the control points with the mouse by clicking on them with the left mouse button and dragging them to a new location. Don't allow moving them across the axis of symmetry. Regenerate the surface of revolution for the new set of control points every time the mouse button is released. ('''10 points''')
+
Use the following settings for your texture after your first <tt>glBindTexture</tt> for correct lighting and filtering settings:
  
==2. Texture Your Object (40 Points)==
+
<pre>
 +
  // Make sure no bytes are padded:
 +
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  
Take a photograph or find one on-line and drape it onto your surface of revolution. It needs to stretch across its entire surface area, from top to bottom and all the way around, but only on the outside, not the inside of the object.
+
  // Select GL_MODULATE to mix texture with polygon color for shading:
 +
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  
To familiarize yourself with texture mapping in OpenGL, we provide a [[texture.cpp | sample program]], which loads a PPM file and uses it as a texture for a quad. You can cut and paste code from it into your own project.
+
  // Use bilinear interpolation:
 +
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 +
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 +
</pre>
  
Follow these steps:
+
To familiarize yourself with texture mapping in OpenGL, we provide a [[texture.cpp | 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 [http://www.irfanview.com IrfanView] for Windows will do this for you.
  
a) Convert your photograph to the PPM format. The free image processing tool [http://www.irfanview.com IrfanView] will do this for you. ('''5 points''')
+
Alternatively, you can use a third party library such as [http://lonesock.net/soil.html SOIL] to natively load JPEG images.
  
b) Read the PPM image and turn it into an OpenGL texture. You can use the code from the above referenced sample program. ('''10 points''')
+
==3. Environment Mapping (30 Points)==
  
c) Calculate texture coordinates for each vertex and set them with <tt>glTexCoord2f</tt>. Make sure the texture gets mapped right side up. The image needs to stretch to the entire height of the object and go all the way around it - this means that the texture coordinates at each vertex will need to be fractions of 1. ('''10 points''')
+
Add shaders to render your patch with environment mapping (reflection mapping), using the sky box textures as your cubic environment map.
  
d) Render the surface of revolution with the texture. ('''5 points''')
+
Support the 'e' key to turn environment mapping on and off.
  
e) Add support for the 't' key to toggle between the object with and without the texture. ('''5 points''')
+
Useful links with tutorials:
  
f) Make sure your control points still work as before and allow changing the shape of the object. ('''5 points''')
+
* http://www.3dcpptutorials.sk/index.php?id=24
 +
* http://antongerdelan.net/opengl/cubemaps.html
  
'''Tips:'''
+
==4. Animation (20 Points)==
  
* Use the following settings for your texture after your first <tt>glBindTexture</tt> for correct lighting and filtering settings:
+
Use sine and cosine functions to move the control points of your patch up and down, to simulate the movements on the surface of water.
  
<pre>
+
==5. Optional: Improvements (10 Points)==
  // Make sure no bytes are padded:
+
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
  
  // Select GL_MODULATE to mix texture with quad color for shading:
+
Each of the following improvements to your algorithm will get you 10 points of extra credit:
  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>
+
  
* For the texture coordinates u/v, you can use the curve parameter t at each vertex as the u parameter. The v parameter at each vertex is proportional to the rotation angle around the y axis you applied to get the vertex.
+
* Piecewise Bezier patch: instead of just one patch, use four in an array of 2x2 patches, or even more. This way you will have more control points to create more realistic looking waves. Make sure the patches have C1 continuity so that there won't be creases between them.
  
-->
+
* More realistic water: research refraction mapping and improve your shader to create more realistic looking water. You will need a texture for what is below the water surface, for which you can use the base texture of the sky box, or a different one, for instance with pebbles, rocks, sand, or other lake floor-type imagery.

Latest revision as of 11:49, 1 December 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. Bezier Patch (30 Points)

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. Sky Box (20 Points)

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);

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.

3. Environment Mapping (30 Points)

Add shaders to render your patch with environment mapping (reflection mapping), using the sky box textures as your cubic environment map.

Support the 'e' key to turn environment mapping on and off.

Useful links with tutorials:

4. Animation (20 Points)

Use sine and cosine functions to move the control points of your patch up and down, to simulate the movements on the surface of water.

5. Optional: Improvements (10 Points)

Each of the following improvements to your algorithm will get you 10 points of extra credit:

  • Piecewise Bezier patch: instead of just one patch, use four in an array of 2x2 patches, or even more. This way you will have more control points to create more realistic looking waves. Make sure the patches have C1 continuity so that there won't be creases between them.
  • More realistic water: research refraction mapping and improve your shader to create more realistic looking water. You will need a texture for what is below the water surface, for which you can use the base texture of the sky box, or a different one, for instance with pebbles, rocks, sand, or other lake floor-type imagery.