Changeset 1827 for trunk/tutorial/03_noise.lolfx
 Timestamp:
 Aug 27, 2012, 6:20:42 PM (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/tutorial/03_noise.lolfx
r1825 r1827 14 14 #version 120 15 15 16 uniform float in_Time;17 18 vec3 noise 3(vec2 p)16 uniform float u_Time; 17 18 vec3 noise2d(vec2 p) 19 19 { 20 20 return vec3(fract(sin(dot(p, vec2(12.3453, 54.3353432))) * 8433.235443), … … 23 23 } 24 24 25 vec3 noise3 (vec3 p)25 vec3 noise3d(vec3 p) 26 26 { 27 27 return vec3(fract(sin(54.343909 + dot(p, vec3(12.3453, 54.3353432, 34.3490432))) * 8433.235443), … … 36 36 d = d * d * (3.0  2.0 * d); 37 37 38 vec3 n1 = noise 3(a);39 vec3 n2 = noise 3(a + vec2(1.0, 0.0));40 vec3 n3 = noise 3(a + vec2(0.0, 1.0));41 vec3 n4 = noise 3(a + vec2(1.0, 1.0));38 vec3 n1 = noise2d(a); 39 vec3 n2 = noise2d(a + vec2(1.0, 0.0)); 40 vec3 n3 = noise2d(a + vec2(0.0, 1.0)); 41 vec3 n4 = noise2d(a + vec2(1.0, 1.0)); 42 42 43 43 vec3 q1 = n2 * d.x + n1 * (1.0  d.x); … … 58 58 d = d * d * (3.0  2.0 * d); 59 59 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));60 vec3 o1 = noise3d(a); 61 vec3 o2 = noise3d(a + vec3(1.0, 0.0, 0.0)); 62 vec3 o3 = noise3d(a + vec3(0.0, 1.0, 0.0)); 63 vec3 o4 = noise3d(a + vec3(1.0, 1.0, 0.0)); 64 vec3 o5 = noise3d(a + vec3(0.0, 0.0, 1.0)); 65 vec3 o6 = noise3d(a + vec3(1.0, 0.0, 1.0)); 66 vec3 o7 = noise3d(a + vec3(0.0, 1.0, 1.0)); 67 vec3 o8 = noise3d(a + vec3(1.0, 1.0, 1.0)); 68 68 69 69 vec3 n1 = o2 * d.x + o1 * (1.0  d.x); … … 82 82 void main(void) 83 83 { 84 vec2 xy = gl_FragCoord.xy; 85 float z = in_Time * 2.0; 84 vec2 xy = gl_FragCoord.xy * 2.0; 85 xy.y = u_Time * 400.0; 86 float z = u_Time * 2.0; 86 87 87 88 vec3 p = perlin3d(vec3(xy / 160.0, z)) / 2.0 … … 92 93 + perlin3d(vec3(xy / 5.0, z + 1.7)) / 64.0 93 94 + perlin3d(vec3(xy / 2.5, z + 4.2)) / 128.0; 95 96 /* Scroll by adding [.5,.5] */ 97 p = gl_FragCoord.y / 720.0  0.5; 98 p = max(p, 0.0); 99 p = min(p, 1.0); 100 94 101 p = p * p * (3.0  2.0 * p); 95 102 p = p * p * (3.0  2.0 * p); … … 100 107 101 108 void main(float2 in_Position : POSITION, 102 out float4 out_Position : POSITION) 103 { 109 uniform float2 u_WinSize, 110 out float4 out_Position : POSITION, 111 out float2 pass_Position : TEXCOORD0) 112 { 113 //pass_Position = in_Position * u_WinSize; 114 pass_Position = in_Position * float2(1280.0, 720.0); 104 115 out_Position = float4(in_Position, 0.0, 1.0); 105 116 } … … 107 118  HLSL.Frag  108 119 109 void main(out float4 out_FragColor : COLOR) 110 { 111 out_FragColor = float4(0.7, 0.2, 0.5, 1.0); 112 } 113 120 float3 noise2d(float2 p) 121 { 122 return float3(frac(sin(dot(p, float2(12.3453, 54.3353432))) * 8433.235443), 123 frac(sin(dot(p, float2(34.23232, 98.03537))) * 8294.5345433), 124 frac(sin(dot(p, float2(82.91234, 19.243533))) * 2912.454369)); 125 } 126 127 float3 noise3d(float3 p) 128 { 129 return float3(frac(sin(54.343909 + dot(p, float3(12.3453, 54.3353432, 34.3490432))) * 8433.235443), 130 frac(sin(93.329945  dot(p, float3(34.23232, 98.0353743, 90.2390984))) * 8294.5345433), 131 frac(sin(32.039284 + dot(p, float3(82.91234, 19.243533, 22.3294090))) * 2912.454369)); 132 } 133 134 float3 perlin2d(float2 p) 135 { 136 float2 a = floor(p); 137 float2 d = p  a; 138 d = d * d * (3.0  2.0 * d); 139 140 float3 n1 = noise2d(a); 141 float3 n2 = noise2d(a + float2(1.0, 0.0)); 142 float3 n3 = noise2d(a + float2(0.0, 1.0)); 143 float3 n4 = noise2d(a + float2(1.0, 1.0)); 144 145 float3 q1 = n2 * d.x + n1 * (1.0  d.x); 146 float3 q2 = n4 * d.x + n3 * (1.0  d.x); 147 148 float3 q3 = q2 * d.y + q1 * (1.0  d.y); 149 150 return q3; 151 } 152 153 float3 perlin3d(float3 p) 154 { 155 float3x3 r = float3x3(0.36, 0.48, 0.8, 0.8, 0.60, 0.0, 0.48, 0.64, 0.60); 156 p = mul(r, p); 157 158 float3 a = floor(p); 159 float3 d = p  a; 160 d = d * d * (3.0  2.0 * d); 161 162 float3 o1 = noise3d(a); 163 float3 o2 = noise3d(a + float3(1.0, 0.0, 0.0)); 164 float3 o3 = noise3d(a + float3(0.0, 1.0, 0.0)); 165 float3 o4 = noise3d(a + float3(1.0, 1.0, 0.0)); 166 float3 o5 = noise3d(a + float3(0.0, 0.0, 1.0)); 167 float3 o6 = noise3d(a + float3(1.0, 0.0, 1.0)); 168 float3 o7 = noise3d(a + float3(0.0, 1.0, 1.0)); 169 float3 o8 = noise3d(a + float3(1.0, 1.0, 1.0)); 170 171 float3 n1 = o2 * d.x + o1 * (1.0  d.x); 172 float3 n2 = o4 * d.x + o3 * (1.0  d.x); 173 float3 n3 = o6 * d.x + o5 * (1.0  d.x); 174 float3 n4 = o8 * d.x + o7 * (1.0  d.x); 175 176 float3 q1 = n2 * d.y + n1 * (1.0  d.y); 177 float3 q2 = n4 * d.y + n3 * (1.0  d.y); 178 179 float3 q3 = q2 * d.z + q1 * (1.0  d.z); 180 181 return q3; 182 } 183 184 void main(in float2 pass_Position : TEXCOORD0, 185 uniform float u_Time, 186 out float4 out_FragColor : COLOR) 187 { 188 float2 xy = pass_Position; 189 xy.y = u_Time * 400.0; 190 float z = u_Time * 2.0; 191 192 float3 p = perlin3d(float3(xy / 160.0, z)) / 2.0 193 + perlin3d(float3(xy / 80.0, z + 1.5)) / 4.0 194 + perlin3d(float3(xy / 40.0, z + 0.3)) / 8.0 195 + perlin3d(float3(xy / 20.0, z + 3.3)) / 16.0 196 + perlin3d(float3(xy / 10.0, z + 2.0)) / 32.0 197 + perlin3d(float3(xy / 5.0, z + 1.7)) / 64.0 198 + perlin3d(float3(xy / 2.5, z + 4.2)) / 128.0; 199 200 /* Scroll by adding [.5,.5] */ 201 p = pass_Position.y / 1440.0; 202 p = max(p, 0.0); 203 p = min(p, 1.0); 204 205 p = p * p * (3.0  2.0 * p); 206 p = p * p * (3.0  2.0 * p); 207 out_FragColor = float4(min(p.x * 2.0, 1.0), max(p.x * 1.5  0.5, 0.0), 0.0, 1.0); 208 }
Note: See TracChangeset
for help on using the changeset viewer.