// Blending shader // PI constant #define M_PI 3.1415926535897932384626433832795 // Used by lighting fragment shader varying vec3 N; varying vec3 v; // Bending angle (-30 to 30 degrees) uniform float bendAngle; // Creates matrix representing rotation around X axis mat4 makeXRotMat(float myAngle) { // STUDENTS CODE // // X Y Z W mat4 retMat = mat4( 1.0, 0.0, 0.0, 0.0, 0.0, cos(myAngle), -sin(myAngle), 0.0, 0.0, sin(myAngle), cos(myAngle), 0.0, 0.0, 0.0, 0.0, 1.0 ); // TODO: create matrix representing rotation around X axis // Hint: use circle equation in parametric form // X column should remain constant - YZ unit vectors represent desired change of base vectors // STUDENTS CODE END // return retMat; } // Vertex shader entry point void main() { // Copy vertex vec4 tmpV = gl_Vertex; // STUDENTS CODE // // TODO: Create blended cone animation using vertices with Z > 1.0 // Step one: create rotation matrices: one should represent rotation and the other should be identity matrix // We will blend vertex rotation between them mat4 matOne = makeXRotMat(bendAngle); // Step two: calculate blending coefficient - we start bending if given vertex tmpV has Z coordinate greater than 1.0 // Cone has height of 4.0 units (Z axis), so coefficient should be calculated for Z in range from 1.0 to 4.0 // and result should be between 0.0 and 1.0 // Hint: use function clamp(val_to_clamp, min, max); // float coeff = ... float coeff = clamp((tmpV.z - 1)/3, 0, 1); // Step three: alter only vertices with Z coordinate greater than 1.0 // Hint: You can access tmpV like a structure - tmpV.x, tmpV.y, tmpV.z // Hint: tmpV must be translated to the origin in Z axis before transformation, since center of rotation will be in the origin // Hint: matrices can be blended using regular multiplication operations - blendedMat = coeffN1 * matN1 + coeffN2 * matN2 + ... // Hint: sum of coeffN1 + coeffN2 + ... must be equal to 1.0 // Hint: after altering tmpV with blendMat (tmpV = tmpV * blendMat; or tmpV *= blendMat), remember to translate tmpV back in Z axis! if(tmpV.z > 1.0) { tmpV.z -= 1.0; tmpV *= (coeff*matOne + (1f-coeff)*mat4(1f)); tmpV.z += 1.0; } // STUDENTS CODE END // // tmpV now contains final position in model space.. // Transforming The Vertex v = vec3(gl_ModelViewMatrix * tmpV); N = normalize(gl_NormalMatrix * gl_Normal); gl_Position = gl_ModelViewProjectionMatrix * tmpV; }