1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#version 430
// triangles, quads, or isolines
layout (quads, fractional_odd_spacing, ccw) in;
in vec3 evaluationpoint[];
// could use a displacement map here
uniform mat4 viewmat;
uniform mat4 projmat;
// gl_TessCoord is location within the patch
// (barycentric for triangles, UV for quads)
//
layout(location = 4) uniform mat4 pjMatrix ;
layout(location = 5) uniform mat4 mvMatrix ;
layout(location = 7) uniform mat3 normalMatrix ;
layout(location = 9) uniform float time ;
out vec3 normal ;
out vec4 position ;
out vec2 texpos ;
out vec3 original_x ;
out vec3 original_z ;
out vec3 tmpnormal ;
vec2 skew( float t ) {
return vec2(0.8*sin(t-time)+t,sin(t-time) / 5) ;
}
vec2 dskew( float t ) {
return vec2(-cos(time-t),5*(0.8*cos(time-t)+1)) ;
}
vec2 xripple( float t ) {
return vec2(t,sin(t-time)/5.0) ;
}
vec2 dxripple( float t ) {
return vec2(cos(time-t)/5.0,-1);
}
void main () {
float u = gl_TessCoord.x;
float v = gl_TessCoord.y;
vec3 a = mix(evaluationpoint[1], evaluationpoint[0], u);
vec3 b = mix(evaluationpoint[2], evaluationpoint[3], u);
vec3 pos = mix(a, b, v);
// Bolt down the two edges to ensure the end of the
// polygon does not show itself
if( u != 0 && u != 1 ) {
vec2 sk = skew(pos.z) ;
vec2 dsk = dskew(pos.z) ;
vec2 xr = xripple(pos.x) ;
vec2 dxr = dxripple(pos.x) ;
pos = vec3( xr.x, pos.y + sk.y + xr.y, sk.x);
vec3 normal_ = vec3(dxr.x, (dsk.y+dxr.y)/2, dsk.x) ;
normal = - normalMatrix * normal_; // cross( p0 - p1, p0 - p2 );
tmpnormal = normalize(normal_) ;
} else {
normal = - normalMatrix * vec3(0,1,0) ;
tmpnormal = vec3(0,1,0);
}
texpos = pos.xz / 20.0 ;
gl_Position = pjMatrix * (position = mvMatrix * vec4(pos, 1.0));
original_x = normalize(- normalMatrix * vec3(1,0,0)) ;
original_z = normalize(- normalMatrix * vec3(0,0,1)) ;
}
|