tesspot

annotate 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
rev   line source
nuclear@0 1 #version 410 compatibility
nuclear@0 2
nuclear@1 3 layout(quads, ccw) in;
nuclear@0 4
nuclear@0 5 out vec3 normal;
nuclear@0 6 out vec3 vpos;
nuclear@2 7 out vec2 uv;
nuclear@0 8
nuclear@1 9 uniform vec3 norm_scale;
nuclear@1 10
nuclear@0 11 vec3 bezier_patch(float u, float v);
nuclear@0 12 vec3 bezier_patch_norm(float u, float v);
nuclear@0 13 float bernstein(int i, float x);
nuclear@0 14
nuclear@0 15 void main()
nuclear@0 16 {
nuclear@0 17 vec3 pos = bezier_patch(gl_TessCoord.x, gl_TessCoord.y);
nuclear@0 18 normal = gl_NormalMatrix * bezier_patch_norm(gl_TessCoord.x, gl_TessCoord.y);
nuclear@0 19
nuclear@2 20 uv = gl_TessCoord.xy;
nuclear@2 21
nuclear@0 22 gl_Position = gl_ModelViewProjectionMatrix * vec4(pos, 1.0);
nuclear@0 23 vpos = (gl_ModelViewMatrix * vec4(pos, 1.0)).xyz;
nuclear@0 24 }
nuclear@0 25
nuclear@0 26 vec3 bezier_patch(float u, float v)
nuclear@0 27 {
nuclear@0 28 int i, j;
nuclear@0 29 vec3 res = vec3(0.0, 0.0, 0.0);
nuclear@0 30
nuclear@0 31 for(j=0; j<4; j++) {
nuclear@0 32 for(i=0; i<4; i++) {
nuclear@0 33 float bu = bernstein(i, u);
nuclear@0 34 float bv = bernstein(j, v);
nuclear@0 35
nuclear@0 36 res += gl_in[j * 4 + i].gl_Position.xyz * bu * bv;
nuclear@0 37 }
nuclear@0 38 }
nuclear@0 39 return res;
nuclear@0 40 }
nuclear@0 41
nuclear@0 42 #define DT 0.0001
nuclear@0 43 vec3 bezier_patch_norm(float u, float v)
nuclear@0 44 {
nuclear@0 45 vec3 tang = bezier_patch(u + DT, v) - bezier_patch(u - DT, v);
nuclear@0 46 vec3 bitan = bezier_patch(u, v + DT) - bezier_patch(u, v - DT);
nuclear@1 47 return cross(tang, bitan) * norm_scale;
nuclear@0 48 }
nuclear@0 49
nuclear@0 50 float bernstein(int i, float x)
nuclear@0 51 {
nuclear@0 52 float invx = 1.0 - x;
nuclear@0 53
nuclear@0 54 if(i == 0) {
nuclear@0 55 return invx * invx * invx;
nuclear@0 56 }
nuclear@0 57 if(i == 1) {
nuclear@0 58 return 3 * x * invx * invx;
nuclear@0 59 }
nuclear@0 60 if(i == 2) {
nuclear@0 61 return 3 * x * x * invx;
nuclear@0 62 }
nuclear@0 63 return x * x * x;
nuclear@0 64 }