Blender  V3.3
noise.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 #include <math.h>
9 
10 #include "BLI_compiler_compat.h"
11 #include "BLI_sys_types.h"
12 
13 #include "BLI_noise.h" /* Own include. */
14 
15 /* local */
16 static float noise3_perlin(const float vec[3]);
17 // static float turbulence_perlin(const float point[3], float lofreq, float hifreq);
18 // static float turbulencep(float noisesize, float x, float y, float z, int nr);
19 
20 /* UNUSED */
21 // #define HASHVEC(x, y, z) hashvectf + 3 * hash[(hash[(hash[(z) & 255] + (y)) & 255] + (x)) & 255]
22 
23 /* -------------------------------------------------------------------- */
27 /* needed for voronoi */
28 #define HASHPNT(x, y, z) hashpntf + 3 * hash[(hash[(hash[(z)&255] + (y)) & 255] + (x)) & 255]
29 static const float hashpntf[768] = {
30  0.536902, 0.020915, 0.501445, 0.216316, 0.517036, 0.822466, 0.965315, 0.377313, 0.678764,
31  0.744545, 0.097731, 0.396357, 0.247202, 0.520897, 0.613396, 0.542124, 0.146813, 0.255489,
32  0.810868, 0.638641, 0.980742, 0.292316, 0.357948, 0.114382, 0.861377, 0.629634, 0.722530,
33  0.714103, 0.048549, 0.075668, 0.564920, 0.162026, 0.054466, 0.411738, 0.156897, 0.887657,
34  0.599368, 0.074249, 0.170277, 0.225799, 0.393154, 0.301348, 0.057434, 0.293849, 0.442745,
35  0.150002, 0.398732, 0.184582, 0.915200, 0.630984, 0.974040, 0.117228, 0.795520, 0.763238,
36  0.158982, 0.616211, 0.250825, 0.906539, 0.316874, 0.676205, 0.234720, 0.667673, 0.792225,
37  0.273671, 0.119363, 0.199131, 0.856716, 0.828554, 0.900718, 0.705960, 0.635923, 0.989433,
38  0.027261, 0.283507, 0.113426, 0.388115, 0.900176, 0.637741, 0.438802, 0.715490, 0.043692,
39  0.202640, 0.378325, 0.450325, 0.471832, 0.147803, 0.906899, 0.524178, 0.784981, 0.051483,
40  0.893369, 0.596895, 0.275635, 0.391483, 0.844673, 0.103061, 0.257322, 0.708390, 0.504091,
41  0.199517, 0.660339, 0.376071, 0.038880, 0.531293, 0.216116, 0.138672, 0.907737, 0.807994,
42  0.659582, 0.915264, 0.449075, 0.627128, 0.480173, 0.380942, 0.018843, 0.211808, 0.569701,
43  0.082294, 0.689488, 0.573060, 0.593859, 0.216080, 0.373159, 0.108117, 0.595539, 0.021768,
44  0.380297, 0.948125, 0.377833, 0.319699, 0.315249, 0.972805, 0.792270, 0.445396, 0.845323,
45  0.372186, 0.096147, 0.689405, 0.423958, 0.055675, 0.117940, 0.328456, 0.605808, 0.631768,
46  0.372170, 0.213723, 0.032700, 0.447257, 0.440661, 0.728488, 0.299853, 0.148599, 0.649212,
47  0.498381, 0.049921, 0.496112, 0.607142, 0.562595, 0.990246, 0.739659, 0.108633, 0.978156,
48  0.209814, 0.258436, 0.876021, 0.309260, 0.600673, 0.713597, 0.576967, 0.641402, 0.853930,
49  0.029173, 0.418111, 0.581593, 0.008394, 0.589904, 0.661574, 0.979326, 0.275724, 0.111109,
50  0.440472, 0.120839, 0.521602, 0.648308, 0.284575, 0.204501, 0.153286, 0.822444, 0.300786,
51  0.303906, 0.364717, 0.209038, 0.916831, 0.900245, 0.600685, 0.890002, 0.581660, 0.431154,
52  0.705569, 0.551250, 0.417075, 0.403749, 0.696652, 0.292652, 0.911372, 0.690922, 0.323718,
53  0.036773, 0.258976, 0.274265, 0.225076, 0.628965, 0.351644, 0.065158, 0.080340, 0.467271,
54  0.130643, 0.385914, 0.919315, 0.253821, 0.966163, 0.017439, 0.392610, 0.478792, 0.978185,
55  0.072691, 0.982009, 0.097987, 0.731533, 0.401233, 0.107570, 0.349587, 0.479122, 0.700598,
56  0.481751, 0.788429, 0.706864, 0.120086, 0.562691, 0.981797, 0.001223, 0.192120, 0.451543,
57  0.173092, 0.108960, 0.549594, 0.587892, 0.657534, 0.396365, 0.125153, 0.666420, 0.385823,
58  0.890916, 0.436729, 0.128114, 0.369598, 0.759096, 0.044677, 0.904752, 0.088052, 0.621148,
59  0.005047, 0.452331, 0.162032, 0.494238, 0.523349, 0.741829, 0.698450, 0.452316, 0.563487,
60  0.819776, 0.492160, 0.004210, 0.647158, 0.551475, 0.362995, 0.177937, 0.814722, 0.727729,
61  0.867126, 0.997157, 0.108149, 0.085726, 0.796024, 0.665075, 0.362462, 0.323124, 0.043718,
62  0.042357, 0.315030, 0.328954, 0.870845, 0.683186, 0.467922, 0.514894, 0.809971, 0.631979,
63  0.176571, 0.366320, 0.850621, 0.505555, 0.749551, 0.750830, 0.401714, 0.481216, 0.438393,
64  0.508832, 0.867971, 0.654581, 0.058204, 0.566454, 0.084124, 0.548539, 0.902690, 0.779571,
65  0.562058, 0.048082, 0.863109, 0.079290, 0.713559, 0.783496, 0.265266, 0.672089, 0.786939,
66  0.143048, 0.086196, 0.876129, 0.408708, 0.229312, 0.629995, 0.206665, 0.207308, 0.710079,
67  0.341704, 0.264921, 0.028748, 0.629222, 0.470173, 0.726228, 0.125243, 0.328249, 0.794187,
68  0.741340, 0.489895, 0.189396, 0.724654, 0.092841, 0.039809, 0.860126, 0.247701, 0.655331,
69  0.964121, 0.672536, 0.044522, 0.690567, 0.837238, 0.631520, 0.953734, 0.352484, 0.289026,
70  0.034152, 0.852575, 0.098454, 0.795529, 0.452181, 0.826159, 0.186993, 0.820725, 0.440328,
71  0.922137, 0.704592, 0.915437, 0.738183, 0.733461, 0.193798, 0.929213, 0.161390, 0.318547,
72  0.888751, 0.430968, 0.740837, 0.193544, 0.872253, 0.563074, 0.274598, 0.347805, 0.666176,
73  0.449831, 0.800991, 0.588727, 0.052296, 0.714761, 0.420620, 0.570325, 0.057550, 0.210888,
74  0.407312, 0.662848, 0.924382, 0.895958, 0.775198, 0.688605, 0.025721, 0.301913, 0.791408,
75  0.500602, 0.831984, 0.828509, 0.642093, 0.494174, 0.525880, 0.446365, 0.440063, 0.763114,
76  0.630358, 0.223943, 0.333806, 0.906033, 0.498306, 0.241278, 0.427640, 0.772683, 0.198082,
77  0.225379, 0.503894, 0.436599, 0.016503, 0.803725, 0.189878, 0.291095, 0.499114, 0.151573,
78  0.079031, 0.904618, 0.708535, 0.273900, 0.067419, 0.317124, 0.936499, 0.716511, 0.543845,
79  0.939909, 0.826574, 0.715090, 0.154864, 0.750150, 0.845808, 0.648108, 0.556564, 0.644757,
80  0.140873, 0.799167, 0.632989, 0.444245, 0.471978, 0.435910, 0.359793, 0.216241, 0.007633,
81  0.337236, 0.857863, 0.380247, 0.092517, 0.799973, 0.919000, 0.296798, 0.096989, 0.854831,
82  0.165369, 0.568475, 0.216855, 0.020457, 0.835511, 0.538039, 0.999742, 0.620226, 0.244053,
83  0.060399, 0.323007, 0.294874, 0.988899, 0.384919, 0.735655, 0.773428, 0.549776, 0.292882,
84  0.660611, 0.593507, 0.621118, 0.175269, 0.682119, 0.794493, 0.868197, 0.632150, 0.807823,
85  0.509656, 0.482035, 0.001780, 0.259126, 0.358002, 0.280263, 0.192985, 0.290367, 0.208111,
86  0.917633, 0.114422, 0.925491, 0.981110, 0.255570, 0.974862, 0.016629, 0.552599, 0.575741,
87  0.612978, 0.615965, 0.803615, 0.772334, 0.089745, 0.838812, 0.634542, 0.113709, 0.755832,
88  0.577589, 0.667489, 0.529834, 0.325660, 0.817597, 0.316557, 0.335093, 0.737363, 0.260951,
89  0.737073, 0.049540, 0.735541, 0.988891, 0.299116, 0.147695, 0.417271, 0.940811, 0.524160,
90  0.857968, 0.176403, 0.244835, 0.485759, 0.033353, 0.280319, 0.750688, 0.755809, 0.924208,
91  0.095956, 0.962504, 0.275584, 0.173715, 0.942716, 0.706721, 0.078464, 0.576716, 0.804667,
92  0.559249, 0.900611, 0.646904, 0.432111, 0.927885, 0.383277, 0.269973, 0.114244, 0.574867,
93  0.150703, 0.241855, 0.272871, 0.199950, 0.079719, 0.868566, 0.962833, 0.789122, 0.320025,
94  0.905554, 0.234876, 0.991356, 0.061913, 0.732911, 0.785960, 0.874074, 0.069035, 0.658632,
95  0.309901, 0.023676, 0.791603, 0.764661, 0.661278, 0.319583, 0.829650, 0.117091, 0.903124,
96  0.982098, 0.161631, 0.193576, 0.670428, 0.857390, 0.003760, 0.572578, 0.222162, 0.114551,
97  0.420118, 0.530404, 0.470682, 0.525527, 0.764281, 0.040596, 0.443275, 0.501124, 0.816161,
98  0.417467, 0.332172, 0.447565, 0.614591, 0.559246, 0.805295, 0.226342, 0.155065, 0.714630,
99  0.160925, 0.760001, 0.453456, 0.093869, 0.406092, 0.264801, 0.720370, 0.743388, 0.373269,
100  0.403098, 0.911923, 0.897249, 0.147038, 0.753037, 0.516093, 0.739257, 0.175018, 0.045768,
101  0.735857, 0.801330, 0.927708, 0.240977, 0.591870, 0.921831, 0.540733, 0.149100, 0.423152,
102  0.806876, 0.397081, 0.061100, 0.811630, 0.044899, 0.460915, 0.961202, 0.822098, 0.971524,
103  0.867608, 0.773604, 0.226616, 0.686286, 0.926972, 0.411613, 0.267873, 0.081937, 0.226124,
104  0.295664, 0.374594, 0.533240, 0.237876, 0.669629, 0.599083, 0.513081, 0.878719, 0.201577,
105  0.721296, 0.495038, 0.079760, 0.965959, 0.233090, 0.052496, 0.714748, 0.887844, 0.308724,
106  0.972885, 0.723337, 0.453089, 0.914474, 0.704063, 0.823198, 0.834769, 0.906561, 0.919600,
107  0.100601, 0.307564, 0.901977, 0.468879, 0.265376, 0.885188, 0.683875, 0.868623, 0.081032,
108  0.466835, 0.199087, 0.663437, 0.812241, 0.311337, 0.821361, 0.356628, 0.898054, 0.160781,
109  0.222539, 0.714889, 0.490287, 0.984915, 0.951755, 0.964097, 0.641795, 0.815472, 0.852732,
110  0.862074, 0.051108, 0.440139, 0.323207, 0.517171, 0.562984, 0.115295, 0.743103, 0.977914,
111  0.337596, 0.440694, 0.535879, 0.959427, 0.351427, 0.704361, 0.010826, 0.131162, 0.577080,
112  0.349572, 0.774892, 0.425796, 0.072697, 0.500001, 0.267322, 0.909654, 0.206176, 0.223987,
113  0.937698, 0.323423, 0.117501, 0.490308, 0.474372, 0.689943, 0.168671, 0.719417, 0.188928,
114  0.330464, 0.265273, 0.446271, 0.171933, 0.176133, 0.474616, 0.140182, 0.114246, 0.905043,
115  0.713870, 0.555261, 0.951333,
116 };
117 
118 extern const unsigned char BLI_noise_hash_uchar_512[512]; /* Quiet warning. */
119 const unsigned char BLI_noise_hash_uchar_512[512] = {
120  0xA2, 0xA0, 0x19, 0x3B, 0xF8, 0xEB, 0xAA, 0xEE, 0xF3, 0x1C, 0x67, 0x28, 0x1D, 0xED, 0x0, 0xDE,
121  0x95, 0x2E, 0xDC, 0x3F, 0x3A, 0x82, 0x35, 0x4D, 0x6C, 0xBA, 0x36, 0xD0, 0xF6, 0xC, 0x79, 0x32,
122  0xD1, 0x59, 0xF4, 0x8, 0x8B, 0x63, 0x89, 0x2F, 0xB8, 0xB4, 0x97, 0x83, 0xF2, 0x8F, 0x18, 0xC7,
123  0x51, 0x14, 0x65, 0x87, 0x48, 0x20, 0x42, 0xA8, 0x80, 0xB5, 0x40, 0x13, 0xB2, 0x22, 0x7E, 0x57,
124  0xBC, 0x7F, 0x6B, 0x9D, 0x86, 0x4C, 0xC8, 0xDB, 0x7C, 0xD5, 0x25, 0x4E, 0x5A, 0x55, 0x74, 0x50,
125  0xCD, 0xB3, 0x7A, 0xBB, 0xC3, 0xCB, 0xB6, 0xE2, 0xE4, 0xEC, 0xFD, 0x98, 0xB, 0x96, 0xD3, 0x9E,
126  0x5C, 0xA1, 0x64, 0xF1, 0x81, 0x61, 0xE1, 0xC4, 0x24, 0x72, 0x49, 0x8C, 0x90, 0x4B, 0x84, 0x34,
127  0x38, 0xAB, 0x78, 0xCA, 0x1F, 0x1, 0xD7, 0x93, 0x11, 0xC1, 0x58, 0xA9, 0x31, 0xF9, 0x44, 0x6D,
128  0xBF, 0x33, 0x9C, 0x5F, 0x9, 0x94, 0xA3, 0x85, 0x6, 0xC6, 0x9A, 0x1E, 0x7B, 0x46, 0x15, 0x30,
129  0x27, 0x2B, 0x1B, 0x71, 0x3C, 0x5B, 0xD6, 0x6F, 0x62, 0xAC, 0x4F, 0xC2, 0xC0, 0xE, 0xB1, 0x23,
130  0xA7, 0xDF, 0x47, 0xB0, 0x77, 0x69, 0x5, 0xE9, 0xE6, 0xE7, 0x76, 0x73, 0xF, 0xFE, 0x6E, 0x9B,
131  0x56, 0xEF, 0x12, 0xA5, 0x37, 0xFC, 0xAE, 0xD9, 0x3, 0x8E, 0xDD, 0x10, 0xB9, 0xCE, 0xC9, 0x8D,
132  0xDA, 0x2A, 0xBD, 0x68, 0x17, 0x9F, 0xBE, 0xD4, 0xA, 0xCC, 0xD2, 0xE8, 0x43, 0x3D, 0x70, 0xB7,
133  0x2, 0x7D, 0x99, 0xD8, 0xD, 0x60, 0x8A, 0x4, 0x2C, 0x3E, 0x92, 0xE5, 0xAF, 0x53, 0x7, 0xE0,
134  0x29, 0xA6, 0xC5, 0xE3, 0xF5, 0xF7, 0x4A, 0x41, 0x26, 0x6A, 0x16, 0x5E, 0x52, 0x2D, 0x21, 0xAD,
135  0xF0, 0x91, 0xFF, 0xEA, 0x54, 0xFA, 0x66, 0x1A, 0x45, 0x39, 0xCF, 0x75, 0xA4, 0x88, 0xFB, 0x5D,
136  0xA2, 0xA0, 0x19, 0x3B, 0xF8, 0xEB, 0xAA, 0xEE, 0xF3, 0x1C, 0x67, 0x28, 0x1D, 0xED, 0x0, 0xDE,
137  0x95, 0x2E, 0xDC, 0x3F, 0x3A, 0x82, 0x35, 0x4D, 0x6C, 0xBA, 0x36, 0xD0, 0xF6, 0xC, 0x79, 0x32,
138  0xD1, 0x59, 0xF4, 0x8, 0x8B, 0x63, 0x89, 0x2F, 0xB8, 0xB4, 0x97, 0x83, 0xF2, 0x8F, 0x18, 0xC7,
139  0x51, 0x14, 0x65, 0x87, 0x48, 0x20, 0x42, 0xA8, 0x80, 0xB5, 0x40, 0x13, 0xB2, 0x22, 0x7E, 0x57,
140  0xBC, 0x7F, 0x6B, 0x9D, 0x86, 0x4C, 0xC8, 0xDB, 0x7C, 0xD5, 0x25, 0x4E, 0x5A, 0x55, 0x74, 0x50,
141  0xCD, 0xB3, 0x7A, 0xBB, 0xC3, 0xCB, 0xB6, 0xE2, 0xE4, 0xEC, 0xFD, 0x98, 0xB, 0x96, 0xD3, 0x9E,
142  0x5C, 0xA1, 0x64, 0xF1, 0x81, 0x61, 0xE1, 0xC4, 0x24, 0x72, 0x49, 0x8C, 0x90, 0x4B, 0x84, 0x34,
143  0x38, 0xAB, 0x78, 0xCA, 0x1F, 0x1, 0xD7, 0x93, 0x11, 0xC1, 0x58, 0xA9, 0x31, 0xF9, 0x44, 0x6D,
144  0xBF, 0x33, 0x9C, 0x5F, 0x9, 0x94, 0xA3, 0x85, 0x6, 0xC6, 0x9A, 0x1E, 0x7B, 0x46, 0x15, 0x30,
145  0x27, 0x2B, 0x1B, 0x71, 0x3C, 0x5B, 0xD6, 0x6F, 0x62, 0xAC, 0x4F, 0xC2, 0xC0, 0xE, 0xB1, 0x23,
146  0xA7, 0xDF, 0x47, 0xB0, 0x77, 0x69, 0x5, 0xE9, 0xE6, 0xE7, 0x76, 0x73, 0xF, 0xFE, 0x6E, 0x9B,
147  0x56, 0xEF, 0x12, 0xA5, 0x37, 0xFC, 0xAE, 0xD9, 0x3, 0x8E, 0xDD, 0x10, 0xB9, 0xCE, 0xC9, 0x8D,
148  0xDA, 0x2A, 0xBD, 0x68, 0x17, 0x9F, 0xBE, 0xD4, 0xA, 0xCC, 0xD2, 0xE8, 0x43, 0x3D, 0x70, 0xB7,
149  0x2, 0x7D, 0x99, 0xD8, 0xD, 0x60, 0x8A, 0x4, 0x2C, 0x3E, 0x92, 0xE5, 0xAF, 0x53, 0x7, 0xE0,
150  0x29, 0xA6, 0xC5, 0xE3, 0xF5, 0xF7, 0x4A, 0x41, 0x26, 0x6A, 0x16, 0x5E, 0x52, 0x2D, 0x21, 0xAD,
151  0xF0, 0x91, 0xFF, 0xEA, 0x54, 0xFA, 0x66, 0x1A, 0x45, 0x39, 0xCF, 0x75, 0xA4, 0x88, 0xFB, 0x5D,
152 };
153 #define hash BLI_noise_hash_uchar_512
154 
155 static const float hashvectf[768] = {
156  0.33783, 0.715698, -0.611206, -0.944031, -0.326599, -0.045624, -0.101074, -0.416443,
157  -0.903503, 0.799286, 0.49411, -0.341949, -0.854645, 0.518036, 0.033936, 0.42514,
158  -0.437866, -0.792114, -0.358948, 0.597046, 0.717377, -0.985413, 0.144714, 0.089294,
159  -0.601776, -0.33728, -0.723907, -0.449921, 0.594513, 0.666382, 0.208313, -0.10791,
160  0.972076, 0.575317, 0.060425, 0.815643, 0.293365, -0.875702, -0.383453, 0.293762,
161  0.465759, 0.834686, -0.846008, -0.233398, -0.47934, -0.115814, 0.143036, -0.98291,
162  0.204681, -0.949036, -0.239532, 0.946716, -0.263947, 0.184326, -0.235596, 0.573822,
163  0.784332, 0.203705, -0.372253, -0.905487, 0.756989, -0.651031, 0.055298, 0.497803,
164  0.814697, -0.297363, -0.16214, 0.063995, -0.98468, -0.329254, 0.834381, 0.441925,
165  0.703827, -0.527039, -0.476227, 0.956421, 0.266113, 0.119781, 0.480133, 0.482849,
166  0.7323, -0.18631, 0.961212, -0.203125, -0.748474, -0.656921, -0.090393, -0.085052,
167  -0.165253, 0.982544, -0.76947, 0.628174, -0.115234, 0.383148, 0.537659, 0.751068,
168  0.616486, -0.668488, -0.415924, -0.259979, -0.630005, 0.73175, 0.570953, -0.087952,
169  0.816223, -0.458008, 0.023254, 0.888611, -0.196167, 0.976563, -0.088287, -0.263885,
170  -0.69812, -0.665527, 0.437134, -0.892273, -0.112793, -0.621674, -0.230438, 0.748566,
171  0.232422, 0.900574, -0.367249, 0.22229, -0.796143, 0.562744, -0.665497, -0.73764,
172  0.11377, 0.670135, 0.704803, 0.232605, 0.895599, 0.429749, -0.114655, -0.11557,
173  -0.474243, 0.872742, 0.621826, 0.604004, -0.498444, -0.832214, 0.012756, 0.55426,
174  -0.702484, 0.705994, -0.089661, -0.692017, 0.649292, 0.315399, -0.175995, -0.977997,
175  0.111877, 0.096954, -0.04953, 0.994019, 0.635284, -0.606689, -0.477783, -0.261261,
176  -0.607422, -0.750153, 0.983276, 0.165436, 0.075958, -0.29837, 0.404083, -0.864655,
177  -0.638672, 0.507721, 0.578156, 0.388214, 0.412079, 0.824249, 0.556183, -0.208832,
178  0.804352, 0.778442, 0.562012, 0.27951, -0.616577, 0.781921, -0.091522, 0.196289,
179  0.051056, 0.979187, -0.121216, 0.207153, -0.970734, -0.173401, -0.384735, 0.906555,
180  0.161499, -0.723236, -0.671387, 0.178497, -0.006226, -0.983887, -0.126038, 0.15799,
181  0.97934, 0.830475, -0.024811, 0.556458, -0.510132, -0.76944, 0.384247, 0.81424,
182  0.200104, -0.544891, -0.112549, -0.393311, -0.912445, 0.56189, 0.152222, -0.813049,
183  0.198914, -0.254517, -0.946381, -0.41217, 0.690979, -0.593811, -0.407257, 0.324524,
184  0.853668, -0.690186, 0.366119, -0.624115, -0.428345, 0.844147, -0.322296, -0.21228,
185  -0.297546, -0.930756, -0.273071, 0.516113, 0.811798, 0.928314, 0.371643, 0.007233,
186  0.785828, -0.479218, -0.390778, -0.704895, 0.058929, 0.706818, 0.173248, 0.203583,
187  0.963562, 0.422211, -0.904297, -0.062469, -0.363312, -0.182465, 0.913605, 0.254028,
188  -0.552307, -0.793945, -0.28891, -0.765747, -0.574554, 0.058319, 0.291382, 0.954803,
189  0.946136, -0.303925, 0.111267, -0.078156, 0.443695, -0.892731, 0.182098, 0.89389,
190  0.409515, -0.680298, -0.213318, 0.701141, 0.062469, 0.848389, -0.525635, -0.72879,
191  -0.641846, 0.238342, -0.88089, 0.427673, 0.202637, -0.532501, -0.21405, 0.818878,
192  0.948975, -0.305084, 0.07962, 0.925446, 0.374664, 0.055817, 0.820923, 0.565491,
193  0.079102, 0.25882, 0.099792, -0.960724, -0.294617, 0.910522, 0.289978, 0.137115,
194  0.320038, -0.937408, -0.908386, 0.345276, -0.235718, -0.936218, 0.138763, 0.322754,
195  0.366577, 0.925934, -0.090637, 0.309296, -0.686829, -0.657684, 0.66983, 0.024445,
196  0.742065, -0.917999, -0.059113, -0.392059, 0.365509, 0.462158, -0.807922, 0.083374,
197  0.996399, -0.014801, 0.593842, 0.253143, -0.763672, 0.974976, -0.165466, 0.148285,
198  0.918976, 0.137299, 0.369537, 0.294952, 0.694977, 0.655731, 0.943085, 0.152618,
199  -0.295319, 0.58783, -0.598236, 0.544495, 0.203796, 0.678223, 0.705994, -0.478821,
200  -0.661011, 0.577667, 0.719055, -0.1698, -0.673828, -0.132172, -0.965332, 0.225006,
201  -0.981873, -0.14502, 0.121979, 0.763458, 0.579742, 0.284546, -0.893188, 0.079681,
202  0.442474, -0.795776, -0.523804, 0.303802, 0.734955, 0.67804, -0.007446, 0.15506,
203  0.986267, -0.056183, 0.258026, 0.571503, -0.778931, -0.681549, -0.702087, -0.206116,
204  -0.96286, -0.177185, 0.203613, -0.470978, -0.515106, 0.716095, -0.740326, 0.57135,
205  0.354095, -0.56012, -0.824982, -0.074982, -0.507874, 0.753204, 0.417969, -0.503113,
206  0.038147, 0.863342, 0.594025, 0.673553, -0.439758, -0.119873, -0.005524, -0.992737,
207  0.098267, -0.213776, 0.971893, -0.615631, 0.643951, 0.454163, 0.896851, -0.441071,
208  0.032166, -0.555023, 0.750763, -0.358093, 0.398773, 0.304688, 0.864929, -0.722961,
209  0.303589, 0.620544, -0.63559, -0.621948, -0.457306, -0.293243, 0.072327, 0.953278,
210  -0.491638, 0.661041, -0.566772, -0.304199, -0.572083, -0.761688, 0.908081, -0.398956,
211  0.127014, -0.523621, -0.549683, -0.650848, -0.932922, -0.19986, 0.299408, 0.099426,
212  0.140869, 0.984985, -0.020325, -0.999756, -0.002319, 0.952667, 0.280853, -0.11615,
213  -0.971893, 0.082581, 0.220337, 0.65921, 0.705292, -0.260651, 0.733063, -0.175537,
214  0.657043, -0.555206, 0.429504, -0.712189, 0.400421, -0.89859, 0.179352, 0.750885,
215  -0.19696, 0.630341, 0.785675, -0.569336, 0.241821, -0.058899, -0.464111, 0.883789,
216  0.129608, -0.94519, 0.299622, -0.357819, 0.907654, 0.219238, -0.842133, -0.439117,
217  -0.312927, -0.313477, 0.84433, 0.434479, -0.241211, 0.053253, 0.968994, 0.063873,
218  0.823273, 0.563965, 0.476288, 0.862152, -0.172516, 0.620941, -0.298126, 0.724915,
219  0.25238, -0.749359, -0.612122, -0.577545, 0.386566, 0.718994, -0.406342, -0.737976,
220  0.538696, 0.04718, 0.556305, 0.82959, -0.802856, 0.587463, 0.101166, -0.707733,
221  -0.705963, 0.026428, 0.374908, 0.68457, 0.625092, 0.472137, 0.208405, -0.856506,
222  -0.703064, -0.581085, -0.409821, -0.417206, -0.736328, 0.532623, -0.447876, -0.20285,
223  -0.870728, 0.086945, -0.990417, 0.107086, 0.183685, 0.018341, -0.982788, 0.560638,
224  -0.428864, 0.708282, 0.296722, -0.952576, -0.0672, 0.135773, 0.990265, 0.030243,
225  -0.068787, 0.654724, 0.752686, 0.762604, -0.551758, 0.337585, -0.819611, -0.407684,
226  0.402466, -0.727844, -0.55072, -0.408539, -0.855774, -0.480011, 0.19281, 0.693176,
227  -0.079285, 0.716339, 0.226013, 0.650116, -0.725433, 0.246704, 0.953369, -0.173553,
228  -0.970398, -0.239227, -0.03244, 0.136383, -0.394318, 0.908752, 0.813232, 0.558167,
229  0.164368, 0.40451, 0.549042, -0.731323, -0.380249, -0.566711, 0.730865, 0.022156,
230  0.932739, 0.359741, 0.00824, 0.996552, -0.082306, 0.956635, -0.065338, -0.283722,
231  -0.743561, 0.008209, 0.668579, -0.859589, -0.509674, 0.035767, -0.852234, 0.363678,
232  -0.375977, -0.201965, -0.970795, -0.12915, 0.313477, 0.947327, 0.06546, -0.254028,
233  -0.528259, 0.81015, 0.628052, 0.601105, 0.49411, -0.494385, 0.868378, 0.037933,
234  0.275635, -0.086426, 0.957336, -0.197937, 0.468903, -0.860748, 0.895599, 0.399384,
235  0.195801, 0.560791, 0.825012, -0.069214, 0.304199, -0.849487, 0.43103, 0.096375,
236  0.93576, 0.339111, -0.051422, 0.408966, -0.911072, 0.330444, 0.942841, -0.042389,
237  -0.452362, -0.786407, 0.420563, 0.134308, -0.933472, -0.332489, 0.80191, -0.566711,
238  -0.188934, -0.987946, -0.105988, 0.112518, -0.24408, 0.892242, -0.379791, -0.920502,
239  0.229095, -0.316376, 0.7789, 0.325958, 0.535706, -0.912872, 0.185211, -0.36377,
240  -0.184784, 0.565369, -0.803833, -0.018463, 0.119537, 0.992615, -0.259247, -0.935608,
241  0.239532, -0.82373, -0.449127, -0.345947, -0.433105, 0.659515, 0.614349, -0.822754,
242  0.378845, -0.423676, 0.687195, -0.674835, -0.26889, -0.246582, -0.800842, 0.545715,
243  -0.729187, -0.207794, 0.651978, 0.653534, -0.610443, -0.447388, 0.492584, -0.023346,
244  0.869934, 0.609039, 0.009094, -0.79306, 0.962494, -0.271088, -0.00885, 0.2659,
245  -0.004913, 0.963959, 0.651245, 0.553619, -0.518951, 0.280548, -0.84314, 0.458618,
246  -0.175293, -0.983215, 0.049805, 0.035339, -0.979919, 0.196045, -0.982941, 0.164307,
247  -0.082245, 0.233734, -0.97226, -0.005005, -0.747253, -0.611328, 0.260437, 0.645599,
248  0.592773, 0.481384, 0.117706, -0.949524, -0.29068, -0.535004, -0.791901, -0.294312,
249  -0.627167, -0.214447, 0.748718, -0.047974, -0.813477, -0.57959, -0.175537, 0.477264,
250  -0.860992, 0.738556, -0.414246, -0.53183, 0.562561, -0.704071, 0.433289, -0.754944,
251  0.64801, -0.100586, 0.114716, 0.044525, -0.992371, 0.966003, 0.244873, -0.082764,
252 };
253 
256 /* -------------------------------------------------------------------- */
260 BLI_INLINE float lerp(float t, float a, float b)
261 {
262  return (a + t * (b - a));
263 }
264 
265 BLI_INLINE float npfade(float t)
266 {
267  return (t * t * t * (t * (t * 6.0f - 15.0f) + 10.0f));
268 }
269 
270 BLI_INLINE float grad(int hash_val, float x, float y, float z)
271 {
272  int h = hash_val & 15; /* CONVERT LO 4 BITS OF HASH CODE */
273  float u = h < 8 ? x : y; /* INTO 12 GRADIENT DIRECTIONS. */
274  float v = h < 4 ? y : h == 12 || h == 14 ? x : z;
275  return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
276 }
277 
278 /* instead of adding another permutation array, just use hash table defined above */
279 static float newPerlin(float x, float y, float z)
280 {
281  int A, AA, AB, B, BA, BB;
282  float u = floor(x), v = floor(y), w = floor(z);
283  int X = ((int)u) & 255;
284  int Y = ((int)v) & 255;
285  int Z = ((int)w) & 255; /* FIND UNIT CUBE THAT CONTAINS POINT */
286  x -= u; /* FIND RELATIVE X,Y,Z */
287  y -= v; /* OF POINT IN CUBE. */
288  z -= w;
289  u = npfade(x); /* COMPUTE FADE CURVES */
290  v = npfade(y); /* FOR EACH OF X,Y,Z. */
291  w = npfade(z);
292  A = hash[X] + Y;
293  AA = hash[A] + Z;
294  AB = hash[A + 1] + Z; /* HASH COORDINATES OF */
295  B = hash[X + 1] + Y;
296  BA = hash[B] + Z;
297  BB = hash[B + 1] + Z; /* THE 8 CUBE CORNERS, */
298  return lerp(
299  w,
300  lerp(v,
301  lerp(u,
302  grad(hash[AA], x, y, z), /* AND ADD */
303  grad(hash[BA], x - 1, y, z)), /* BLENDED */
304  lerp(u,
305  grad(hash[AB], x, y - 1, z), /* RESULTS */
306  grad(hash[BB], x - 1, y - 1, z))), /* FROM 8 */
307  lerp(v,
308  lerp(u,
309  grad(hash[AA + 1], x, y, z - 1), /* CORNERS */
310  grad(hash[BA + 1], x - 1, y, z - 1)), /* OF CUBE */
311  lerp(u, grad(hash[AB + 1], x, y - 1, z - 1), grad(hash[BB + 1], x - 1, y - 1, z - 1))));
312 }
313 
314 /* for use with BLI_noise_generic_noise()/BLI_noise_generic_turbulence(), returns unsigned improved
315  * perlin noise */
316 static float newPerlinU(float x, float y, float z)
317 {
318  return (0.5f + 0.5f * newPerlin(x, y, z));
319 }
320 
323 /* -------------------------------------------------------------------- */
327 /* Was BLI_noise_hnoise(), removed noisesize, so other functions can call it without scaling. */
328 static float orgBlenderNoise(float x, float y, float z)
329 {
330  float cn1, cn2, cn3, cn4, cn5, cn6, i;
331  const float *h;
332  float fx, fy, fz, ox, oy, oz, jx, jy, jz;
333  float n = 0.5;
334  int ix, iy, iz, b00, b01, b10, b11, b20, b21;
335 
336  fx = floor(x);
337  fy = floor(y);
338  fz = floor(z);
339 
340  ox = x - fx;
341  oy = y - fy;
342  oz = z - fz;
343 
344  ix = (int)fx;
345  iy = (int)fy;
346  iz = (int)fz;
347 
348  jx = ox - 1;
349  jy = oy - 1;
350  jz = oz - 1;
351 
352  cn1 = ox * ox;
353  cn2 = oy * oy;
354  cn3 = oz * oz;
355  cn4 = jx * jx;
356  cn5 = jy * jy;
357  cn6 = jz * jz;
358 
359  cn1 = 1.0f - 3.0f * cn1 + 2.0f * cn1 * ox;
360  cn2 = 1.0f - 3.0f * cn2 + 2.0f * cn2 * oy;
361  cn3 = 1.0f - 3.0f * cn3 + 2.0f * cn3 * oz;
362  cn4 = 1.0f - 3.0f * cn4 - 2.0f * cn4 * jx;
363  cn5 = 1.0f - 3.0f * cn5 - 2.0f * cn5 * jy;
364  cn6 = 1.0f - 3.0f * cn6 - 2.0f * cn6 * jz;
365 
366  b00 = hash[hash[ix & 255] + (iy & 255)];
367  b10 = hash[hash[(ix + 1) & 255] + (iy & 255)];
368  b01 = hash[hash[ix & 255] + ((iy + 1) & 255)];
369  b11 = hash[hash[(ix + 1) & 255] + ((iy + 1) & 255)];
370 
371  b20 = iz & 255;
372  b21 = (iz + 1) & 255;
373 
374  /* 0 */
375  i = (cn1 * cn2 * cn3);
376  h = hashvectf + 3 * hash[b20 + b00];
377  n += i * (h[0] * ox + h[1] * oy + h[2] * oz);
378  /* 1 */
379  i = (cn1 * cn2 * cn6);
380  h = hashvectf + 3 * hash[b21 + b00];
381  n += i * (h[0] * ox + h[1] * oy + h[2] * jz);
382  /* 2 */
383  i = (cn1 * cn5 * cn3);
384  h = hashvectf + 3 * hash[b20 + b01];
385  n += i * (h[0] * ox + h[1] * jy + h[2] * oz);
386  /* 3 */
387  i = (cn1 * cn5 * cn6);
388  h = hashvectf + 3 * hash[b21 + b01];
389  n += i * (h[0] * ox + h[1] * jy + h[2] * jz);
390  /* 4 */
391  i = cn4 * cn2 * cn3;
392  h = hashvectf + 3 * hash[b20 + b10];
393  n += i * (h[0] * jx + h[1] * oy + h[2] * oz);
394  /* 5 */
395  i = cn4 * cn2 * cn6;
396  h = hashvectf + 3 * hash[b21 + b10];
397  n += i * (h[0] * jx + h[1] * oy + h[2] * jz);
398  /* 6 */
399  i = cn4 * cn5 * cn3;
400  h = hashvectf + 3 * hash[b20 + b11];
401  n += i * (h[0] * jx + h[1] * jy + h[2] * oz);
402  /* 7 */
403  i = (cn4 * cn5 * cn6);
404  h = hashvectf + 3 * hash[b21 + b11];
405  n += i * (h[0] * jx + h[1] * jy + h[2] * jz);
406 
407  if (n < 0.0f) {
408  n = 0.0f;
409  }
410  else if (n > 1.0f) {
411  n = 1.0f;
412  }
413  return n;
414 }
415 
416 static float orgBlenderNoiseS(float x, float y, float z)
417 {
418  /* NOTE: As #orgBlenderNoise(), returning signed noise. */
419 
420  return (2.0f * orgBlenderNoise(x, y, z) - 1.0f);
421 }
422 
423 float BLI_noise_hnoise(float noisesize, float x, float y, float z)
424 {
425  /* NOTE: Separated from orgBlenderNoise, with scaling. */
426 
427  if (noisesize == 0.0f) {
428  return 0.0f;
429  }
430  x = (1.0f + x) / noisesize;
431  y = (1.0f + y) / noisesize;
432  z = (1.0f + z) / noisesize;
433  return orgBlenderNoise(x, y, z);
434 }
435 
436 float BLI_noise_turbulence(float noisesize, float x, float y, float z, int nr)
437 {
438  float s, d = 0.5, div = 1.0;
439 
440  s = BLI_noise_hnoise(noisesize, x, y, z);
441 
442  while (nr > 0) {
443 
444  s += d * BLI_noise_hnoise(noisesize * d, x, y, z);
445  div += d;
446  d *= 0.5f;
447 
448  nr--;
449  }
450  return s / div;
451 }
452 
453 /* ********************* FROM PERLIN HIMSELF: ******************** */
454 
455 static const char g_perlin_data_ub[512 + 2] = {
456  0xA2, 0xA0, 0x19, 0x3B, 0xF8, 0xEB, 0xAA, 0xEE, 0xF3, 0x1C, 0x67, 0x28, 0x1D, 0xED, 0x0, 0xDE,
457  0x95, 0x2E, 0xDC, 0x3F, 0x3A, 0x82, 0x35, 0x4D, 0x6C, 0xBA, 0x36, 0xD0, 0xF6, 0xC, 0x79, 0x32,
458  0xD1, 0x59, 0xF4, 0x8, 0x8B, 0x63, 0x89, 0x2F, 0xB8, 0xB4, 0x97, 0x83, 0xF2, 0x8F, 0x18, 0xC7,
459  0x51, 0x14, 0x65, 0x87, 0x48, 0x20, 0x42, 0xA8, 0x80, 0xB5, 0x40, 0x13, 0xB2, 0x22, 0x7E, 0x57,
460  0xBC, 0x7F, 0x6B, 0x9D, 0x86, 0x4C, 0xC8, 0xDB, 0x7C, 0xD5, 0x25, 0x4E, 0x5A, 0x55, 0x74, 0x50,
461  0xCD, 0xB3, 0x7A, 0xBB, 0xC3, 0xCB, 0xB6, 0xE2, 0xE4, 0xEC, 0xFD, 0x98, 0xB, 0x96, 0xD3, 0x9E,
462  0x5C, 0xA1, 0x64, 0xF1, 0x81, 0x61, 0xE1, 0xC4, 0x24, 0x72, 0x49, 0x8C, 0x90, 0x4B, 0x84, 0x34,
463  0x38, 0xAB, 0x78, 0xCA, 0x1F, 0x1, 0xD7, 0x93, 0x11, 0xC1, 0x58, 0xA9, 0x31, 0xF9, 0x44, 0x6D,
464  0xBF, 0x33, 0x9C, 0x5F, 0x9, 0x94, 0xA3, 0x85, 0x6, 0xC6, 0x9A, 0x1E, 0x7B, 0x46, 0x15, 0x30,
465  0x27, 0x2B, 0x1B, 0x71, 0x3C, 0x5B, 0xD6, 0x6F, 0x62, 0xAC, 0x4F, 0xC2, 0xC0, 0xE, 0xB1, 0x23,
466  0xA7, 0xDF, 0x47, 0xB0, 0x77, 0x69, 0x5, 0xE9, 0xE6, 0xE7, 0x76, 0x73, 0xF, 0xFE, 0x6E, 0x9B,
467  0x56, 0xEF, 0x12, 0xA5, 0x37, 0xFC, 0xAE, 0xD9, 0x3, 0x8E, 0xDD, 0x10, 0xB9, 0xCE, 0xC9, 0x8D,
468  0xDA, 0x2A, 0xBD, 0x68, 0x17, 0x9F, 0xBE, 0xD4, 0xA, 0xCC, 0xD2, 0xE8, 0x43, 0x3D, 0x70, 0xB7,
469  0x2, 0x7D, 0x99, 0xD8, 0xD, 0x60, 0x8A, 0x4, 0x2C, 0x3E, 0x92, 0xE5, 0xAF, 0x53, 0x7, 0xE0,
470  0x29, 0xA6, 0xC5, 0xE3, 0xF5, 0xF7, 0x4A, 0x41, 0x26, 0x6A, 0x16, 0x5E, 0x52, 0x2D, 0x21, 0xAD,
471  0xF0, 0x91, 0xFF, 0xEA, 0x54, 0xFA, 0x66, 0x1A, 0x45, 0x39, 0xCF, 0x75, 0xA4, 0x88, 0xFB, 0x5D,
472  0xA2, 0xA0, 0x19, 0x3B, 0xF8, 0xEB, 0xAA, 0xEE, 0xF3, 0x1C, 0x67, 0x28, 0x1D, 0xED, 0x0, 0xDE,
473  0x95, 0x2E, 0xDC, 0x3F, 0x3A, 0x82, 0x35, 0x4D, 0x6C, 0xBA, 0x36, 0xD0, 0xF6, 0xC, 0x79, 0x32,
474  0xD1, 0x59, 0xF4, 0x8, 0x8B, 0x63, 0x89, 0x2F, 0xB8, 0xB4, 0x97, 0x83, 0xF2, 0x8F, 0x18, 0xC7,
475  0x51, 0x14, 0x65, 0x87, 0x48, 0x20, 0x42, 0xA8, 0x80, 0xB5, 0x40, 0x13, 0xB2, 0x22, 0x7E, 0x57,
476  0xBC, 0x7F, 0x6B, 0x9D, 0x86, 0x4C, 0xC8, 0xDB, 0x7C, 0xD5, 0x25, 0x4E, 0x5A, 0x55, 0x74, 0x50,
477  0xCD, 0xB3, 0x7A, 0xBB, 0xC3, 0xCB, 0xB6, 0xE2, 0xE4, 0xEC, 0xFD, 0x98, 0xB, 0x96, 0xD3, 0x9E,
478  0x5C, 0xA1, 0x64, 0xF1, 0x81, 0x61, 0xE1, 0xC4, 0x24, 0x72, 0x49, 0x8C, 0x90, 0x4B, 0x84, 0x34,
479  0x38, 0xAB, 0x78, 0xCA, 0x1F, 0x1, 0xD7, 0x93, 0x11, 0xC1, 0x58, 0xA9, 0x31, 0xF9, 0x44, 0x6D,
480  0xBF, 0x33, 0x9C, 0x5F, 0x9, 0x94, 0xA3, 0x85, 0x6, 0xC6, 0x9A, 0x1E, 0x7B, 0x46, 0x15, 0x30,
481  0x27, 0x2B, 0x1B, 0x71, 0x3C, 0x5B, 0xD6, 0x6F, 0x62, 0xAC, 0x4F, 0xC2, 0xC0, 0xE, 0xB1, 0x23,
482  0xA7, 0xDF, 0x47, 0xB0, 0x77, 0x69, 0x5, 0xE9, 0xE6, 0xE7, 0x76, 0x73, 0xF, 0xFE, 0x6E, 0x9B,
483  0x56, 0xEF, 0x12, 0xA5, 0x37, 0xFC, 0xAE, 0xD9, 0x3, 0x8E, 0xDD, 0x10, 0xB9, 0xCE, 0xC9, 0x8D,
484  0xDA, 0x2A, 0xBD, 0x68, 0x17, 0x9F, 0xBE, 0xD4, 0xA, 0xCC, 0xD2, 0xE8, 0x43, 0x3D, 0x70, 0xB7,
485  0x2, 0x7D, 0x99, 0xD8, 0xD, 0x60, 0x8A, 0x4, 0x2C, 0x3E, 0x92, 0xE5, 0xAF, 0x53, 0x7, 0xE0,
486  0x29, 0xA6, 0xC5, 0xE3, 0xF5, 0xF7, 0x4A, 0x41, 0x26, 0x6A, 0x16, 0x5E, 0x52, 0x2D, 0x21, 0xAD,
487  0xF0, 0x91, 0xFF, 0xEA, 0x54, 0xFA, 0x66, 0x1A, 0x45, 0x39, 0xCF, 0x75, 0xA4, 0x88, 0xFB, 0x5D,
488  0xA2, 0xA0,
489 };
490 
491 static const float g_perlin_data_v3[512 + 2][3] = {
492  {0.33783, 0.715698, -0.611206}, {-0.944031, -0.326599, -0.045624},
493  {-0.101074, -0.416443, -0.903503}, {0.799286, 0.49411, -0.341949},
494  {-0.854645, 0.518036, 0.033936}, {0.42514, -0.437866, -0.792114},
495  {-0.358948, 0.597046, 0.717377}, {-0.985413, 0.144714, 0.089294},
496  {-0.601776, -0.33728, -0.723907}, {-0.449921, 0.594513, 0.666382},
497  {0.208313, -0.10791, 0.972076}, {0.575317, 0.060425, 0.815643},
498  {0.293365, -0.875702, -0.383453}, {0.293762, 0.465759, 0.834686},
499  {-0.846008, -0.233398, -0.47934}, {-0.115814, 0.143036, -0.98291},
500  {0.204681, -0.949036, -0.239532}, {0.946716, -0.263947, 0.184326},
501  {-0.235596, 0.573822, 0.784332}, {0.203705, -0.372253, -0.905487},
502  {0.756989, -0.651031, 0.055298}, {0.497803, 0.814697, -0.297363},
503  {-0.16214, 0.063995, -0.98468}, {-0.329254, 0.834381, 0.441925},
504  {0.703827, -0.527039, -0.476227}, {0.956421, 0.266113, 0.119781},
505  {0.480133, 0.482849, 0.7323}, {-0.18631, 0.961212, -0.203125},
506  {-0.748474, -0.656921, -0.090393}, {-0.085052, -0.165253, 0.982544},
507  {-0.76947, 0.628174, -0.115234}, {0.383148, 0.537659, 0.751068},
508  {0.616486, -0.668488, -0.415924}, {-0.259979, -0.630005, 0.73175},
509  {0.570953, -0.087952, 0.816223}, {-0.458008, 0.023254, 0.888611},
510  {-0.196167, 0.976563, -0.088287}, {-0.263885, -0.69812, -0.665527},
511  {0.437134, -0.892273, -0.112793}, {-0.621674, -0.230438, 0.748566},
512  {0.232422, 0.900574, -0.367249}, {0.22229, -0.796143, 0.562744},
513  {-0.665497, -0.73764, 0.11377}, {0.670135, 0.704803, 0.232605},
514  {0.895599, 0.429749, -0.114655}, {-0.11557, -0.474243, 0.872742},
515  {0.621826, 0.604004, -0.498444}, {-0.832214, 0.012756, 0.55426},
516  {-0.702484, 0.705994, -0.089661}, {-0.692017, 0.649292, 0.315399},
517  {-0.175995, -0.977997, 0.111877}, {0.096954, -0.04953, 0.994019},
518  {0.635284, -0.606689, -0.477783}, {-0.261261, -0.607422, -0.750153},
519  {0.983276, 0.165436, 0.075958}, {-0.29837, 0.404083, -0.864655},
520  {-0.638672, 0.507721, 0.578156}, {0.388214, 0.412079, 0.824249},
521  {0.556183, -0.208832, 0.804352}, {0.778442, 0.562012, 0.27951},
522  {-0.616577, 0.781921, -0.091522}, {0.196289, 0.051056, 0.979187},
523  {-0.121216, 0.207153, -0.970734}, {-0.173401, -0.384735, 0.906555},
524  {0.161499, -0.723236, -0.671387}, {0.178497, -0.006226, -0.983887},
525  {-0.126038, 0.15799, 0.97934}, {0.830475, -0.024811, 0.556458},
526  {-0.510132, -0.76944, 0.384247}, {0.81424, 0.200104, -0.544891},
527  {-0.112549, -0.393311, -0.912445}, {0.56189, 0.152222, -0.813049},
528  {0.198914, -0.254517, -0.946381}, {-0.41217, 0.690979, -0.593811},
529  {-0.407257, 0.324524, 0.853668}, {-0.690186, 0.366119, -0.624115},
530  {-0.428345, 0.844147, -0.322296}, {-0.21228, -0.297546, -0.930756},
531  {-0.273071, 0.516113, 0.811798}, {0.928314, 0.371643, 0.007233},
532  {0.785828, -0.479218, -0.390778}, {-0.704895, 0.058929, 0.706818},
533  {0.173248, 0.203583, 0.963562}, {0.422211, -0.904297, -0.062469},
534  {-0.363312, -0.182465, 0.913605}, {0.254028, -0.552307, -0.793945},
535  {-0.28891, -0.765747, -0.574554}, {0.058319, 0.291382, 0.954803},
536  {0.946136, -0.303925, 0.111267}, {-0.078156, 0.443695, -0.892731},
537  {0.182098, 0.89389, 0.409515}, {-0.680298, -0.213318, 0.701141},
538  {0.062469, 0.848389, -0.525635}, {-0.72879, -0.641846, 0.238342},
539  {-0.88089, 0.427673, 0.202637}, {-0.532501, -0.21405, 0.818878},
540  {0.948975, -0.305084, 0.07962}, {0.925446, 0.374664, 0.055817},
541  {0.820923, 0.565491, 0.079102}, {0.25882, 0.099792, -0.960724},
542  {-0.294617, 0.910522, 0.289978}, {0.137115, 0.320038, -0.937408},
543  {-0.908386, 0.345276, -0.235718}, {-0.936218, 0.138763, 0.322754},
544  {0.366577, 0.925934, -0.090637}, {0.309296, -0.686829, -0.657684},
545  {0.66983, 0.024445, 0.742065}, {-0.917999, -0.059113, -0.392059},
546  {0.365509, 0.462158, -0.807922}, {0.083374, 0.996399, -0.014801},
547  {0.593842, 0.253143, -0.763672}, {0.974976, -0.165466, 0.148285},
548  {0.918976, 0.137299, 0.369537}, {0.294952, 0.694977, 0.655731},
549  {0.943085, 0.152618, -0.295319}, {0.58783, -0.598236, 0.544495},
550  {0.203796, 0.678223, 0.705994}, {-0.478821, -0.661011, 0.577667},
551  {0.719055, -0.1698, -0.673828}, {-0.132172, -0.965332, 0.225006},
552  {-0.981873, -0.14502, 0.121979}, {0.763458, 0.579742, 0.284546},
553  {-0.893188, 0.079681, 0.442474}, {-0.795776, -0.523804, 0.303802},
554  {0.734955, 0.67804, -0.007446}, {0.15506, 0.986267, -0.056183},
555  {0.258026, 0.571503, -0.778931}, {-0.681549, -0.702087, -0.206116},
556  {-0.96286, -0.177185, 0.203613}, {-0.470978, -0.515106, 0.716095},
557  {-0.740326, 0.57135, 0.354095}, {-0.56012, -0.824982, -0.074982},
558  {-0.507874, 0.753204, 0.417969}, {-0.503113, 0.038147, 0.863342},
559  {0.594025, 0.673553, -0.439758}, {-0.119873, -0.005524, -0.992737},
560  {0.098267, -0.213776, 0.971893}, {-0.615631, 0.643951, 0.454163},
561  {0.896851, -0.441071, 0.032166}, {-0.555023, 0.750763, -0.358093},
562  {0.398773, 0.304688, 0.864929}, {-0.722961, 0.303589, 0.620544},
563  {-0.63559, -0.621948, -0.457306}, {-0.293243, 0.072327, 0.953278},
564  {-0.491638, 0.661041, -0.566772}, {-0.304199, -0.572083, -0.761688},
565  {0.908081, -0.398956, 0.127014}, {-0.523621, -0.549683, -0.650848},
566  {-0.932922, -0.19986, 0.299408}, {0.099426, 0.140869, 0.984985},
567  {-0.020325, -0.999756, -0.002319}, {0.952667, 0.280853, -0.11615},
568  {-0.971893, 0.082581, 0.220337}, {0.65921, 0.705292, -0.260651},
569  {0.733063, -0.175537, 0.657043}, {-0.555206, 0.429504, -0.712189},
570  {0.400421, -0.89859, 0.179352}, {0.750885, -0.19696, 0.630341},
571  {0.785675, -0.569336, 0.241821}, {-0.058899, -0.464111, 0.883789},
572  {0.129608, -0.94519, 0.299622}, {-0.357819, 0.907654, 0.219238},
573  {-0.842133, -0.439117, -0.312927}, {-0.313477, 0.84433, 0.434479},
574  {-0.241211, 0.053253, 0.968994}, {0.063873, 0.823273, 0.563965},
575  {0.476288, 0.862152, -0.172516}, {0.620941, -0.298126, 0.724915},
576  {0.25238, -0.749359, -0.612122}, {-0.577545, 0.386566, 0.718994},
577  {-0.406342, -0.737976, 0.538696}, {0.04718, 0.556305, 0.82959},
578  {-0.802856, 0.587463, 0.101166}, {-0.707733, -0.705963, 0.026428},
579  {0.374908, 0.68457, 0.625092}, {0.472137, 0.208405, -0.856506},
580  {-0.703064, -0.581085, -0.409821}, {-0.417206, -0.736328, 0.532623},
581  {-0.447876, -0.20285, -0.870728}, {0.086945, -0.990417, 0.107086},
582  {0.183685, 0.018341, -0.982788}, {0.560638, -0.428864, 0.708282},
583  {0.296722, -0.952576, -0.0672}, {0.135773, 0.990265, 0.030243},
584  {-0.068787, 0.654724, 0.752686}, {0.762604, -0.551758, 0.337585},
585  {-0.819611, -0.407684, 0.402466}, {-0.727844, -0.55072, -0.408539},
586  {-0.855774, -0.480011, 0.19281}, {0.693176, -0.079285, 0.716339},
587  {0.226013, 0.650116, -0.725433}, {0.246704, 0.953369, -0.173553},
588  {-0.970398, -0.239227, -0.03244}, {0.136383, -0.394318, 0.908752},
589  {0.813232, 0.558167, 0.164368}, {0.40451, 0.549042, -0.731323},
590  {-0.380249, -0.566711, 0.730865}, {0.022156, 0.932739, 0.359741},
591  {0.00824, 0.996552, -0.082306}, {0.956635, -0.065338, -0.283722},
592  {-0.743561, 0.008209, 0.668579}, {-0.859589, -0.509674, 0.035767},
593  {-0.852234, 0.363678, -0.375977}, {-0.201965, -0.970795, -0.12915},
594  {0.313477, 0.947327, 0.06546}, {-0.254028, -0.528259, 0.81015},
595  {0.628052, 0.601105, 0.49411}, {-0.494385, 0.868378, 0.037933},
596  {0.275635, -0.086426, 0.957336}, {-0.197937, 0.468903, -0.860748},
597  {0.895599, 0.399384, 0.195801}, {0.560791, 0.825012, -0.069214},
598  {0.304199, -0.849487, 0.43103}, {0.096375, 0.93576, 0.339111},
599  {-0.051422, 0.408966, -0.911072}, {0.330444, 0.942841, -0.042389},
600  {-0.452362, -0.786407, 0.420563}, {0.134308, -0.933472, -0.332489},
601  {0.80191, -0.566711, -0.188934}, {-0.987946, -0.105988, 0.112518},
602  {-0.24408, 0.892242, -0.379791}, {-0.920502, 0.229095, -0.316376},
603  {0.7789, 0.325958, 0.535706}, {-0.912872, 0.185211, -0.36377},
604  {-0.184784, 0.565369, -0.803833}, {-0.018463, 0.119537, 0.992615},
605  {-0.259247, -0.935608, 0.239532}, {-0.82373, -0.449127, -0.345947},
606  {-0.433105, 0.659515, 0.614349}, {-0.822754, 0.378845, -0.423676},
607  {0.687195, -0.674835, -0.26889}, {-0.246582, -0.800842, 0.545715},
608  {-0.729187, -0.207794, 0.651978}, {0.653534, -0.610443, -0.447388},
609  {0.492584, -0.023346, 0.869934}, {0.609039, 0.009094, -0.79306},
610  {0.962494, -0.271088, -0.00885}, {0.2659, -0.004913, 0.963959},
611  {0.651245, 0.553619, -0.518951}, {0.280548, -0.84314, 0.458618},
612  {-0.175293, -0.983215, 0.049805}, {0.035339, -0.979919, 0.196045},
613  {-0.982941, 0.164307, -0.082245}, {0.233734, -0.97226, -0.005005},
614  {-0.747253, -0.611328, 0.260437}, {0.645599, 0.592773, 0.481384},
615  {0.117706, -0.949524, -0.29068}, {-0.535004, -0.791901, -0.294312},
616  {-0.627167, -0.214447, 0.748718}, {-0.047974, -0.813477, -0.57959},
617  {-0.175537, 0.477264, -0.860992}, {0.738556, -0.414246, -0.53183},
618  {0.562561, -0.704071, 0.433289}, {-0.754944, 0.64801, -0.100586},
619  {0.114716, 0.044525, -0.992371}, {0.966003, 0.244873, -0.082764},
620  {0.33783, 0.715698, -0.611206}, {-0.944031, -0.326599, -0.045624},
621  {-0.101074, -0.416443, -0.903503}, {0.799286, 0.49411, -0.341949},
622  {-0.854645, 0.518036, 0.033936}, {0.42514, -0.437866, -0.792114},
623  {-0.358948, 0.597046, 0.717377}, {-0.985413, 0.144714, 0.089294},
624  {-0.601776, -0.33728, -0.723907}, {-0.449921, 0.594513, 0.666382},
625  {0.208313, -0.10791, 0.972076}, {0.575317, 0.060425, 0.815643},
626  {0.293365, -0.875702, -0.383453}, {0.293762, 0.465759, 0.834686},
627  {-0.846008, -0.233398, -0.47934}, {-0.115814, 0.143036, -0.98291},
628  {0.204681, -0.949036, -0.239532}, {0.946716, -0.263947, 0.184326},
629  {-0.235596, 0.573822, 0.784332}, {0.203705, -0.372253, -0.905487},
630  {0.756989, -0.651031, 0.055298}, {0.497803, 0.814697, -0.297363},
631  {-0.16214, 0.063995, -0.98468}, {-0.329254, 0.834381, 0.441925},
632  {0.703827, -0.527039, -0.476227}, {0.956421, 0.266113, 0.119781},
633  {0.480133, 0.482849, 0.7323}, {-0.18631, 0.961212, -0.203125},
634  {-0.748474, -0.656921, -0.090393}, {-0.085052, -0.165253, 0.982544},
635  {-0.76947, 0.628174, -0.115234}, {0.383148, 0.537659, 0.751068},
636  {0.616486, -0.668488, -0.415924}, {-0.259979, -0.630005, 0.73175},
637  {0.570953, -0.087952, 0.816223}, {-0.458008, 0.023254, 0.888611},
638  {-0.196167, 0.976563, -0.088287}, {-0.263885, -0.69812, -0.665527},
639  {0.437134, -0.892273, -0.112793}, {-0.621674, -0.230438, 0.748566},
640  {0.232422, 0.900574, -0.367249}, {0.22229, -0.796143, 0.562744},
641  {-0.665497, -0.73764, 0.11377}, {0.670135, 0.704803, 0.232605},
642  {0.895599, 0.429749, -0.114655}, {-0.11557, -0.474243, 0.872742},
643  {0.621826, 0.604004, -0.498444}, {-0.832214, 0.012756, 0.55426},
644  {-0.702484, 0.705994, -0.089661}, {-0.692017, 0.649292, 0.315399},
645  {-0.175995, -0.977997, 0.111877}, {0.096954, -0.04953, 0.994019},
646  {0.635284, -0.606689, -0.477783}, {-0.261261, -0.607422, -0.750153},
647  {0.983276, 0.165436, 0.075958}, {-0.29837, 0.404083, -0.864655},
648  {-0.638672, 0.507721, 0.578156}, {0.388214, 0.412079, 0.824249},
649  {0.556183, -0.208832, 0.804352}, {0.778442, 0.562012, 0.27951},
650  {-0.616577, 0.781921, -0.091522}, {0.196289, 0.051056, 0.979187},
651  {-0.121216, 0.207153, -0.970734}, {-0.173401, -0.384735, 0.906555},
652  {0.161499, -0.723236, -0.671387}, {0.178497, -0.006226, -0.983887},
653  {-0.126038, 0.15799, 0.97934}, {0.830475, -0.024811, 0.556458},
654  {-0.510132, -0.76944, 0.384247}, {0.81424, 0.200104, -0.544891},
655  {-0.112549, -0.393311, -0.912445}, {0.56189, 0.152222, -0.813049},
656  {0.198914, -0.254517, -0.946381}, {-0.41217, 0.690979, -0.593811},
657  {-0.407257, 0.324524, 0.853668}, {-0.690186, 0.366119, -0.624115},
658  {-0.428345, 0.844147, -0.322296}, {-0.21228, -0.297546, -0.930756},
659  {-0.273071, 0.516113, 0.811798}, {0.928314, 0.371643, 0.007233},
660  {0.785828, -0.479218, -0.390778}, {-0.704895, 0.058929, 0.706818},
661  {0.173248, 0.203583, 0.963562}, {0.422211, -0.904297, -0.062469},
662  {-0.363312, -0.182465, 0.913605}, {0.254028, -0.552307, -0.793945},
663  {-0.28891, -0.765747, -0.574554}, {0.058319, 0.291382, 0.954803},
664  {0.946136, -0.303925, 0.111267}, {-0.078156, 0.443695, -0.892731},
665  {0.182098, 0.89389, 0.409515}, {-0.680298, -0.213318, 0.701141},
666  {0.062469, 0.848389, -0.525635}, {-0.72879, -0.641846, 0.238342},
667  {-0.88089, 0.427673, 0.202637}, {-0.532501, -0.21405, 0.818878},
668  {0.948975, -0.305084, 0.07962}, {0.925446, 0.374664, 0.055817},
669  {0.820923, 0.565491, 0.079102}, {0.25882, 0.099792, -0.960724},
670  {-0.294617, 0.910522, 0.289978}, {0.137115, 0.320038, -0.937408},
671  {-0.908386, 0.345276, -0.235718}, {-0.936218, 0.138763, 0.322754},
672  {0.366577, 0.925934, -0.090637}, {0.309296, -0.686829, -0.657684},
673  {0.66983, 0.024445, 0.742065}, {-0.917999, -0.059113, -0.392059},
674  {0.365509, 0.462158, -0.807922}, {0.083374, 0.996399, -0.014801},
675  {0.593842, 0.253143, -0.763672}, {0.974976, -0.165466, 0.148285},
676  {0.918976, 0.137299, 0.369537}, {0.294952, 0.694977, 0.655731},
677  {0.943085, 0.152618, -0.295319}, {0.58783, -0.598236, 0.544495},
678  {0.203796, 0.678223, 0.705994}, {-0.478821, -0.661011, 0.577667},
679  {0.719055, -0.1698, -0.673828}, {-0.132172, -0.965332, 0.225006},
680  {-0.981873, -0.14502, 0.121979}, {0.763458, 0.579742, 0.284546},
681  {-0.893188, 0.079681, 0.442474}, {-0.795776, -0.523804, 0.303802},
682  {0.734955, 0.67804, -0.007446}, {0.15506, 0.986267, -0.056183},
683  {0.258026, 0.571503, -0.778931}, {-0.681549, -0.702087, -0.206116},
684  {-0.96286, -0.177185, 0.203613}, {-0.470978, -0.515106, 0.716095},
685  {-0.740326, 0.57135, 0.354095}, {-0.56012, -0.824982, -0.074982},
686  {-0.507874, 0.753204, 0.417969}, {-0.503113, 0.038147, 0.863342},
687  {0.594025, 0.673553, -0.439758}, {-0.119873, -0.005524, -0.992737},
688  {0.098267, -0.213776, 0.971893}, {-0.615631, 0.643951, 0.454163},
689  {0.896851, -0.441071, 0.032166}, {-0.555023, 0.750763, -0.358093},
690  {0.398773, 0.304688, 0.864929}, {-0.722961, 0.303589, 0.620544},
691  {-0.63559, -0.621948, -0.457306}, {-0.293243, 0.072327, 0.953278},
692  {-0.491638, 0.661041, -0.566772}, {-0.304199, -0.572083, -0.761688},
693  {0.908081, -0.398956, 0.127014}, {-0.523621, -0.549683, -0.650848},
694  {-0.932922, -0.19986, 0.299408}, {0.099426, 0.140869, 0.984985},
695  {-0.020325, -0.999756, -0.002319}, {0.952667, 0.280853, -0.11615},
696  {-0.971893, 0.082581, 0.220337}, {0.65921, 0.705292, -0.260651},
697  {0.733063, -0.175537, 0.657043}, {-0.555206, 0.429504, -0.712189},
698  {0.400421, -0.89859, 0.179352}, {0.750885, -0.19696, 0.630341},
699  {0.785675, -0.569336, 0.241821}, {-0.058899, -0.464111, 0.883789},
700  {0.129608, -0.94519, 0.299622}, {-0.357819, 0.907654, 0.219238},
701  {-0.842133, -0.439117, -0.312927}, {-0.313477, 0.84433, 0.434479},
702  {-0.241211, 0.053253, 0.968994}, {0.063873, 0.823273, 0.563965},
703  {0.476288, 0.862152, -0.172516}, {0.620941, -0.298126, 0.724915},
704  {0.25238, -0.749359, -0.612122}, {-0.577545, 0.386566, 0.718994},
705  {-0.406342, -0.737976, 0.538696}, {0.04718, 0.556305, 0.82959},
706  {-0.802856, 0.587463, 0.101166}, {-0.707733, -0.705963, 0.026428},
707  {0.374908, 0.68457, 0.625092}, {0.472137, 0.208405, -0.856506},
708  {-0.703064, -0.581085, -0.409821}, {-0.417206, -0.736328, 0.532623},
709  {-0.447876, -0.20285, -0.870728}, {0.086945, -0.990417, 0.107086},
710  {0.183685, 0.018341, -0.982788}, {0.560638, -0.428864, 0.708282},
711  {0.296722, -0.952576, -0.0672}, {0.135773, 0.990265, 0.030243},
712  {-0.068787, 0.654724, 0.752686}, {0.762604, -0.551758, 0.337585},
713  {-0.819611, -0.407684, 0.402466}, {-0.727844, -0.55072, -0.408539},
714  {-0.855774, -0.480011, 0.19281}, {0.693176, -0.079285, 0.716339},
715  {0.226013, 0.650116, -0.725433}, {0.246704, 0.953369, -0.173553},
716  {-0.970398, -0.239227, -0.03244}, {0.136383, -0.394318, 0.908752},
717  {0.813232, 0.558167, 0.164368}, {0.40451, 0.549042, -0.731323},
718  {-0.380249, -0.566711, 0.730865}, {0.022156, 0.932739, 0.359741},
719  {0.00824, 0.996552, -0.082306}, {0.956635, -0.065338, -0.283722},
720  {-0.743561, 0.008209, 0.668579}, {-0.859589, -0.509674, 0.035767},
721  {-0.852234, 0.363678, -0.375977}, {-0.201965, -0.970795, -0.12915},
722  {0.313477, 0.947327, 0.06546}, {-0.254028, -0.528259, 0.81015},
723  {0.628052, 0.601105, 0.49411}, {-0.494385, 0.868378, 0.037933},
724  {0.275635, -0.086426, 0.957336}, {-0.197937, 0.468903, -0.860748},
725  {0.895599, 0.399384, 0.195801}, {0.560791, 0.825012, -0.069214},
726  {0.304199, -0.849487, 0.43103}, {0.096375, 0.93576, 0.339111},
727  {-0.051422, 0.408966, -0.911072}, {0.330444, 0.942841, -0.042389},
728  {-0.452362, -0.786407, 0.420563}, {0.134308, -0.933472, -0.332489},
729  {0.80191, -0.566711, -0.188934}, {-0.987946, -0.105988, 0.112518},
730  {-0.24408, 0.892242, -0.379791}, {-0.920502, 0.229095, -0.316376},
731  {0.7789, 0.325958, 0.535706}, {-0.912872, 0.185211, -0.36377},
732  {-0.184784, 0.565369, -0.803833}, {-0.018463, 0.119537, 0.992615},
733  {-0.259247, -0.935608, 0.239532}, {-0.82373, -0.449127, -0.345947},
734  {-0.433105, 0.659515, 0.614349}, {-0.822754, 0.378845, -0.423676},
735  {0.687195, -0.674835, -0.26889}, {-0.246582, -0.800842, 0.545715},
736  {-0.729187, -0.207794, 0.651978}, {0.653534, -0.610443, -0.447388},
737  {0.492584, -0.023346, 0.869934}, {0.609039, 0.009094, -0.79306},
738  {0.962494, -0.271088, -0.00885}, {0.2659, -0.004913, 0.963959},
739  {0.651245, 0.553619, -0.518951}, {0.280548, -0.84314, 0.458618},
740  {-0.175293, -0.983215, 0.049805}, {0.035339, -0.979919, 0.196045},
741  {-0.982941, 0.164307, -0.082245}, {0.233734, -0.97226, -0.005005},
742  {-0.747253, -0.611328, 0.260437}, {0.645599, 0.592773, 0.481384},
743  {0.117706, -0.949524, -0.29068}, {-0.535004, -0.791901, -0.294312},
744  {-0.627167, -0.214447, 0.748718}, {-0.047974, -0.813477, -0.57959},
745  {-0.175537, 0.477264, -0.860992}, {0.738556, -0.414246, -0.53183},
746  {0.562561, -0.704071, 0.433289}, {-0.754944, 0.64801, -0.100586},
747  {0.114716, 0.044525, -0.992371}, {0.966003, 0.244873, -0.082764},
748  {0.33783, 0.715698, -0.611206}, {-0.944031, -0.326599, -0.045624},
749 };
750 
751 #define SETUP(val, b0, b1, r0, r1) \
752  { \
753  t = val + 10000.0f; \
754  b0 = ((int)t) & 255; \
755  b1 = (b0 + 1) & 255; \
756  r0 = t - floorf(t); \
757  r1 = r0 - 1.0f; \
758  } \
759  (void)0
760 
761 static float noise3_perlin(const float vec[3])
762 {
763  const char *p = g_perlin_data_ub;
764  const float(*g)[3] = g_perlin_data_v3;
765  int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
766  float rx0, rx1, ry0, ry1, rz0, rz1, sx, sy, sz, a, b, c, d, t, u, v;
767  const float *q;
768 
769  SETUP(vec[0], bx0, bx1, rx0, rx1);
770  SETUP(vec[1], by0, by1, ry0, ry1);
771  SETUP(vec[2], bz0, bz1, rz0, rz1);
772 
773  int i = p[bx0];
774  int j = p[bx1];
775 
776  b00 = p[i + by0];
777  b10 = p[j + by0];
778  b01 = p[i + by1];
779  b11 = p[j + by1];
780 
781 #define VALUE_AT(rx, ry, rz) ((rx)*q[0] + (ry)*q[1] + (rz)*q[2])
782 #define SURVE(t) ((t) * (t) * (3.0f - 2.0f * (t)))
783 
784  /* lerp moved to improved perlin above */
785 
786  sx = SURVE(rx0);
787  sy = SURVE(ry0);
788  sz = SURVE(rz0);
789 
790  q = g[b00 + bz0];
791  u = VALUE_AT(rx0, ry0, rz0);
792  q = g[b10 + bz0];
793  v = VALUE_AT(rx1, ry0, rz0);
794  a = lerp(sx, u, v);
795 
796  q = g[b01 + bz0];
797  u = VALUE_AT(rx0, ry1, rz0);
798  q = g[b11 + bz0];
799  v = VALUE_AT(rx1, ry1, rz0);
800  b = lerp(sx, u, v);
801 
802  c = lerp(sy, a, b); /* interpolate in y at lo x */
803 
804  q = g[b00 + bz1];
805  u = VALUE_AT(rx0, ry0, rz1);
806  q = g[b10 + bz1];
807  v = VALUE_AT(rx1, ry0, rz1);
808  a = lerp(sx, u, v);
809 
810  q = g[b01 + bz1];
811  u = VALUE_AT(rx0, ry1, rz1);
812  q = g[b11 + bz1];
813  v = VALUE_AT(rx1, ry1, rz1);
814  b = lerp(sx, u, v);
815 
816  d = lerp(sy, a, b); /* interpolate in y at hi x */
817 
818  return 1.5f * lerp(sz, c, d); /* interpolate in z */
819 
820 #undef VALUE_AT
821 #undef SURVE
822 }
823 
824 /* for use with BLI_noise_generic_noise/gTurbulence, returns signed noise */
825 static float orgPerlinNoise(float x, float y, float z)
826 {
827  float v[3] = {x, y, z};
828  return noise3_perlin(v);
829 }
830 
831 /* for use with BLI_noise_generic_noise/gTurbulence, returns unsigned noise */
832 static float orgPerlinNoiseU(float x, float y, float z)
833 {
834  float v[3] = {x, y, z};
835  return (0.5f + 0.5f * noise3_perlin(v));
836 }
837 
838 /* *************** CALL AS: *************** */
839 
840 float BLI_noise_hnoisep(float noisesize, float x, float y, float z)
841 {
842  float vec[3];
843 
844  vec[0] = x / noisesize;
845  vec[1] = y / noisesize;
846  vec[2] = z / noisesize;
847 
848  return noise3_perlin(vec);
849 }
850 
853 /* -------------------------------------------------------------------- */
857 /* distance metrics for voronoi, e parameter only used in Minkowski */
858 /* Camberra omitted, didn't seem useful */
859 
860 /* distance squared */
861 static float dist_Squared(float x, float y, float z, float e)
862 {
863  (void)e;
864  return (x * x + y * y + z * z);
865 }
866 /* real distance */
867 static float dist_Real(float x, float y, float z, float e)
868 {
869  (void)e;
870  return sqrtf(x * x + y * y + z * z);
871 }
872 /* Manhattan/Taxi-Cab/City-Block distance. */
873 static float dist_Manhattan(float x, float y, float z, float e)
874 {
875  (void)e;
876  return (fabsf(x) + fabsf(y) + fabsf(z));
877 }
878 /* Chebychev */
879 static float dist_Chebychev(float x, float y, float z, float e)
880 {
881  (void)e;
882 
883  x = fabsf(x);
884  y = fabsf(y);
885  z = fabsf(z);
886  float t = (x > y) ? x : y;
887  return ((z > t) ? z : t);
888 }
889 
890 /* minkowski preset exponent 0.5 */
891 static float dist_MinkovskyH(float x, float y, float z, float e)
892 {
893  float d = sqrtf(fabsf(x)) + sqrtf(fabsf(y)) + sqrtf(fabsf(z));
894  (void)e;
895  return (d * d);
896 }
897 
898 /* minkowski preset exponent 4 */
899 static float dist_Minkovsky4(float x, float y, float z, float e)
900 {
901  (void)e;
902  x *= x;
903  y *= y;
904  z *= z;
905  return sqrtf(sqrtf(x * x + y * y + z * z));
906 }
907 
908 /* Minkowski, general case, slow, maybe too slow to be useful */
909 static float dist_Minkovsky(float x, float y, float z, float e)
910 {
911  return powf(powf(fabsf(x), e) + powf(fabsf(y), e) + powf(fabsf(z), e), 1.0f / e);
912 }
913 
914 void BLI_noise_voronoi(float x, float y, float z, float *da, float *pa, float me, int dtype)
915 {
916  float (*distfunc)(float, float, float, float);
917  switch (dtype) {
918  case 1:
919  distfunc = dist_Squared;
920  break;
921  case 2:
922  distfunc = dist_Manhattan;
923  break;
924  case 3:
925  distfunc = dist_Chebychev;
926  break;
927  case 4:
928  distfunc = dist_MinkovskyH;
929  break;
930  case 5:
931  distfunc = dist_Minkovsky4;
932  break;
933  case 6:
934  distfunc = dist_Minkovsky;
935  break;
936  case 0:
937  default:
938  distfunc = dist_Real;
939  break;
940  }
941 
942  int xi = (int)(floor(x));
943  int yi = (int)(floor(y));
944  int zi = (int)(floor(z));
945  da[0] = da[1] = da[2] = da[3] = 1e10f;
946  for (int xx = xi - 1; xx <= xi + 1; xx++) {
947  for (int yy = yi - 1; yy <= yi + 1; yy++) {
948  for (int zz = zi - 1; zz <= zi + 1; zz++) {
949  const float *p = HASHPNT(xx, yy, zz);
950  float xd = x - (p[0] + xx);
951  float yd = y - (p[1] + yy);
952  float zd = z - (p[2] + zz);
953  float d = distfunc(xd, yd, zd, me);
954  if (d < da[0]) {
955  da[3] = da[2];
956  da[2] = da[1];
957  da[1] = da[0];
958  da[0] = d;
959  pa[9] = pa[6];
960  pa[10] = pa[7];
961  pa[11] = pa[8];
962  pa[6] = pa[3];
963  pa[7] = pa[4];
964  pa[8] = pa[5];
965  pa[3] = pa[0];
966  pa[4] = pa[1];
967  pa[5] = pa[2];
968  pa[0] = p[0] + xx;
969  pa[1] = p[1] + yy;
970  pa[2] = p[2] + zz;
971  }
972  else if (d < da[1]) {
973  da[3] = da[2];
974  da[2] = da[1];
975  da[1] = d;
976  pa[9] = pa[6];
977  pa[10] = pa[7];
978  pa[11] = pa[8];
979  pa[6] = pa[3];
980  pa[7] = pa[4];
981  pa[8] = pa[5];
982  pa[3] = p[0] + xx;
983  pa[4] = p[1] + yy;
984  pa[5] = p[2] + zz;
985  }
986  else if (d < da[2]) {
987  da[3] = da[2];
988  da[2] = d;
989  pa[9] = pa[6];
990  pa[10] = pa[7];
991  pa[11] = pa[8];
992  pa[6] = p[0] + xx;
993  pa[7] = p[1] + yy;
994  pa[8] = p[2] + zz;
995  }
996  else if (d < da[3]) {
997  da[3] = d;
998  pa[9] = p[0] + xx;
999  pa[10] = p[1] + yy;
1000  pa[11] = p[2] + zz;
1001  }
1002  }
1003  }
1004  }
1005 }
1006 
1007 /* returns different feature points for use in BLI_noise_generic_noise() */
1008 static float voronoi_F1(float x, float y, float z)
1009 {
1010  float da[4], pa[12];
1011  BLI_noise_voronoi(x, y, z, da, pa, 1, 0);
1012  return da[0];
1013 }
1014 
1015 static float voronoi_F2(float x, float y, float z)
1016 {
1017  float da[4], pa[12];
1018  BLI_noise_voronoi(x, y, z, da, pa, 1, 0);
1019  return da[1];
1020 }
1021 
1022 static float voronoi_F3(float x, float y, float z)
1023 {
1024  float da[4], pa[12];
1025  BLI_noise_voronoi(x, y, z, da, pa, 1, 0);
1026  return da[2];
1027 }
1028 
1029 static float voronoi_F4(float x, float y, float z)
1030 {
1031  float da[4], pa[12];
1032  BLI_noise_voronoi(x, y, z, da, pa, 1, 0);
1033  return da[3];
1034 }
1035 
1036 static float voronoi_F1F2(float x, float y, float z)
1037 {
1038  float da[4], pa[12];
1039  BLI_noise_voronoi(x, y, z, da, pa, 1, 0);
1040  return (da[1] - da[0]);
1041 }
1042 
1043 /* Crackle type pattern, just a scale/clamp of F2-F1 */
1044 static float voronoi_Cr(float x, float y, float z)
1045 {
1046  float t = 10 * voronoi_F1F2(x, y, z);
1047  if (t > 1.0f) {
1048  return 1.0f;
1049  }
1050  return t;
1051 }
1052 
1053 /* Signed version of all 6 of the above, just 2x-1, not really correct though
1054  * (range is potentially (0, sqrt(6)).
1055  * Used in the musgrave functions */
1056 static float voronoi_F1S(float x, float y, float z)
1057 {
1058  float da[4], pa[12];
1059  BLI_noise_voronoi(x, y, z, da, pa, 1, 0);
1060  return (2.0f * da[0] - 1.0f);
1061 }
1062 
1063 static float voronoi_F2S(float x, float y, float z)
1064 {
1065  float da[4], pa[12];
1066  BLI_noise_voronoi(x, y, z, da, pa, 1, 0);
1067  return (2.0f * da[1] - 1.0f);
1068 }
1069 
1070 static float voronoi_F3S(float x, float y, float z)
1071 {
1072  float da[4], pa[12];
1073  BLI_noise_voronoi(x, y, z, da, pa, 1, 0);
1074  return (2.0f * da[2] - 1.0f);
1075 }
1076 
1077 static float voronoi_F4S(float x, float y, float z)
1078 {
1079  float da[4], pa[12];
1080  BLI_noise_voronoi(x, y, z, da, pa, 1, 0);
1081  return (2.0f * da[3] - 1.0f);
1082 }
1083 
1084 static float voronoi_F1F2S(float x, float y, float z)
1085 {
1086  float da[4], pa[12];
1087  BLI_noise_voronoi(x, y, z, da, pa, 1, 0);
1088  return (2.0f * (da[1] - da[0]) - 1.0f);
1089 }
1090 
1091 /* Crackle type pattern, just a scale/clamp of F2-F1 */
1092 static float voronoi_CrS(float x, float y, float z)
1093 {
1094  float t = 10 * voronoi_F1F2(x, y, z);
1095  if (t > 1.0f) {
1096  return 1.0f;
1097  }
1098  return (2.0f * t - 1.0f);
1099 }
1100 
1103 /* -------------------------------------------------------------------- */
1108 static float BLI_cellNoiseU(float x, float y, float z)
1109 {
1110  /* avoid precision issues on unit coordinates */
1111  x = (x + 0.000001f) * 1.00001f;
1112  y = (y + 0.000001f) * 1.00001f;
1113  z = (z + 0.000001f) * 1.00001f;
1114 
1115  int xi = (int)(floor(x));
1116  int yi = (int)(floor(y));
1117  int zi = (int)(floor(z));
1118  unsigned int n = xi + yi * 1301 + zi * 314159;
1119  n ^= (n << 13);
1120  return ((float)(n * (n * n * 15731 + 789221) + 1376312589) / 4294967296.0f);
1121 }
1122 
1123 float BLI_noise_cell(float x, float y, float z)
1124 {
1125  return (2.0f * BLI_cellNoiseU(x, y, z) - 1.0f);
1126 }
1127 
1128 void BLI_noise_cell_v3(float x, float y, float z, float ca[3])
1129 {
1130  /* avoid precision issues on unit coordinates */
1131  x = (x + 0.000001f) * 1.00001f;
1132  y = (y + 0.000001f) * 1.00001f;
1133  z = (z + 0.000001f) * 1.00001f;
1134 
1135  int xi = (int)(floor(x));
1136  int yi = (int)(floor(y));
1137  int zi = (int)(floor(z));
1138  const float *p = HASHPNT(xi, yi, zi);
1139  ca[0] = p[0];
1140  ca[1] = p[1];
1141  ca[2] = p[2];
1142 }
1143 
1146 /* -------------------------------------------------------------------- */
1151  float noisesize, float x, float y, float z, bool hard, int noisebasis)
1152 {
1153  float (*noisefunc)(float, float, float);
1154 
1155  switch (noisebasis) {
1156  case 1:
1157  noisefunc = orgPerlinNoiseU;
1158  break;
1159  case 2:
1160  noisefunc = newPerlinU;
1161  break;
1162  case 3:
1163  noisefunc = voronoi_F1;
1164  break;
1165  case 4:
1166  noisefunc = voronoi_F2;
1167  break;
1168  case 5:
1169  noisefunc = voronoi_F3;
1170  break;
1171  case 6:
1172  noisefunc = voronoi_F4;
1173  break;
1174  case 7:
1175  noisefunc = voronoi_F1F2;
1176  break;
1177  case 8:
1178  noisefunc = voronoi_Cr;
1179  break;
1180  case 14:
1181  noisefunc = BLI_cellNoiseU;
1182  break;
1183  case 0:
1184  default: {
1185  noisefunc = orgBlenderNoise;
1186  /* add one to make return value same as BLI_noise_hnoise */
1187  x += 1;
1188  y += 1;
1189  z += 1;
1190  break;
1191  }
1192  }
1193 
1194  if (noisesize != 0.0f) {
1195  noisesize = 1.0f / noisesize;
1196  x *= noisesize;
1197  y *= noisesize;
1198  z *= noisesize;
1199  }
1200 
1201  if (hard) {
1202  return fabsf(2.0f * noisefunc(x, y, z) - 1.0f);
1203  }
1204  return noisefunc(x, y, z);
1205 }
1206 
1208  float noisesize, float x, float y, float z, int oct, bool hard, int noisebasis)
1209 {
1210  float (*noisefunc)(float, float, float);
1211  switch (noisebasis) {
1212  case 1:
1213  noisefunc = orgPerlinNoiseU;
1214  break;
1215  case 2:
1216  noisefunc = newPerlinU;
1217  break;
1218  case 3:
1219  noisefunc = voronoi_F1;
1220  break;
1221  case 4:
1222  noisefunc = voronoi_F2;
1223  break;
1224  case 5:
1225  noisefunc = voronoi_F3;
1226  break;
1227  case 6:
1228  noisefunc = voronoi_F4;
1229  break;
1230  case 7:
1231  noisefunc = voronoi_F1F2;
1232  break;
1233  case 8:
1234  noisefunc = voronoi_Cr;
1235  break;
1236  case 14:
1237  noisefunc = BLI_cellNoiseU;
1238  break;
1239  case 0:
1240  default:
1241  noisefunc = orgBlenderNoise;
1242  x += 1;
1243  y += 1;
1244  z += 1;
1245  break;
1246  }
1247 
1248  if (noisesize != 0.0f) {
1249  noisesize = 1.0f / noisesize;
1250  x *= noisesize;
1251  y *= noisesize;
1252  z *= noisesize;
1253  }
1254 
1255  float sum = 0, amp = 1, fscale = 1;
1256  for (int i = 0; i <= oct; i++, amp *= 0.5f, fscale *= 2.0f) {
1257  float t = noisefunc(fscale * x, fscale * y, fscale * z);
1258  if (hard) {
1259  t = fabsf(2.0f * t - 1.0f);
1260  }
1261  sum += t * amp;
1262  }
1263 
1264  sum *= ((float)(1 << oct) / (float)((1 << (oct + 1)) - 1));
1265 
1266  return sum;
1267 }
1268 
1270  float x, float y, float z, float H, float lacunarity, float octaves, int noisebasis)
1271 {
1272  /* The following code is based on Ken Musgrave's explanations and sample
1273  * source code in the book "Texturing and Modeling: A procedural approach". */
1274 
1275  float (*noisefunc)(float, float, float);
1276  switch (noisebasis) {
1277  case 1:
1278  noisefunc = orgPerlinNoise;
1279  break;
1280  case 2:
1281  noisefunc = newPerlin;
1282  break;
1283  case 3:
1284  noisefunc = voronoi_F1S;
1285  break;
1286  case 4:
1287  noisefunc = voronoi_F2S;
1288  break;
1289  case 5:
1290  noisefunc = voronoi_F3S;
1291  break;
1292  case 6:
1293  noisefunc = voronoi_F4S;
1294  break;
1295  case 7:
1296  noisefunc = voronoi_F1F2S;
1297  break;
1298  case 8:
1299  noisefunc = voronoi_CrS;
1300  break;
1301  case 14:
1302  noisefunc = BLI_noise_cell;
1303  break;
1304  case 0:
1305  default: {
1306  noisefunc = orgBlenderNoiseS;
1307  break;
1308  }
1309  }
1310 
1311  float value = 0.0, pwr = 1.0, pwHL = powf(lacunarity, -H);
1312  for (int i = 0; i < (int)octaves; i++) {
1313  value += noisefunc(x, y, z) * pwr;
1314  pwr *= pwHL;
1315  x *= lacunarity;
1316  y *= lacunarity;
1317  z *= lacunarity;
1318  }
1319 
1320  float rmd = octaves - floorf(octaves);
1321  if (rmd != 0.0f) {
1322  value += rmd * noisefunc(x, y, z) * pwr;
1323  }
1324 
1325  return value;
1326 
1327 } /* fBm() */
1328 
1330  float x, float y, float z, float H, float lacunarity, float octaves, int noisebasis)
1331 {
1332  /* This one is in fact rather confusing,
1333  * there seem to be errors in the original source code (in all three versions of proc.text&mod),
1334  * I modified it to something that made sense to me, so it might be wrong. */
1335 
1336  float (*noisefunc)(float, float, float);
1337  switch (noisebasis) {
1338  case 1:
1339  noisefunc = orgPerlinNoise;
1340  break;
1341  case 2:
1342  noisefunc = newPerlin;
1343  break;
1344  case 3:
1345  noisefunc = voronoi_F1S;
1346  break;
1347  case 4:
1348  noisefunc = voronoi_F2S;
1349  break;
1350  case 5:
1351  noisefunc = voronoi_F3S;
1352  break;
1353  case 6:
1354  noisefunc = voronoi_F4S;
1355  break;
1356  case 7:
1357  noisefunc = voronoi_F1F2S;
1358  break;
1359  case 8:
1360  noisefunc = voronoi_CrS;
1361  break;
1362  case 14:
1363  noisefunc = BLI_noise_cell;
1364  break;
1365  case 0:
1366  default: {
1367  noisefunc = orgBlenderNoiseS;
1368  break;
1369  }
1370  }
1371 
1372  float value = 1.0, pwr = 1.0, pwHL = powf(lacunarity, -H);
1373  for (int i = 0; i < (int)octaves; i++) {
1374  value *= (pwr * noisefunc(x, y, z) + 1.0f);
1375  pwr *= pwHL;
1376  x *= lacunarity;
1377  y *= lacunarity;
1378  z *= lacunarity;
1379  }
1380  float rmd = octaves - floorf(octaves);
1381  if (rmd != 0.0f) {
1382  value *= (rmd * noisefunc(x, y, z) * pwr + 1.0f);
1383  }
1384 
1385  return value;
1386 }
1387 
1389  float y,
1390  float z,
1391  float H,
1392  float lacunarity,
1393  float octaves,
1394  float offset,
1395  int noisebasis)
1396 {
1397  float (*noisefunc)(float, float, float);
1398  switch (noisebasis) {
1399  case 1:
1400  noisefunc = orgPerlinNoise;
1401  break;
1402  case 2:
1403  noisefunc = newPerlin;
1404  break;
1405  case 3:
1406  noisefunc = voronoi_F1S;
1407  break;
1408  case 4:
1409  noisefunc = voronoi_F2S;
1410  break;
1411  case 5:
1412  noisefunc = voronoi_F3S;
1413  break;
1414  case 6:
1415  noisefunc = voronoi_F4S;
1416  break;
1417  case 7:
1418  noisefunc = voronoi_F1F2S;
1419  break;
1420  case 8:
1421  noisefunc = voronoi_CrS;
1422  break;
1423  case 14:
1424  noisefunc = BLI_noise_cell;
1425  break;
1426  case 0:
1427  default: {
1428  noisefunc = orgBlenderNoiseS;
1429  break;
1430  }
1431  }
1432 
1433  /* first unscaled octave of function; later octaves are scaled */
1434  float value = offset + noisefunc(x, y, z);
1435  x *= lacunarity;
1436  y *= lacunarity;
1437  z *= lacunarity;
1438 
1439  float pwHL = powf(lacunarity, -H);
1440  float pwr = pwHL; /* starts with i=1 instead of 0 */
1441  for (int i = 1; i < (int)octaves; i++) {
1442  float increment = (noisefunc(x, y, z) + offset) * pwr * value;
1443  value += increment;
1444  pwr *= pwHL;
1445  x *= lacunarity;
1446  y *= lacunarity;
1447  z *= lacunarity;
1448  }
1449 
1450  float rmd = octaves - floorf(octaves);
1451  if (rmd != 0.0f) {
1452  float increment = (noisefunc(x, y, z) + offset) * pwr * value;
1453  value += rmd * increment;
1454  }
1455  return value;
1456 }
1457 
1459  float y,
1460  float z,
1461  float H,
1462  float lacunarity,
1463  float octaves,
1464  float offset,
1465  float gain,
1466  int noisebasis)
1467 {
1468  float (*noisefunc)(float, float, float);
1469  switch (noisebasis) {
1470  case 1:
1471  noisefunc = orgPerlinNoise;
1472  break;
1473  case 2:
1474  noisefunc = newPerlin;
1475  break;
1476  case 3:
1477  noisefunc = voronoi_F1S;
1478  break;
1479  case 4:
1480  noisefunc = voronoi_F2S;
1481  break;
1482  case 5:
1483  noisefunc = voronoi_F3S;
1484  break;
1485  case 6:
1486  noisefunc = voronoi_F4S;
1487  break;
1488  case 7:
1489  noisefunc = voronoi_F1F2S;
1490  break;
1491  case 8:
1492  noisefunc = voronoi_CrS;
1493  break;
1494  case 14:
1495  noisefunc = BLI_noise_cell;
1496  break;
1497  case 0:
1498  default: {
1499  noisefunc = orgBlenderNoiseS;
1500  break;
1501  }
1502  }
1503 
1504  float result = noisefunc(x, y, z) + offset;
1505  float weight = gain * result;
1506  x *= lacunarity;
1507  y *= lacunarity;
1508  z *= lacunarity;
1509 
1510  float pwHL = powf(lacunarity, -H);
1511  float pwr = pwHL; /* starts with i=1 instead of 0 */
1512  for (int i = 1; (weight > 0.001f) && (i < (int)octaves); i++) {
1513  if (weight > 1.0f) {
1514  weight = 1.0f;
1515  }
1516  float signal = (noisefunc(x, y, z) + offset) * pwr;
1517  pwr *= pwHL;
1518  result += weight * signal;
1519  weight *= gain * signal;
1520  x *= lacunarity;
1521  y *= lacunarity;
1522  z *= lacunarity;
1523  }
1524 
1525  float rmd = octaves - floorf(octaves);
1526  if (rmd != 0.0f) {
1527  result += rmd * ((noisefunc(x, y, z) + offset) * pwr);
1528  }
1529 
1530  return result;
1531 
1532 } /* HybridMultifractal() */
1533 
1535  float y,
1536  float z,
1537  float H,
1538  float lacunarity,
1539  float octaves,
1540  float offset,
1541  float gain,
1542  int noisebasis)
1543 {
1544  float (*noisefunc)(float, float, float);
1545  switch (noisebasis) {
1546  case 1:
1547  noisefunc = orgPerlinNoise;
1548  break;
1549  case 2:
1550  noisefunc = newPerlin;
1551  break;
1552  case 3:
1553  noisefunc = voronoi_F1S;
1554  break;
1555  case 4:
1556  noisefunc = voronoi_F2S;
1557  break;
1558  case 5:
1559  noisefunc = voronoi_F3S;
1560  break;
1561  case 6:
1562  noisefunc = voronoi_F4S;
1563  break;
1564  case 7:
1565  noisefunc = voronoi_F1F2S;
1566  break;
1567  case 8:
1568  noisefunc = voronoi_CrS;
1569  break;
1570  case 14:
1571  noisefunc = BLI_noise_cell;
1572  break;
1573  case 0:
1574  default: {
1575  noisefunc = orgBlenderNoiseS;
1576  break;
1577  }
1578  }
1579 
1580  float signal = powf(offset - fabsf(noisefunc(x, y, z)), 2);
1581  float result = signal;
1582  float pwHL = powf(lacunarity, -H);
1583  float pwr = pwHL; /* starts with i=1 instead of 0 */
1584  for (int i = 1; i < (int)octaves; i++) {
1585  x *= lacunarity;
1586  y *= lacunarity;
1587  z *= lacunarity;
1588  float weight = signal * gain;
1589  if (weight > 1.0f) {
1590  weight = 1.0f;
1591  }
1592  else if (weight < 0.0f) {
1593  weight = 0.0f;
1594  }
1595  signal = offset - fabsf(noisefunc(x, y, z));
1596  signal *= signal;
1597  signal *= weight;
1598  result += signal * pwr;
1599  pwr *= pwHL;
1600  }
1601 
1602  return result;
1603 } /* RidgedMultifractal() */
1604 
1606  float x, float y, float z, float distortion, int nbas1, int nbas2)
1607 {
1608  float (*noisefunc1)(float, float, float);
1609  switch (nbas1) {
1610  case 1:
1611  noisefunc1 = orgPerlinNoise;
1612  break;
1613  case 2:
1614  noisefunc1 = newPerlin;
1615  break;
1616  case 3:
1617  noisefunc1 = voronoi_F1S;
1618  break;
1619  case 4:
1620  noisefunc1 = voronoi_F2S;
1621  break;
1622  case 5:
1623  noisefunc1 = voronoi_F3S;
1624  break;
1625  case 6:
1626  noisefunc1 = voronoi_F4S;
1627  break;
1628  case 7:
1629  noisefunc1 = voronoi_F1F2S;
1630  break;
1631  case 8:
1632  noisefunc1 = voronoi_CrS;
1633  break;
1634  case 14:
1635  noisefunc1 = BLI_noise_cell;
1636  break;
1637  case 0:
1638  default: {
1639  noisefunc1 = orgBlenderNoiseS;
1640  break;
1641  }
1642  }
1643 
1644  float (*noisefunc2)(float, float, float);
1645  switch (nbas2) {
1646  case 1:
1647  noisefunc2 = orgPerlinNoise;
1648  break;
1649  case 2:
1650  noisefunc2 = newPerlin;
1651  break;
1652  case 3:
1653  noisefunc2 = voronoi_F1S;
1654  break;
1655  case 4:
1656  noisefunc2 = voronoi_F2S;
1657  break;
1658  case 5:
1659  noisefunc2 = voronoi_F3S;
1660  break;
1661  case 6:
1662  noisefunc2 = voronoi_F4S;
1663  break;
1664  case 7:
1665  noisefunc2 = voronoi_F1F2S;
1666  break;
1667  case 8:
1668  noisefunc2 = voronoi_CrS;
1669  break;
1670  case 14:
1671  noisefunc2 = BLI_noise_cell;
1672  break;
1673  case 0:
1674  default: {
1675  noisefunc2 = orgBlenderNoiseS;
1676  break;
1677  }
1678  }
1679 
1680  /* get a random vector and scale the randomization */
1681  float rv[3] = {
1682  rv[0] = noisefunc1(x + 13.5f, y + 13.5f, z + 13.5f) * distortion,
1683  rv[1] = noisefunc1(x, y, z) * distortion,
1684  rv[2] = noisefunc1(x - 13.5f, y - 13.5f, z - 13.5f) * distortion,
1685  };
1686 
1687  return noisefunc2(x + rv[0], y + rv[1], z + rv[2]); /* distorted-domain noise */
1688 }
1689 
typedef float(TangentPoint)[2]
#define BLI_INLINE
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
#define Z
Definition: GeomUtils.cpp:201
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Retrieve a color or the default fallback if none is specified Separate Split a vector into its X
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Retrieve a color or the default fallback if none is specified Separate Split a vector into its Y
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
#define A
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
static T sum(const btAlignedObjectArray< T > &items)
#define powf(x, y)
Definition: cuda/compat.h:103
SyclQueue void void size_t num_bytes void
ccl_gpu_kernel_postfix ccl_global float int int sy
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
ccl_gpu_kernel_postfix ccl_global float int sx
#define B
#define H(x, y, z)
#define floorf(x)
Definition: metal/compat.h:224
#define fabsf(x)
Definition: metal/compat.h:219
#define sqrtf(x)
Definition: metal/compat.h:243
static unsigned c
Definition: RandGen.cpp:83
static unsigned a[3]
Definition: RandGen.cpp:78
T floor(const T &a)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static const pxr::TfToken g("g", pxr::TfToken::Immortal)
static const float g_perlin_data_v3[512+2][3]
Definition: noise.c:491
static float voronoi_F4(float x, float y, float z)
Definition: noise.c:1029
BLI_INLINE float lerp(float t, float a, float b)
Definition: noise.c:260
#define VALUE_AT(rx, ry, rz)
static float dist_Minkovsky4(float x, float y, float z, float e)
Definition: noise.c:899
float BLI_noise_mg_hetero_terrain(float x, float y, float z, float H, float lacunarity, float octaves, float offset, int noisebasis)
Definition: noise.c:1388
static float dist_Real(float x, float y, float z, float e)
Definition: noise.c:867
static float orgPerlinNoise(float x, float y, float z)
Definition: noise.c:825
static float orgBlenderNoiseS(float x, float y, float z)
Definition: noise.c:416
static float dist_Minkovsky(float x, float y, float z, float e)
Definition: noise.c:909
static float newPerlinU(float x, float y, float z)
Definition: noise.c:316
float BLI_noise_mg_multi_fractal(float x, float y, float z, float H, float lacunarity, float octaves, int noisebasis)
Definition: noise.c:1329
static float noise3_perlin(const float vec[3])
Definition: noise.c:761
float BLI_noise_mg_ridged_multi_fractal(float x, float y, float z, float H, float lacunarity, float octaves, float offset, float gain, int noisebasis)
Definition: noise.c:1534
static float newPerlin(float x, float y, float z)
Definition: noise.c:279
static float voronoi_F1F2S(float x, float y, float z)
Definition: noise.c:1084
static float voronoi_CrS(float x, float y, float z)
Definition: noise.c:1092
static float orgBlenderNoise(float x, float y, float z)
Definition: noise.c:328
float BLI_noise_mg_variable_lacunarity(float x, float y, float z, float distortion, int nbas1, int nbas2)
Definition: noise.c:1605
static float orgPerlinNoiseU(float x, float y, float z)
Definition: noise.c:832
#define hash
Definition: noise.c:153
float BLI_noise_cell(float x, float y, float z)
Definition: noise.c:1123
static float voronoi_F1F2(float x, float y, float z)
Definition: noise.c:1036
const unsigned char BLI_noise_hash_uchar_512[512]
Definition: noise.c:119
float BLI_noise_generic_noise(float noisesize, float x, float y, float z, bool hard, int noisebasis)
Definition: noise.c:1150
static float voronoi_F1S(float x, float y, float z)
Definition: noise.c:1056
static const float hashpntf[768]
Definition: noise.c:29
static float voronoi_Cr(float x, float y, float z)
Definition: noise.c:1044
BLI_INLINE float npfade(float t)
Definition: noise.c:265
static float voronoi_F1(float x, float y, float z)
Definition: noise.c:1008
static float voronoi_F4S(float x, float y, float z)
Definition: noise.c:1077
static float dist_Squared(float x, float y, float z, float e)
Definition: noise.c:861
float BLI_noise_turbulence(float noisesize, float x, float y, float z, int nr)
Definition: noise.c:436
static float voronoi_F2S(float x, float y, float z)
Definition: noise.c:1063
static float dist_MinkovskyH(float x, float y, float z, float e)
Definition: noise.c:891
static float voronoi_F2(float x, float y, float z)
Definition: noise.c:1015
static const char g_perlin_data_ub[512+2]
Definition: noise.c:455
static const float hashvectf[768]
Definition: noise.c:155
float BLI_noise_hnoisep(float noisesize, float x, float y, float z)
Definition: noise.c:840
void BLI_noise_voronoi(float x, float y, float z, float *da, float *pa, float me, int dtype)
Definition: noise.c:914
static float voronoi_F3S(float x, float y, float z)
Definition: noise.c:1070
BLI_INLINE float grad(int hash_val, float x, float y, float z)
Definition: noise.c:270
float BLI_noise_hnoise(float noisesize, float x, float y, float z)
Definition: noise.c:423
static float dist_Manhattan(float x, float y, float z, float e)
Definition: noise.c:873
void BLI_noise_cell_v3(float x, float y, float z, float ca[3])
Definition: noise.c:1128
#define SETUP(val, b0, b1, r0, r1)
Definition: noise.c:751
float BLI_noise_mg_fbm(float x, float y, float z, float H, float lacunarity, float octaves, int noisebasis)
Definition: noise.c:1269
#define SURVE(t)
static float dist_Chebychev(float x, float y, float z, float e)
Definition: noise.c:879
static float BLI_cellNoiseU(float x, float y, float z)
Definition: noise.c:1108
float BLI_noise_mg_hybrid_multi_fractal(float x, float y, float z, float H, float lacunarity, float octaves, float offset, float gain, int noisebasis)
Definition: noise.c:1458
static float voronoi_F3(float x, float y, float z)
Definition: noise.c:1022
float BLI_noise_generic_turbulence(float noisesize, float x, float y, float z, int oct, bool hard, int noisebasis)
Definition: noise.c:1207
#define HASHPNT(x, y, z)
Definition: noise.c:28
Definition: pbvh_intern.h:21