Fix T70357: ANT Landscape Line artifacts
[blender-addons.git] / ant_landscape / ant_noise.py
blob7d6b12e8b11c15dd3d13e710413409d9b610cf06
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 # Another Noise Tool - Noise and Effects
20 # Jimmy Hazevoet
22 import bpy
23 from mathutils.noise import (
24 seed_set,
25 noise,
26 turbulence,
27 turbulence_vector,
28 fractal,
29 hybrid_multi_fractal,
30 multi_fractal,
31 ridged_multi_fractal,
32 hetero_terrain,
33 random_unit_vector,
34 variable_lacunarity,
35 voronoi,
37 from math import (
38 floor, sqrt,
39 sin, cos, pi,
42 noise_basis_default = "BLENDER"
43 noise_basis = [
44 ("BLENDER", "Blender", "Blender default noise", 0),
45 ("PERLIN_ORIGINAL", "Perlin", "Perlin noise", 1),
46 ("PERLIN_NEW", "New Perlin", "New Perlin noise", 2),
47 ("VORONOI_F1", "Voronoi F1", "Voronoi F1", 3),
48 ("VORONOI_F2", "Voronoi F2", "Voronoi F2", 4),
49 ("VORONOI_F3", "Voronoi F3", "Voronoi F3", 5),
50 ("VORONOI_F4", "Voronoi F4", "Voronoi F4", 6),
51 ("VORONOI_F2F1", "Voronoi F2-F1", "Voronoi F2-F1", 7),
52 ("VORONOI_CRACKLE", "Voronoi Crackle", "Voronoi Crackle", 8),
53 ("CELLNOISE", "Cell Noise", "Cell noise", 9)
56 # ------------------------------------------------------------
57 # Height scale:
58 def Height_Scale(input, iscale, offset, invert):
59 if invert != 0:
60 return (1.0 - input) * iscale + offset
61 else:
62 return input * iscale + offset
65 # Functions for marble_noise and effects:
67 def Dist(x, y):
68 return sqrt((x * x) + (y * y))
71 def sin_bias(a):
72 return 0.5 + 0.5 * sin(a)
75 def cos_bias(a):
76 return 0.5 + 0.5 * cos(a)
79 def tri_bias(a):
80 b = 2 * pi
81 a = 1 - 2 * abs(floor((a * (1 / b)) + 0.5) - (a * (1 / b)))
82 return a
85 def saw_bias(a):
86 b = 2 * pi
87 n = int(a / b)
88 a -= n * b
89 if a < 0:
90 a += b
91 return a / b
94 def soft(a):
95 return a
98 def sharp(a):
99 return a**0.5
102 def sharper(a):
103 return sharp(sharp(a))
106 def no_bias(a):
107 return a
110 def shapes(x, y, z, shape=0):
111 p = pi
112 if shape == 1:
113 # ring
114 x = x * p
115 y = y * p
116 s = cos(x**2 + y**2) / (x**2 + y**2 + 0.5)
117 elif shape == 2:
118 # swirl
119 x = x * p
120 y = y * p
121 s = ((x * sin(x * x + y * y) + y * cos(x * x + y * y)) / (x**2 + y**2 + 0.5))
122 elif shape == 3:
123 # bumps
124 x = x * p
125 y = y * p
126 z = z * p
127 s = 1 - ((cos(x * p) + cos(y * p) + cos(z * p)) - 0.5)
128 elif shape == 4:
129 # wave
130 x = x * p * 2
131 y = y * p * 2
132 s = sin(x + sin(y))
133 elif shape == 5:
134 # z grad.
135 s = (z * p)
136 elif shape == 6:
137 # y grad.
138 s = (y * p)
139 elif shape == 7:
140 # x grad.
141 s = (x * p)
142 else:
143 # marble default
144 s = ((x + y + z) * 5)
145 return s
148 # marble_noise
149 def marble_noise(x, y, z, origin, size, shape, bias, sharpnes, turb, depth, hard, basis, amp, freq):
151 s = shapes(x, y, z, shape)
152 x += origin[0]
153 y += origin[1]
154 z += origin[2]
155 value = s + turb * turbulence_vector((x, y, z), depth, hard, noise_basis=basis)[1]
157 if bias == 1:
158 value = cos_bias(value)
159 elif bias == 2:
160 value = tri_bias(value)
161 elif bias == 3:
162 value = saw_bias(value)
163 else:
164 value = sin_bias(value)
166 if sharpnes == 1:
167 value = 1.0 - sharp(value)
168 elif sharpnes == 2:
169 value = 1.0 - sharper(value)
170 elif sharpnes == 3:
171 value = soft(value)
172 elif sharpnes == 4:
173 value = sharp(value)
174 elif sharpnes == 5:
175 value = sharper(value)
176 else:
177 value = 1.0 - soft(value)
179 return value
182 # vl_noise_turbulence:
183 def vlnTurbMode(coords, distort, basis, vlbasis, hardnoise):
184 # hard noise
185 if hardnoise:
186 return (abs(-variable_lacunarity(coords, distort, noise_type1=basis, noise_type2=vlbasis)))
187 # soft noise
188 else:
189 return variable_lacunarity(coords, distort, noise_type1=basis, noise_type2=vlbasis)
192 def vl_noise_turbulence(coords, distort, depth, basis, vlbasis, hardnoise, amp, freq):
193 x, y, z = coords
194 value = vlnTurbMode(coords, distort, basis, vlbasis, hardnoise)
196 for i in range(depth):
197 i+=1
198 value += vlnTurbMode((x * (freq * i), y * (freq * i), z * (freq * i)), distort, basis, vlbasis, hardnoise) * (amp * 0.5 / i)
199 return value
202 ## duo_multiFractal:
203 def double_multiFractal(coords, H, lacunarity, octaves, offset, gain, basis, vlbasis):
204 x, y, z = coords
205 n1 = multi_fractal((x * 1.5 + 1, y * 1.5 + 1, z * 1.5 + 1), 1.0, 1.0, 1.0, noise_basis=basis) * (offset * 0.5)
206 n2 = multi_fractal((x - 1, y - 1, z - 1), H, lacunarity, octaves, noise_basis=vlbasis) * (gain * 0.5)
207 return (n1 * n1 + n2 * n2) * 0.5
210 ## distorted_heteroTerrain:
211 def distorted_heteroTerrain(coords, H, lacunarity, octaves, offset, distort, basis, vlbasis):
212 x, y, z = coords
213 h1 = (hetero_terrain((x, y, z), 1.0, 2.0, 1.0, 1.0, noise_basis=basis) * 0.5)
214 d = h1 * distort
215 h2 = (hetero_terrain((x + d, y + d, z + d), H, lacunarity, octaves, offset, noise_basis=vlbasis) * 0.25)
216 return (h1 * h1 + h2 * h2) * 0.5
219 ## SlickRock:
220 def slick_rock(coords, H, lacunarity, octaves, offset, gain, distort, basis, vlbasis):
221 x, y, z = coords
222 n = multi_fractal((x,y,z), 1.0, 2.0, 2.0, noise_basis=basis) * distort * 0.25
223 r = ridged_multi_fractal((x + n, y + n, z + n), H, lacunarity, octaves, offset + 0.1, gain * 2, noise_basis=vlbasis)
224 return (n + (n * r)) * 0.5
227 ## vlhTerrain
228 def vl_hTerrain(coords, H, lacunarity, octaves, offset, basis, vlbasis, distort):
229 x, y, z = coords
230 ht = hetero_terrain((x, y, z), H, lacunarity, octaves, offset, noise_basis=basis ) * 0.25
231 vl = ht * variable_lacunarity((x, y, z), distort, noise_type1=basis, noise_type2=vlbasis) * 0.5 + 0.5
232 return vl * ht
235 # another turbulence
236 def ant_turbulence(coords, depth, hardnoise, nbasis, amp, freq, distortion):
237 x, y, z = coords
238 t = turbulence_vector((x/2, y/2, z/2), depth, 0, noise_basis=nbasis, amplitude_scale=amp, frequency_scale=freq) * 0.5 * distortion
239 return turbulence((t[0], t[1], t[2]), 2, hardnoise, noise_basis="VORONOI_F1") * 0.5 + 0.5
242 # rocks noise
243 def rocks_noise(coords, depth, hardnoise, nbasis, distortion):
244 x,y,z = coords
245 p = turbulence((x, y, z), 4, 0, noise_basis='BLENDER') * 0.125 * distortion
246 xx, yy, zz = x, y, z
247 a = turbulence((xx + p, yy + p, zz), 2, 0, noise_basis='VORONOI_F2F1')
248 pa = a * 0.1875 * distortion
249 b = turbulence((x, y, z + pa), depth, hardnoise, noise_basis=nbasis)
250 return ((a + 0.5 * (b - a)) * 0.5 + 0.5)
253 # shattered_hterrain:
254 def shattered_hterrain(coords, H, lacunarity, octaves, offset, distort, basis):
255 x, y, z = coords
256 d = (turbulence_vector(coords, 6, 0)[0] * 0.5 + 0.5) * distort * 0.5
257 t1 = (turbulence_vector((x + d, y + d, z + d), 0, 0, noise_basis='VORONOI_F2F1')[0] + 0.5)
258 t2 = (hetero_terrain((x * 2, y * 2, z * 2), H, lacunarity, octaves, offset, noise_basis=basis) * 0.5)
259 return ((t1 * t2) + t2 * 0.5) * 0.5
262 # strata_hterrain
263 def strata_hterrain(coords, H, lacunarity, octaves, offset, distort, basis):
264 x, y, z = coords
265 value = hetero_terrain((x, y, z), H, lacunarity, octaves, offset, noise_basis=basis) * 0.5
266 steps = (sin(value * (distort * 5) * pi) * (0.1 / (distort * 5) * pi))
267 return (value * (1.0 - 0.5) + steps * 0.5)
270 # Planet Noise by: Farsthary
271 # https://farsthary.com/2010/11/24/new-planet-procedural-texture/
272 def planet_noise(coords, oct=6, hard=0, noisebasis='PERLIN_ORIGINAL', nabla=0.001):
273 x, y, z = coords
274 d = 0.001
275 offset = nabla * 1000
276 x = turbulence((x, y, z), oct, hard, noise_basis=noisebasis)
277 y = turbulence((x + offset, y, z), oct, hard, noise_basis=noisebasis)
278 z = turbulence((x, y + offset, z), oct, hard, noise_basis=noisebasis)
279 xdy = x - turbulence((x, y + d, z), oct, hard, noise_basis=noisebasis)
280 xdz = x - turbulence((x, y, z + d), oct, hard, noise_basis=noisebasis)
281 ydx = y - turbulence((x + d, y, z), oct, hard, noise_basis=noisebasis)
282 ydz = y - turbulence((x, y, z + d), oct, hard, noise_basis=noisebasis)
283 zdx = z - turbulence((x + d, y, z), oct, hard, noise_basis=noisebasis)
284 zdy = z - turbulence((x, y + d, z), oct, hard, noise_basis=noisebasis)
285 return (zdy - ydz), (zdx - xdz), (ydx - xdy)
288 ###----------------------------------------------------------------------
289 # v.1.04 Effect functions:
291 def maximum(a, b):
292 if (a > b): b = a
293 return b
296 def minimum(a, b):
297 if (a < b): b = a
298 return b
301 def Mix_Modes(a, b, mixfactor, mode):
302 mode = int(mode)
303 a = a * (1.0 - mixfactor)
304 b = b * (1.0 + mixfactor)
305 #1 mix
306 if mode == 0:
307 return (a * (1.0 - 0.5) + b * 0.5)
308 #2 add
309 elif mode == 1:
310 return (a + b)
311 #3 sub.
312 elif mode == 2:
313 return (a - b)
314 #4 mult.
315 elif mode == 3:
316 return (a * b)
317 #5 abs diff.
318 elif mode == 4:
319 return (abs(a - b))
320 #6 screen
321 elif mode == 5:
322 return 1.0 - ((1.0 - a) * (1.0 - b) / 1.0)
323 #7 addmodulo
324 elif mode == 6:
325 return (a + b) % 1.0
326 #8 min.
327 elif mode == 7:
328 return minimum(a, b)
329 #9 max.
330 elif mode == 8:
331 return maximum(a, b)
332 else:
333 return 0
336 Bias_Types = [sin_bias, cos_bias, tri_bias, saw_bias, no_bias]
337 Sharp_Types = [soft, sharp, sharper]
340 # Transpose effect coords:
341 def Trans_Effect(coords, size, loc):
342 x, y, z = coords
343 x = (x * 2.0 / size + loc[0])
344 y = (y * 2.0 / size + loc[1])
345 return x, y, z
348 # Effect_Basis_Function:
349 def Effect_Basis_Function(coords, type, bias):
350 bias = int(bias)
351 type = int(type)
352 x, y, z = coords
353 iscale = 1.0
354 offset = 0.0
356 ## gradient:
357 if type == 1:
358 effect = offset + iscale * (Bias_Types[bias](x + y))
359 ## waves / bumps:
360 elif type == 2:
361 effect = offset + iscale * 0.5 * (Bias_Types[bias](x * pi) + Bias_Types[bias](y * pi))
362 ## zigzag:
363 elif type == 3:
364 effect = offset + iscale * Bias_Types[bias](offset + iscale * sin(x * pi + sin(y * pi)))
365 ## wavy:
366 elif type == 4:
367 effect = offset + iscale * (Bias_Types[bias](cos(x) + sin(y) + cos(x * 2 + y * 2) - sin(-x * 4 + y * 4)))
368 ## sine bump:
369 elif type == 5:
370 effect = offset + iscale * 1 - Bias_Types[bias]((sin(x * pi) + sin(y * pi)))
371 ## dots:
372 elif type == 6:
373 effect = offset + iscale * (Bias_Types[bias](x * pi * 2) * Bias_Types[bias](y * pi * 2)) - 0.5
374 ## rings:
375 elif type == 7:
376 effect = offset + iscale * (Bias_Types[bias ](1.0 - (x * x + y * y)))
377 ## spiral:
378 elif type == 8:
379 effect = offset + iscale * Bias_Types[bias]( (x * sin(x * x + y * y) + y * cos(x * x + y * y)) / (x**2 + y**2 + 0.5)) * 2
380 ## square / piramide:
381 elif type == 9:
382 effect = offset + iscale * Bias_Types[bias](1.0 - sqrt((x * x)**10 + (y * y)**10)**0.1)
383 ## blocks:
384 elif type == 10:
385 effect = (0.5 - max(Bias_Types[bias](x * pi) , Bias_Types[bias](y * pi)))
386 if effect > 0.0:
387 effect = 1.0
388 effect = offset + iscale * effect
389 ## grid:
390 elif type == 11:
391 effect = (0.025 - min(Bias_Types[bias](x * pi), Bias_Types[bias](y * pi)))
392 if effect > 0.0:
393 effect = 1.0
394 effect = offset + iscale * effect
395 ## tech:
396 elif type == 12:
397 a = max(Bias_Types[bias](x * pi), Bias_Types[bias](y * pi))
398 b = max(Bias_Types[bias](x * pi * 2 + 2), Bias_Types[bias](y * pi * 2 + 2))
399 effect = min(Bias_Types[bias](a), Bias_Types[bias](b)) * 3.0 - 2.0
400 if effect > 0.5:
401 effect = 1.0
402 effect = offset + iscale * effect
403 ## crackle:
404 elif type == 13:
405 t = turbulence((x, y, 0), 6, 0, noise_basis="BLENDER") * 0.25
406 effect = variable_lacunarity((x, y, t), 0.25, noise_type2='VORONOI_CRACKLE')
407 if effect > 0.5:
408 effect = 0.5
409 effect = offset + iscale * effect
410 ## sparse cracks noise:
411 elif type == 14:
412 effect = 2.5 * abs(noise((x, y, 0), noise_basis="PERLIN_ORIGINAL")) - 0.1
413 if effect > 0.25:
414 effect = 0.25
415 effect = offset + iscale * (effect * 2.5)
416 ## shattered rock noise:
417 elif type == 15:
418 effect = 0.5 + noise((x, y, 0), noise_basis="VORONOI_F2F1")
419 if effect > 0.75:
420 effect = 0.75
421 effect = offset + iscale * effect
422 ## lunar noise:
423 elif type == 16:
424 effect = 0.25 + 1.5 * voronoi((x, y, 0), distance_metric='DISTANCE_SQUARED')[0][0]
425 if effect > 0.5:
426 effect = 0.5
427 effect = offset + iscale * effect * 2
428 ## cosine noise:
429 elif type == 17:
430 effect = cos(5 * noise((x, y, 0), noise_basis="BLENDER"))
431 effect = offset + iscale * (effect * 0.5)
432 ## spikey noise:
433 elif type == 18:
434 n = 0.5 + 0.5 * turbulence((x * 5, y * 5, 0), 8, 0, noise_basis="BLENDER")
435 effect = ((n * n)**5)
436 effect = offset + iscale * effect
437 ## stone noise:
438 elif type == 19:
439 effect = offset + iscale * (noise((x * 2, y * 2, 0), noise_basis="BLENDER") * 1.5 - 0.75)
440 ## Flat Turb:
441 elif type == 20:
442 t = turbulence((x, y, 0), 6, 0, noise_basis="BLENDER")
443 effect = t * 2.0
444 if effect > 0.25:
445 effect = 0.25
446 effect = offset + iscale * effect
447 ## Flat Voronoi:
448 elif type == 21:
449 t = 1 - voronoi((x, y, 0), distance_metric='DISTANCE_SQUARED')[0][0]
450 effect = t * 2 - 1.5
451 if effect > 0.25:
452 effect = 0.25
453 effect = offset + iscale * effect
454 else:
455 effect = 0.0
457 if effect < 0.0:
458 effect = 0.0
460 return effect
463 # fractalize Effect_Basis_Function: ------------------------------
464 def Effect_Function(coords, type, bias, turb, depth, frequency, amplitude):
466 x, y, z = coords
467 ## turbulence:
468 if turb > 0.0:
469 t = turb * ( 0.5 + 0.5 * turbulence(coords, 6, 0, noise_basis="BLENDER"))
470 x = x + t
471 y = y + t
472 z = z + t
474 result = Effect_Basis_Function((x, y, z), type, bias) * amplitude
475 ## fractalize:
476 if depth != 0:
478 for i in range(depth):
479 i+=1
480 x *= frequency
481 y *= frequency
482 result += Effect_Basis_Function((x, y, z), type, bias) * amplitude / i
484 return result
487 # ------------------------------------------------------------
488 # landscape_gen
489 def noise_gen(coords, props):
491 terrain_name = props[0]
492 cursor = props[1]
493 smooth = props[2]
494 triface = props[3]
495 sphere = props[4]
496 land_mat = props[5]
497 water_mat = props[6]
498 texture_name = props[7]
499 subd_x = props[8]
500 subd_y = props[9]
501 meshsize_x = props[10]
502 meshsize_y = props[11]
503 meshsize = props[12]
504 rseed = props[13]
505 x_offset = props[14]
506 y_offset = props[15]
507 z_offset = props[16]
508 size_x = props[17]
509 size_y = props[18]
510 size_z = props[19]
511 nsize = props[20]
512 ntype = props[21]
513 nbasis = props[22]
514 vlbasis = props[23]
515 distortion = props[24]
516 hardnoise = int(props[25])
517 depth = props[26]
518 amp = props[27]
519 freq = props[28]
520 dimension = props[29]
521 lacunarity = props[30]
522 offset = props[31]
523 gain = props[32]
524 marblebias = int(props[33])
525 marblesharpnes = int(props[34])
526 marbleshape = int(props[35])
527 height = props[36]
528 height_invert = props[37]
529 height_offset = props[38]
530 maximum = props[39]
531 minimum = props[40]
532 falloff = int(props[41])
533 edge_level = props[42]
534 falloffsize_x = props[43]
535 falloffsize_y = props[44]
536 stratatype = props[45]
537 strata = props[46]
538 addwater = props[47]
539 waterlevel = props[48]
540 vert_group = props[49]
541 remove_double = props[50]
542 fx_mixfactor = props[51]
543 fx_mix_mode = props[52]
544 fx_type = props[53]
545 fx_bias = props[54]
546 fx_turb = props[55]
547 fx_depth = props[56]
548 fx_frequency = props[57]
549 fx_amplitude = props[58]
550 fx_size = props[59]
551 fx_loc_x = props[60]
552 fx_loc_y = props[61]
553 fx_height = props[62]
554 fx_offset = props[63]
555 fx_invert = props[64]
557 x, y, z = coords
559 # Origin
560 if rseed == 0:
561 origin = x_offset, y_offset, z_offset
562 origin_x = x_offset
563 origin_y = y_offset
564 origin_z = z_offset
565 o_range = 1.0
566 else:
567 # Randomise origin
568 o_range = 100
569 seed_set(rseed)
570 origin = random_unit_vector()
571 ox = (origin[0] * o_range)
572 oy = (origin[1] * o_range)
573 oz = 0
574 origin_x = (ox - (ox * 0.5)) + x_offset
575 origin_y = (oy - (oy * 0.5)) + y_offset
576 origin_z = oz + z_offset
578 ncoords = (x / (nsize * size_x) + origin_x, y / (nsize * size_y) + origin_y, z / (nsize * size_z) + origin_z)
580 # Noise type's
581 if ntype in [0, 'multi_fractal']:
582 value = multi_fractal(ncoords, dimension, lacunarity, depth, noise_basis=nbasis) * 0.5
584 elif ntype in [1, 'ridged_multi_fractal']:
585 value = ridged_multi_fractal(ncoords, dimension, lacunarity, depth, offset, gain, noise_basis=nbasis) * 0.5
587 elif ntype in [2, 'hybrid_multi_fractal']:
588 value = hybrid_multi_fractal(ncoords, dimension, lacunarity, depth, offset, gain, noise_basis=nbasis) * 0.5
590 elif ntype in [3, 'hetero_terrain']:
591 value = hetero_terrain(ncoords, dimension, lacunarity, depth, offset, noise_basis=nbasis) * 0.25
593 elif ntype in [4, 'fractal']:
594 value = fractal(ncoords, dimension, lacunarity, depth, noise_basis=nbasis)
596 elif ntype in [5, 'turbulence_vector']:
597 value = turbulence_vector(ncoords, depth, hardnoise, noise_basis=nbasis, amplitude_scale=amp, frequency_scale=freq)[0]
599 elif ntype in [6, 'variable_lacunarity']:
600 value = variable_lacunarity(ncoords, distortion, noise_type1=nbasis, noise_type2=vlbasis)
602 elif ntype in [7, 'marble_noise']:
603 value = marble_noise(
604 (ncoords[0] - origin_x + x_offset),
605 (ncoords[1] - origin_y + y_offset),
606 (ncoords[2] - origin_z + z_offset),
607 (origin[0] + x_offset, origin[1] + y_offset, origin[2] + z_offset), nsize,
608 marbleshape, marblebias, marblesharpnes,
609 distortion, depth, hardnoise, nbasis, amp, freq
611 elif ntype in [8, 'shattered_hterrain']:
612 value = shattered_hterrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis)
614 elif ntype in [9, 'strata_hterrain']:
615 value = strata_hterrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis)
617 elif ntype in [10, 'ant_turbulence']:
618 value = ant_turbulence(ncoords, depth, hardnoise, nbasis, amp, freq, distortion)
620 elif ntype in [11, 'vl_noise_turbulence']:
621 value = vl_noise_turbulence(ncoords, distortion, depth, nbasis, vlbasis, hardnoise, amp, freq)
623 elif ntype in [12, 'vl_hTerrain']:
624 value = vl_hTerrain(ncoords, dimension, lacunarity, depth, offset, nbasis, vlbasis, distortion)
626 elif ntype in [13, 'distorted_heteroTerrain']:
627 value = distorted_heteroTerrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis, vlbasis)
629 elif ntype in [14, 'double_multiFractal']:
630 value = double_multiFractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis, vlbasis)
632 elif ntype in [15, 'rocks_noise']:
633 value = rocks_noise(ncoords, depth, hardnoise, nbasis, distortion)
635 elif ntype in [16, 'slick_rock']:
636 value = slick_rock(ncoords,dimension, lacunarity, depth, offset, gain, distortion, nbasis, vlbasis)
638 elif ntype in [17, 'planet_noise']:
639 value = planet_noise(ncoords, depth, hardnoise, nbasis)[2] * 0.5 + 0.5
641 elif ntype in [18, 'blender_texture']:
642 if texture_name != "" and texture_name in bpy.data.textures:
643 value = bpy.data.textures[texture_name].evaluate(ncoords)[3]
644 else:
645 value = 0.0
646 else:
647 value = 0.5
649 # Effect mix
650 val = value
651 if fx_type in [0,"0"]:
652 fx_mixfactor = -1.0
653 fxval = val
654 else:
655 fxcoords = Trans_Effect((x, y, z), fx_size, (fx_loc_x, fx_loc_y))
656 effect = Effect_Function(fxcoords, fx_type, fx_bias, fx_turb, fx_depth, fx_frequency, fx_amplitude)
657 effect = Height_Scale(effect, fx_height, fx_offset, fx_invert)
658 fxval = Mix_Modes(val, effect, fx_mixfactor, fx_mix_mode)
659 value = fxval
661 # Adjust height
662 value = Height_Scale(value, height, height_offset, height_invert)
664 # Edge falloff:
665 if not sphere:
666 if falloff:
667 ratio_x, ratio_y = abs(x) * 2 / meshsize_x, abs(y) * 2 / meshsize_y
668 fallofftypes = [0,
669 sqrt(ratio_y**falloffsize_y),
670 sqrt(ratio_x**falloffsize_x),
671 sqrt(ratio_x**falloffsize_x + ratio_y**falloffsize_y)
673 dist = fallofftypes[falloff]
674 value -= edge_level
675 if(dist < 1.0):
676 dist = (dist * dist * (3 - 2 * dist))
677 value = (value - value * dist) + edge_level
678 else:
679 value = edge_level
681 # Strata / terrace / layers
682 if stratatype not in [0, "0"]:
683 if stratatype in [1, "1"]:
684 strata = strata / height
685 strata *= 2
686 steps = (sin(value * strata * pi) * (0.1 / strata * pi))
687 value = (value * 0.5 + steps * 0.5) * 2.0
689 elif stratatype in [2, "2"]:
690 strata = strata / height
691 steps = -abs(sin(value * strata * pi) * (0.1 / strata * pi))
692 value = (value * 0.5 + steps * 0.5) * 2.0
694 elif stratatype in [3, "3"]:
695 strata = strata / height
696 steps = abs(sin(value * strata * pi) * (0.1 / strata * pi))
697 value = (value * 0.5 + steps * 0.5) * 2.0
699 elif stratatype in [4, "4"]:
700 strata = strata / height
701 value = int( value * strata ) * 1.0 / strata
703 elif stratatype in [5, "5"]:
704 strata = strata / height
705 steps = (int( value * strata ) * 1.0 / strata)
706 value = (value * (1.0 - 0.5) + steps * 0.5)
708 # Clamp height min max
709 if (value < minimum):
710 value = minimum
711 if (value > maximum):
712 value = maximum
714 return value