added morphing to the cow
[demo] / gl_shaders / morphing.v.glsl
index cbb3d9e..6f72aa7 100644 (file)
@@ -3,12 +3,15 @@
 uniform mat4 mview;
 uniform mat4 mmviewproj;
 
+uniform float t;
+const float half_height = 0.855;
+
 varying vec3 pos;
 varying vec3 normal;
 varying vec3 ldir;
 varying vec2 tex_coord;
 
-const vec3 lpos = vec3(-10.0, 100.0, 10.0);
+const vec3 lpos = vec3(0.0, 100.0, -10.0);
 
 /* attributes */
 layout(location = 1) in vec3 attr_pos;
@@ -17,12 +20,21 @@ layout(location = 3) in vec2 attr_tex;
 
 void main()
 {
-       gl_Position = mmviewproj * vec4(attr_pos, 1.0);
+       vec3 sph_pos = normalize(vec3(attr_pos.x, attr_pos.y - half_height, attr_pos.z));
+
+       vec3 sph_normal = sph_pos;
+       sph_pos.y += half_height;
+
+       vec3 p = mix(attr_pos, sph_pos, t);
+       vec3 n = mix(attr_normal, sph_normal, t);
 
-       pos = (mview * vec4(attr_pos, 1.0)).xyz;
+       gl_Position = mmviewproj * vec4(p, 1.0);
+
+       pos = (mview * vec4(p, 1.0)).xyz;
        ldir = (mview * vec4(lpos, 1.0)).xyz;
 
        mat3 normal_matrix = mat3(mview);
-       normal = normal_matrix * attr_normal;
+       normal = normal_matrix * n;
+
        tex_coord = attr_tex;
 }
\ No newline at end of file