Changeset 1842 for trunk/tutorial
 Timestamp:
 Aug 30, 2012, 11:52:03 PM (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/tutorial/03_noise.lolfx
r1840 r1842 16 16 uniform float u_Time; 17 17 18 vec 3 mod289(vec3x)18 vec4 mod289(vec4 x) 19 19 { 20 20 return x  floor(x * (1.0 / 289.0)) * 289.0; 21 21 } 22 22 23 vec 3 perm(vec3x)23 vec4 perm(vec4 x) 24 24 { 25 25 return mod289(((x * 34.0) + 1.0) * x); 26 26 } 27 27 28 vec4 noise3d(vec3 p1, vec3 p2, vec3 p3, vec3 p4) 29 { 30 p1 = perm(perm(perm(p1) + p1.zxy) + p1.yzx); 31 p2 = perm(perm(perm(p2) + p2.zxy) + p2.yzx); 32 p3 = perm(perm(perm(p3) + p3.zxy) + p3.yzx); 33 p4 = perm(perm(perm(p4) + p4.zxy) + p4.yzx); 34 return fract(vec4(p1.x, p2.x, p3.x, p4.x) / 41.0); 35 } 36 37 float perlin3d(vec3 p) 28 float noise3d(vec3 p) 38 29 { 39 30 mat3 r = mat3(0.36, 0.48, 0.8, 0.8, 0.60, 0.0, 0.48, 0.64, 0.60); … … 44 35 d = d * d * (3.0  2.0 * d); 45 36 46 vec4 o1 = noise3d(a, 47 a + vec3(0.0, 1.0, 0.0), 48 a + vec3(0.0, 0.0, 1.0), 49 a + vec3(0.0, 1.0, 1.0)); 50 vec4 o2 = noise3d(a + vec3(1.0, 0.0, 0.0), 51 a + vec3(1.0, 1.0, 0.0), 52 a + vec3(1.0, 0.0, 1.0), 53 a + vec3(1.0, 1.0, 1.0)); 37 vec4 b = a.xxyy + vec4(0.0, 1.0, 0.0, 1.0); 38 vec4 k1 = perm(b.xyxy); 39 vec4 k2 = perm(k1.xyxy + b.zzww); 54 40 55 vec4 o3 = o2 * d.x + o1 * (1.0  d.x); 56 vec2 o4 = o3.yw * d.y + o3.xz * (1.0  d.y); 41 vec4 c = k2 + a.zzzz; 42 vec4 k3 = perm(c); 43 vec4 k4 = perm(c + 1.0); 57 44 58 return o4.y * d.z + o4.x * (1.0  d.z); 45 vec4 o1 = fract(k3 * (1.0 / 41.0)); 46 vec4 o2 = fract(k4 * (1.0 / 41.0)); 47 48 vec4 o3 = o2 * d.z + o1 * (1.0  d.z); 49 vec2 o4 = o3.yw * d.x + o3.xz * (1.0  d.x); 50 51 return o4.y * d.y + o4.x * (1.0  d.y); 59 52 } 60 53 … … 65 58 float z = u_Time * 2.0; 66 59 67 float p = perlin3d(vec3(xy / 80.0, z + 1.5)) / 2.068 + perlin3d(vec3(xy / 40.0, z + 0.3)) / 4.069 + perlin3d(vec3(xy / 20.0, z + 3.3)) / 8.070 + perlin3d(vec3(xy / 10.0, z + 2.0)) / 16.0;60 float p = noise3d(vec3(xy / 80.0, z)) / 2.0 61 + noise3d(vec3(xy / 40.0, z)) / 4.0 62 + noise3d(vec3(xy / 20.0, z)) / 8.0 63 + noise3d(vec3(xy / 10.0, z)) / 16.0; 71 64 72 65 /* Scroll by adding [.5,.5] */ … … 97 90  HLSL.Frag  98 91 99 float 3 mod289(float3x)92 float4 mod289(float4 x) 100 93 { 101 94 return x  floor(x * (1.0 / 289.0)) * 289.0; 102 95 } 103 96 104 float 3 perm(float3x)97 float4 perm(float4 x) 105 98 { 106 99 return mod289(((x * 34.0) + 1.0) * x); 107 100 } 108 101 109 float4 noise3d(float3 p1, float3 p2, float3 p3, float3 p4) 110 { 111 p1 = perm(perm(perm(p1) + p1.zxy) + p1.yzx); 112 p2 = perm(perm(perm(p2) + p2.zxy) + p2.yzx); 113 p3 = perm(perm(perm(p3) + p3.zxy) + p3.yzx); 114 p4 = perm(perm(perm(p4) + p4.zxy) + p4.yzx); 115 return frac(float4(p1.x, p2.x, p3.x, p4.x) / 41.0); 116 } 117 118 float perlin3d(float3 p) 102 float noise3d(float3 p) 119 103 { 120 104 float3x3 r = float3x3(0.36, 0.48, 0.8, 0.8, 0.60, 0.0, 0.48, 0.64, 0.60); … … 125 109 d = d * d * (3.0  2.0 * d); 126 110 127 float4 o1 = noise3d(a, 128 a + float3(0.0, 1.0, 0.0), 129 a + float3(0.0, 0.0, 1.0), 130 a + float3(0.0, 1.0, 1.0)); 131 float4 o2 = noise3d(a + float3(1.0, 0.0, 0.0), 132 a + float3(1.0, 1.0, 0.0), 133 a + float3(1.0, 0.0, 1.0), 134 a + float3(1.0, 1.0, 1.0)); 111 float4 b = a.xxyy + float4(0.0, 1.0, 0.0, 1.0); 112 float4 k1 = perm(b.xyxy); 113 float4 k2 = perm(k1.xyxy + b.zzww); 135 114 136 float4 o3 = o2 * d.x + o1 * (1.0  d.x); 137 float2 o4 = o3.yw * d.y + o3.xz * (1.0  d.y); 115 float4 c = k2 + a.zzzz; 116 float4 k3 = perm(c); 117 float4 k4 = perm(c + 1.0); 138 118 139 return o4.y * d.z + o4.x * (1.0  d.z); 119 float4 o1 = frac(k3 * (1.0 / 41.0)); 120 float4 o2 = frac(k4 * (1.0 / 41.0)); 121 122 float4 o3 = o2 * d.z + o1 * (1.0  d.z); 123 float2 o4 = o3.yw * d.x + o3.xz * (1.0  d.x); 124 125 return o4.y * d.y + o4.x * (1.0  d.y); 140 126 } 141 127 … … 148 134 float z = u_Time * 2.0; 149 135 150 float p = perlin3d(float3(xy / 80.0, z + 1.5)) / 2.0151 + perlin3d(float3(xy / 40.0, z + 0.3)) / 4.0152 + perlin3d(float3(xy / 20.0, z + 3.3)) / 8.0153 + perlin3d(float3(xy / 10.0, z + 2.0)) / 16.0;136 float p = noise3d(float3(xy / 80.0, z)) / 2.0 137 + noise3d(float3(xy / 40.0, z)) / 4.0 138 + noise3d(float3(xy / 20.0, z)) / 8.0 139 + noise3d(float3(xy / 10.0, z)) / 16.0; 154 140 155 141 /* Scroll by adding [.5,.5] */
Note: See TracChangeset
for help on using the changeset viewer.