@@ -253,6 +253,10 @@ struct CellNoise3D:Noise
253
253
254
254
var r2 : Double = self . distance ( from: sample, generating_point: near)
255
255
256
+ // the following unrolled code is not actually necessary — the loop at the
257
+ // bottom of the function is capable of handling all cases, but unrolling
258
+ // it partially results in an enormous performance gain, about a factor
259
+ // of 7 over the pure loop version.
256
260
@inline ( __always)
257
261
func test( generating_point: IntV3 , dx: Double = 0 , dy: Double = 0 , dz: Double = 0 )
258
262
{
@@ -274,7 +278,7 @@ struct CellNoise3D:Noise
274
278
275
279
test ( generating_point: far, dx: nearpoint_disp. x - 0.5 , dy: nearpoint_disp. y - 0.5 , dz: nearpoint_disp. z - 0.5 )
276
280
277
- // Testing shows about 47.85% of samples are eliminated by here
281
+ // EARLY EXIT: Testing shows about 47.85% of samples are eliminated by here
278
282
// (0.25, [(1, 0, 0), ( 0, 1, 0), ( 0, 0, 1),
279
283
// (0, -1, 1), ( 0, 1, -1), ( 1, 0, -1), (-1, 0, 1), (-1, 1, 0), (1, -1, 0),
280
284
// (1, -1, -1), (-1, 1, -1), (-1, -1, 1)])
@@ -300,7 +304,7 @@ struct CellNoise3D:Noise
300
304
test ( generating_point: ( far. a, inner. b, far. c) , dx: nearpoint_disp. x - 0.5 , dy: nearpoint_disp. y + 0.5 , dz: nearpoint_disp. z - 0.5 )
301
305
test ( generating_point: ( far. a, far. b, inner. c) , dx: nearpoint_disp. x - 0.5 , dy: nearpoint_disp. y - 0.5 , dz: nearpoint_disp. z + 0.5 )
302
306
303
- // Testing shows about 88.60% of samples are eliminated by here
307
+ // EARLY EXIT: Testing shows about 88.60% of samples are eliminated by here
304
308
// (0.5 , [(0, 1, 1), (1, 0, 1), (1, 1, 0), (-1, 1, 1), (1, -1, 1), (1, 1, -1)])
305
309
guard r2 > 0.5
306
310
else
@@ -316,7 +320,7 @@ struct CellNoise3D:Noise
316
320
test ( generating_point: ( inner. a, far. b, inner. c) , dx: nearpoint_disp. x + 0.5 , dy: nearpoint_disp. y - 0.5 , dz: nearpoint_disp. z + 0.5 )
317
321
test ( generating_point: ( inner. a, inner. b, far. c) , dx: nearpoint_disp. x + 0.5 , dy: nearpoint_disp. y + 0.5 , dz: nearpoint_disp. z - 0.5 )
318
322
319
- // Testing shows about 98.26% of samples are eliminated by here
323
+ // EARLY EXIT: Testing shows about 98.26% of samples are eliminated by here
320
324
// (0.75, [(1, 1, 1)])
321
325
guard r2 > 0.75
322
326
else
@@ -353,10 +357,11 @@ struct CellNoise3D:Noise
353
357
354
358
for (kernel_radius2, cell_offsets) : ( r2: Double , cell_offsets: [ ( Int , Int , Int ) ] ) in kernel
355
359
{
360
+ // EARLY EXIT
356
361
guard kernel_radius2 < r2
357
362
else
358
363
{
359
- break // EARLY EXIT
364
+ break
360
365
}
361
366
362
367
for cell_offset : IntV3 in cell_offsets
0 commit comments