tesspot
view sdr/bezier.te.glsl @ 2:178a9e3c3c8c
isolines
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 03 Dec 2012 07:30:39 +0200 |
parents | befe01bbd27f |
children |
line source
1 #version 410 compatibility
3 layout(quads, ccw) in;
5 out vec3 normal;
6 out vec3 vpos;
7 out vec2 uv;
9 uniform vec3 norm_scale;
11 vec3 bezier_patch(float u, float v);
12 vec3 bezier_patch_norm(float u, float v);
13 float bernstein(int i, float x);
15 void main()
16 {
17 vec3 pos = bezier_patch(gl_TessCoord.x, gl_TessCoord.y);
18 normal = gl_NormalMatrix * bezier_patch_norm(gl_TessCoord.x, gl_TessCoord.y);
20 uv = gl_TessCoord.xy;
22 gl_Position = gl_ModelViewProjectionMatrix * vec4(pos, 1.0);
23 vpos = (gl_ModelViewMatrix * vec4(pos, 1.0)).xyz;
24 }
26 vec3 bezier_patch(float u, float v)
27 {
28 int i, j;
29 vec3 res = vec3(0.0, 0.0, 0.0);
31 for(j=0; j<4; j++) {
32 for(i=0; i<4; i++) {
33 float bu = bernstein(i, u);
34 float bv = bernstein(j, v);
36 res += gl_in[j * 4 + i].gl_Position.xyz * bu * bv;
37 }
38 }
39 return res;
40 }
42 #define DT 0.0001
43 vec3 bezier_patch_norm(float u, float v)
44 {
45 vec3 tang = bezier_patch(u + DT, v) - bezier_patch(u - DT, v);
46 vec3 bitan = bezier_patch(u, v + DT) - bezier_patch(u, v - DT);
47 return cross(tang, bitan) * norm_scale;
48 }
50 float bernstein(int i, float x)
51 {
52 float invx = 1.0 - x;
54 if(i == 0) {
55 return invx * invx * invx;
56 }
57 if(i == 1) {
58 return 3 * x * invx * invx;
59 }
60 if(i == 2) {
61 return 3 * x * x * invx;
62 }
63 return x * x * x;
64 }