summaryrefslogtreecommitdiffstats log msg author committer range
blob: 3eebaabfba58c8fc9a7676cbd2124980bc40a762 (plain)
 ```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 ``` ``````/***************************************************************** Implementation of the fractional Brownian motion algorithm. These functions were originally the work of F. Kenton Musgrave. For documentation of the different functions please refer to the book: "Texturing and modeling: a procedural approach" by David S. Ebert et. al. ******************************************************************/ #if defined (_MSC_VER) #include #endif #include #include #include "fbm.h" #if defined(Q_CC_MSVC) #pragma warning(disable:4244) #endif /* Definitions used by the noise2() functions */ //#define B 0x100 //#define BM 0xff #define B 0x20 #define BM 0x1f #define N 0x1000 #define NP 12 /* 2^N */ #define NM 0xfff static int p[B + B + 2]; static float g3[B + B + 2][3]; static float g2[B + B + 2][2]; static float g1[B + B + 2]; static int start = 1; static void init(void); #define s_curve(t) ( t * t * (3. - 2. * t) ) #define lerp(t, a, b) ( a + t * (b - a) ) #define setup(i,b0,b1,r0,r1)\ t = vec[i] + N;\ b0 = ((int)t) & BM;\ b1 = (b0+1) & BM;\ r0 = t - (int)t;\ r1 = r0 - 1.; #define at3(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] ) /* Fractional Brownian Motion function */ double fBm( Vector point, double H, double lacunarity, double octaves, int init ) { double value, frequency, remainder; int i; static double exponent_array[10]; float vec[3]; /* precompute and store spectral weights */ if ( init ) { start = 1; srand( time(0) ); /* seize required memory for exponent_array */ frequency = 1.0; for (i=0; i<=octaves; i++) { /* compute weight for each frequency */ exponent_array[i] = pow( frequency, -H ); frequency *= lacunarity; } } value = 0.0; /* initialize vars to proper values */ frequency = 1.0; vec[0]=point.x; vec[1]=point.y; vec[2]=point.z; /* inner loop of spectral construction */ for (i=0; i