Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!
tweet

By: eddietree on Jan 30th, 2012  |  syntax: C  |  size: 1.04 KB  |  views: 176  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. /*
3.
4. by Eddie Lee (twitter: @eddietree)
5. http://illogictree.com
6. Jan 30, 2012
7. */
8.
9. #version 110
10.
11. varying vec2 uv;
12.
13. uniform vec4 v0;
14. uniform vec4 v1;
15. uniform vec4 tan0;
16. uniform vec4 tan1;
17.
18. vec3 hermite( vec3 p0, vec3 t0, vec3 p1, vec3 t1, float alpha )
19. {
20.         float t = alpha;
21.         float t_sqr = alpha*alpha;
22.         float t_cubed = alpha*alpha*alpha;
23.
24.
25.         float h1 =  2.0*t_cubed - 3.0*t_sqr + 1.0;          // calculate basis function 1
26.         float h2 = -2.0*t_cubed + 3.0*t_sqr;              // calculate basis function 2
27.         float h3 =  t_cubed - 2.0*t_sqr + t;         // calculate basis function 3
28.         float h4 =  t_cubed -  t_sqr;              // calculate basis function 4
29.
30.         return h1*p0 + h2*p1 + h3*t0 + h4*t1;
31. }
32.
33. void main()
34. {
35.         // interpolate on x (assume verts are normalized in x,y )
36.         float splineAlpha = gl_Vertex.x;
37.
38.         vec3 pos = hermite( v0.xyz, tan0.xyz, v1.xyz, tan1.xyz, splineAlpha);
39.         pos.y += gl_Vertex.y * 600.0;
40.         gl_Position = gl_ModelViewProjectionMatrix * vec4(pos.xy,0.0,1.0);
41.         uv = gl_Vertex.xy;
42. }
clone this paste RAW Paste Data
Top