morph.vert 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. uniform mat4 view_matrix;
  2. uniform float speed;
  3. uniform float lerpMin;
  4. uniform float lerpMax;
  5. uniform float time_0_X;
  6. varying vec3 vViewVec;
  7. varying vec3 vNormal;
  8. varying vec4 vDiffuse;
  9. void main(void)
  10. {
  11. vec4 Pos = gl_Vertex;
  12. // Define the two key frames
  13. vec3 spherePos = normalize(gl_Vertex.xyz);
  14. vec3 cubePos = 0.9 * gl_Vertex.xyz;
  15. vec3 sphereNormal = spherePos;
  16. vec3 cubeNormal = gl_Normal;
  17. // Make a smooth 0->1->0 curve
  18. float t = fract(speed * time_0_X);
  19. t = smoothstep(0.0, 0.5, t) - smoothstep(0.5, 1.0, t);
  20. // Find the interpolation factor
  21. float lrp = lerpMin + (lerpMax - lerpMin) * t;
  22. // Linearly interpolate the position and normal
  23. Pos = vec4(mix(spherePos, cubePos, lrp), 1.0);
  24. vNormal = mix(sphereNormal, cubeNormal, lrp);
  25. // Use position as base color
  26. vDiffuse = 0.5 + 0.5 * Pos;
  27. // Give the thing some size
  28. Pos.xyz *= 30.0;
  29. // Eye-space lighting
  30. vNormal = gl_NormalMatrix * vNormal;
  31. vViewVec = -(gl_NormalMatrix * Pos.xyz);
  32. vViewVec.z = - vViewVec.z;
  33. gl_Position = gl_ModelViewProjectionMatrix * Pos;
  34. }