# Changeset 1825 for trunk/tutorialTweet

Ignore:
Timestamp:
Aug 27, 2012, 3:38:58 PM (8 years ago)
Message:

tutorial: the noise demo is now really, really, ridiculously good looking.

File:
1 edited

Unmodified
Added
Removed
• ## trunk/tutorial/03_noise.lolfx

 r1824 } vec3 perlin3(vec2 p) vec3 perlin2d(vec2 p) { vec2 a = floor(p); vec2 d = p - a; d = d * d * (3.0 - 2.0 * d); vec2 a = floor(p); vec2 d = p - a; d = d * d * (3.0 - 2.0 * d); vec3 n1 = noise3(a); vec3 n2 = noise3(a + vec2(1.0, 0.0)); vec3 n3 = noise3(a + vec2(0.0, 1.0)); vec3 n4 = noise3(a + vec2(1.0, 1.0)); vec3 n1 = noise3(a); vec3 n2 = noise3(a + vec2(1.0, 0.0)); vec3 n3 = noise3(a + vec2(0.0, 1.0)); vec3 n4 = noise3(a + vec2(1.0, 1.0)); vec3 q1 = n2 * d.x + n1 * (1.0 - d.x); vec3 q2 = n4 * d.x + n3 * (1.0 - d.x); vec3 q1 = n2 * d.x + n1 * (1.0 - d.x); vec3 q2 = n4 * d.x + n3 * (1.0 - d.x); vec3 q3 = q2 * d.y + q1 * (1.0 - d.y); vec3 q3 = q2 * d.y + q1 * (1.0 - d.y); return q3; return q3; } vec3 perlin3(vec3 p) vec3 perlin3d(vec3 p) { vec3 a = floor(p); vec3 d = p - a; d = d * d * (3.0 - 2.0 * d); mat3 r = mat3(0.36, 0.48, -0.8, -0.8, 0.60, 0.0, 0.48, 0.64, 0.60); p = r * p; vec3 o1 = noise3(a); vec3 o2 = noise3(a + vec3(1.0, 0.0, 0.0)); vec3 o3 = noise3(a + vec3(0.0, 1.0, 0.0)); vec3 o4 = noise3(a + vec3(1.0, 1.0, 0.0)); vec3 o5 = noise3(a + vec3(0.0, 0.0, 1.0)); vec3 o6 = noise3(a + vec3(1.0, 0.0, 1.0)); vec3 o7 = noise3(a + vec3(0.0, 1.0, 1.0)); vec3 o8 = noise3(a + vec3(1.0, 1.0, 1.0)); vec3 a = floor(p); vec3 d = p - a; d = d * d * (3.0 - 2.0 * d); vec3 n1 = o2 * d.x + o1 * (1.0 - d.x); vec3 n2 = o4 * d.x + o3 * (1.0 - d.x); vec3 n3 = o6 * d.x + o5 * (1.0 - d.x); vec3 n4 = o8 * d.x + o7 * (1.0 - d.x); vec3 o1 = noise3(a); vec3 o2 = noise3(a + vec3(1.0, 0.0, 0.0)); vec3 o3 = noise3(a + vec3(0.0, 1.0, 0.0)); vec3 o4 = noise3(a + vec3(1.0, 1.0, 0.0)); vec3 o5 = noise3(a + vec3(0.0, 0.0, 1.0)); vec3 o6 = noise3(a + vec3(1.0, 0.0, 1.0)); vec3 o7 = noise3(a + vec3(0.0, 1.0, 1.0)); vec3 o8 = noise3(a + vec3(1.0, 1.0, 1.0)); vec3 q1 = n2 * d.y + n1 * (1.0 - d.y); vec3 q2 = n4 * d.y + n3 * (1.0 - d.y); vec3 n1 = o2 * d.x + o1 * (1.0 - d.x); vec3 n2 = o4 * d.x + o3 * (1.0 - d.x); vec3 n3 = o6 * d.x + o5 * (1.0 - d.x); vec3 n4 = o8 * d.x + o7 * (1.0 - d.x); vec3 q3 = q2 * d.z + q1 * (1.0 - d.z); vec3 q1 = n2 * d.y + n1 * (1.0 - d.y); vec3 q2 = n4 * d.y + n3 * (1.0 - d.y); return q3; vec3 q3 = q2 * d.z + q1 * (1.0 - d.z); return q3; } void main(void) { //vec3 input = vec3(gl_FragCoord.xy, in_Time * 200.0); vec3 input = vec3(in_Time * 20.0, gl_FragCoord.xy); vec2 xy = gl_FragCoord.xy; float z = in_Time * 2.0; vec3 p = perlin3(input / 160.0) / 2.0 + perlin3(input / 80.0) / 4.0 + perlin3(input / 40.0) / 8.0 + perlin3(input / 20.0) / 16.0 + perlin3(input / 10.0) / 32.0 + perlin3(input / 5.0) / 64.0 + perlin3(input / 2.5) / 128.0; gl_FragColor = vec4(p.xxx, 1.0); //inputvec4(perlin3(input), 1.0); //inputvec4(noise3(floor(input / 10.0)).xxx, 1.0); //inputvec4(noise3(input), 1.0); vec3 p = perlin3d(vec3(xy / 160.0, z)) / 2.0 + perlin3d(vec3(xy / 80.0, z + 1.5)) / 4.0 + perlin3d(vec3(xy / 40.0, z + 0.3)) / 8.0 + perlin3d(vec3(xy / 20.0, z + 3.3)) / 16.0 + perlin3d(vec3(xy / 10.0, z + 2.0)) / 32.0 + perlin3d(vec3(xy / 5.0, z + 1.7)) / 64.0 + perlin3d(vec3(xy / 2.5, z + 4.2)) / 128.0; p = p * p * (3.0 - 2.0 * p); p = p * p * (3.0 - 2.0 * p); gl_FragColor = vec4(min(p.x * 2.0, 1.0), max(p.x * 1.5 - 0.5, 0.0), 0.0, 1.0); }
Note: See TracChangeset for help on using the changeset viewer.