*This page was last updated: January 11, 2018*

The goals of this project are to use displacement mapping to turn a simple shape into a more interesting one, re-compute its normals, bump-map it, and light it.

The turnin for this project will be all of the source files and a PDF report containing:

- What you did and explaining why it worked this way
- Side-by-side images showing different values for the input parameters
- Per-fragment lighted mage(s) showing that your normal computation is correct.
- Per-fragment lighted mage(s) showing that your bump-mapping is correct.
- A link to your video

This needs to be a PDF file turned into **Teach** with your other files.
Be sure to keep your PDF outside your .zip file so I can gather up all the PDF files at once with a script.

This shape is a sine wave that increases as you go down in y. If (x,y,z) are the vertex coordinates being processed right now, do something like this:

**z = K * (Y0-y) * sin( 2.*PI*x/P )**

where **K** is a constant that controls amplitude of the pleat fold,
**Y0** is the top of the curtain where there is no z displacement,
and **P** is the period of the sine wave.
**Y0** can just be a constant set in the vertex shader.

The original x and y, plus the new z become the new vertex that gets multiplied by gl_ModelViewProjectionMatrix.

Unlike RenderMan, GLSL has no *calculateormal( )* function to make
displacement mapping go easier.
So, you have to do it yourself.
But, in this case, because you have an equation, it's not too hard.

Remember that the cross product of two vectors gives you a third vector that is perpendicular to both. So, all you have to do to get the normal is determine 2 vectors that lie on the surface at the point in question and then take take their cross product, and then normalize it.

Because those 2 vectors lie in the plane of the surface, they are *tangent lines*.
Each tangent is determined by taking calculus derivatives:

**float dzdx = K * (Y0-y) * (2.*PI/P) * cos( 2.*PI*x/P )**

**float dzdy = -K * sin( 2.*PI*x/P )**

The tangent vectors are then formed like this:

**Tx = (1., 0., dzdx )**

**Ty = (0., 1., dzdy )**

Start with the lighting shader we looked at in class. Feel free to use it as-is or as a starting point, or feel free to make your own. At a minumim, you must be able to adjust Ka, Kd, Ks, shininess, and the light position.

##OpenGL GLIB Perspective 70 LookAt 0 0 3 0 0 0 0 1 0 Vertex pleats.vert Fragment pleats.frag Program Pleats \ uK <? ? ?> \ uP <? ? ?> \ uNoiseAmp <0. 0. ?> \ uNoiseFreq <0. ? ?> \ uKa <0. 0.1 1.0> \ uKd <0. 0.6 1.0> \ uKs <0. 0.3 1.0> \ uShininess <1. 10. 1000.> \ uLightX <-20. 5. 20.> \ uLightY <-20. 10. 20.> \ uLightZ <-20. 20. 20.> \ uColor {1. .7 0. 1.} \ uSpecularColor {1. 1. 1. 1.} QuadXY -0.2 1. 200 200

Note that you need to break the quad down into many sub-quads (the "200 200" above) so that there are enough vertices to create a smooth displacement function.

You've determined the normal. Now you want to perturb it in a seemingly random, yet coherent, way. Sounds like a job for noise, right?

Use the glman noise capability to get two noise values. These will be treated as an angle to rotate the normal about x and an angle to rotate the normal about y. Create at least two more sliders: uNoiseAmp and uNoiseFreq.

vec4 nvx = texture( Noise3, uNoiseFreq*vMC ); float angx = nvx.r + nvx.g + nvx.b + nvx.a - 2.; angx *= uNoiseAmp; vec4 nvy = texture( Noise3, uNoiseFreq*vec3(vMC.xy,vMC.z+0.5) ); float angy = nvy.r + nvy.g + nvy.b + nvy.a - 2.; angy *= uNoiseAmp;

Rotate the normal like this:

vec3 RotateNormal( float angx, float angy, vec3 n ) { float cx = cos( angx ); float sx = sin( angx ); float cy = cos( angy ); float sy = sin( angy ); // rotate about x: float yp = n.y*cx - n.z*sx; // y' n.z = n.y*sx + n.z*cx; // z' n.y = yp; // n.x = n.x; // rotate about y: float xp = n.x*cy + n.z*sy; // x' n.z = -n.x*sy + n.z*cy; // z' n.x = xp; // n.y = n.y; return normalize( n ); }

Feature | Points |
---|---|

Correctly show the effect of changing uK | 15 |

Correctly show the effects of changing uP | 15 |

Correctly show the effects of changing uNoiseAmp | 15 |

Correctly show the effect of changing uNoiseFreq | 15 |

Use lighting to show that you have computed the normal correctly | 20 |

Use lighting to show that you have computed the bump-mapping correctly | 20 |

Potential Total | 100 |