Changeset 1825
 Timestamp:
 Aug 27, 2012, 3:38:58 PM (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/tutorial/03_noise.lolfx
r1824 r1825 30 30 } 31 31 32 vec3 perlin 3(vec2 p)32 vec3 perlin2d(vec2 p) 33 33 { 34 35 36 34 vec2 a = floor(p); 35 vec2 d = p  a; 36 d = d * d * (3.0  2.0 * d); 37 37 38 39 40 41 38 vec3 n1 = noise3(a); 39 vec3 n2 = noise3(a + vec2(1.0, 0.0)); 40 vec3 n3 = noise3(a + vec2(0.0, 1.0)); 41 vec3 n4 = noise3(a + vec2(1.0, 1.0)); 42 42 43 44 43 vec3 q1 = n2 * d.x + n1 * (1.0  d.x); 44 vec3 q2 = n4 * d.x + n3 * (1.0  d.x); 45 45 46 46 vec3 q3 = q2 * d.y + q1 * (1.0  d.y); 47 47 48 48 return q3; 49 49 } 50 50 51 vec3 perlin3 (vec3 p)51 vec3 perlin3d(vec3 p) 52 52 { 53 vec3 a = floor(p); 54 vec3 d = p  a; 55 d = d * d * (3.0  2.0 * d); 53 mat3 r = mat3(0.36, 0.48, 0.8, 0.8, 0.60, 0.0, 0.48, 0.64, 0.60); 54 p = r * p; 56 55 57 vec3 o1 = noise3(a); 58 vec3 o2 = noise3(a + vec3(1.0, 0.0, 0.0)); 59 vec3 o3 = noise3(a + vec3(0.0, 1.0, 0.0)); 60 vec3 o4 = noise3(a + vec3(1.0, 1.0, 0.0)); 61 vec3 o5 = noise3(a + vec3(0.0, 0.0, 1.0)); 62 vec3 o6 = noise3(a + vec3(1.0, 0.0, 1.0)); 63 vec3 o7 = noise3(a + vec3(0.0, 1.0, 1.0)); 64 vec3 o8 = noise3(a + vec3(1.0, 1.0, 1.0)); 56 vec3 a = floor(p); 57 vec3 d = p  a; 58 d = d * d * (3.0  2.0 * d); 65 59 66 vec3 n1 = o2 * d.x + o1 * (1.0  d.x); 67 vec3 n2 = o4 * d.x + o3 * (1.0  d.x); 68 vec3 n3 = o6 * d.x + o5 * (1.0  d.x); 69 vec3 n4 = o8 * d.x + o7 * (1.0  d.x); 60 vec3 o1 = noise3(a); 61 vec3 o2 = noise3(a + vec3(1.0, 0.0, 0.0)); 62 vec3 o3 = noise3(a + vec3(0.0, 1.0, 0.0)); 63 vec3 o4 = noise3(a + vec3(1.0, 1.0, 0.0)); 64 vec3 o5 = noise3(a + vec3(0.0, 0.0, 1.0)); 65 vec3 o6 = noise3(a + vec3(1.0, 0.0, 1.0)); 66 vec3 o7 = noise3(a + vec3(0.0, 1.0, 1.0)); 67 vec3 o8 = noise3(a + vec3(1.0, 1.0, 1.0)); 70 68 71 vec3 q1 = n2 * d.y + n1 * (1.0  d.y); 72 vec3 q2 = n4 * d.y + n3 * (1.0  d.y); 69 vec3 n1 = o2 * d.x + o1 * (1.0  d.x); 70 vec3 n2 = o4 * d.x + o3 * (1.0  d.x); 71 vec3 n3 = o6 * d.x + o5 * (1.0  d.x); 72 vec3 n4 = o8 * d.x + o7 * (1.0  d.x); 73 73 74 vec3 q3 = q2 * d.z + q1 * (1.0  d.z); 74 vec3 q1 = n2 * d.y + n1 * (1.0  d.y); 75 vec3 q2 = n4 * d.y + n3 * (1.0  d.y); 75 76 76 return q3; 77 vec3 q3 = q2 * d.z + q1 * (1.0  d.z); 78 79 return q3; 77 80 } 78 81 79 82 void main(void) 80 83 { 81 //vec3 input = vec3(gl_FragCoord.xy, in_Time * 200.0);82 vec3 input = vec3(in_Time * 20.0, gl_FragCoord.xy);84 vec2 xy = gl_FragCoord.xy; 85 float z = in_Time * 2.0; 83 86 84 vec3 p = perlin3(input / 160.0) / 2.0 85 + perlin3(input / 80.0) / 4.0 86 + perlin3(input / 40.0) / 8.0 87 + perlin3(input / 20.0) / 16.0 88 + perlin3(input / 10.0) / 32.0 89 + perlin3(input / 5.0) / 64.0 90 + perlin3(input / 2.5) / 128.0; 91 gl_FragColor = vec4(p.xxx, 1.0); 92 93 //inputvec4(perlin3(input), 1.0); 94 //inputvec4(noise3(floor(input / 10.0)).xxx, 1.0); 95 //inputvec4(noise3(input), 1.0); 87 vec3 p = perlin3d(vec3(xy / 160.0, z)) / 2.0 88 + perlin3d(vec3(xy / 80.0, z + 1.5)) / 4.0 89 + perlin3d(vec3(xy / 40.0, z + 0.3)) / 8.0 90 + perlin3d(vec3(xy / 20.0, z + 3.3)) / 16.0 91 + perlin3d(vec3(xy / 10.0, z + 2.0)) / 32.0 92 + perlin3d(vec3(xy / 5.0, z + 1.7)) / 64.0 93 + perlin3d(vec3(xy / 2.5, z + 4.2)) / 128.0; 94 p = p * p * (3.0  2.0 * p); 95 p = p * p * (3.0  2.0 * p); 96 gl_FragColor = vec4(min(p.x * 2.0, 1.0), max(p.x * 1.5  0.5, 0.0), 0.0, 1.0); 96 97 } 97 98
Note: See TracChangeset
for help on using the changeset viewer.