Debian Codegraph @

tests/manual/tessellation-modes/shaders/isolines.tes

raw
1 #version 400 core
2
3 layout( isolines, fractional_even_spacing, ccw ) in;
4
5 out Vertex {
6 vec3 color;
7 } te_out;
8
9 uniform mat4 modelViewMatrix;
10 uniform mat3 normalMatrix;
11 uniform mat4 projectionMatrix;
12 uniform mat4 mvp;
13
14 // Calculate RGB triplet from HSV
15 vec3 hsvToRGB( float h, float s, float v )
16 {
17 if ( s <= 0.0 )
18 return vec3( v );
19
20 h = h * 6.0;
21 float c = v * s;
22 float x = ( 1.0 - abs( ( mod( h, 2 ) - 1 ) ) ) * c;
23 float m = v - c;
24 float r = 0.0;
25 float g = 0.0;
26 float b = 0.0;
27
28 if ( h < 1.0 ) { r = c; g = x; b = 0.0;}
29 else if ( h < 2.0 ) { r = x; g = c; b = 0.0; }
30 else if ( h < 3.0 ) { r = 0.0; g = c; b = x; }
31 else if ( h < 4.0 ) { r = 0.0; g = x; b = c; }
32 else if ( h < 5.0 ) { r = x; g = 0.0; b = c; }
33 else { r = c; g = 0.0; b = x; }
34
35 return vec3( r + m, g + m, b + m );
36 }
37
38 void main()
39 {
40 float u = gl_TessCoord.x;
41 float v = gl_TessCoord.y;
42
43 vec4 a = gl_in[0].gl_Position;
44 vec4 b = gl_in[1].gl_Position;
45 vec4 c = gl_in[2].gl_Position;
46 vec4 d = gl_in[3].gl_Position;
47
48 // Use the (u,v) parametric coords to calculate the vertex.
49 // u is the position along an isoline
50 // v is isoline number
51
52 // Let's make a sinusoidal curve as a function of u that varies
53 // in the v direction which we will define as orthogonal to u
54
55 // Interpolate in u along top and bottom edges of the patch
56 vec4 q0 = mix( a, b, u );
57 vec4 q1 = mix( d, c, u );
58
59 // Interpolate in v between the above positions. This gives the
60 // nominal position for our vertex
61 vec4 p = mix( q0, q1, v );
62
63 // Find "vertical" direction
64 vec4 vBasis = normalize( q1 - q0 );
65
66 // Offset vertex in this direction using sinusoid
67 vec4 pos = p + 0.2 * vBasis * sin( 20.0 * u );
68
69 // Use a hue value based on v
70 te_out.color = hsvToRGB( v, 1.0, 1.0 );
71
72 // Transform to clip-space
73 gl_Position = mvp * pos;
74 }