Blender  V3.3
voronoi.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #pragma once
5 
7 
8 /*
9  * SPDX-License-Identifier: MIT
10  * Original code is copyright (c) 2013 Inigo Quilez.
11  *
12  * Smooth Voronoi:
13  *
14  * - https://wiki.blender.org/wiki/User:OmarSquircleArt/GSoC2019/Documentation/Smooth_Voronoi
15  *
16  * Distance To Edge based on:
17  *
18  * - https://www.iquilezles.org/www/articles/voronoilines/voronoilines.htm
19  * - https://www.shadertoy.com/view/ldl3W8
20  *
21  * With optimization to change -2..2 scan window to -1..1 for better performance,
22  * as explained in https://www.shadertoy.com/view/llG3zy.
23  */
24 
25 /* **** 1D Voronoi **** */
26 
28  float b,
30  float exponent)
31 {
32  return fabsf(b - a);
33 }
34 
36  float exponent,
37  float randomness,
39  ccl_private float *outDistance,
40  ccl_private float3 *outColor,
41  ccl_private float *outW)
42 {
43  float cellPosition = floorf(w);
44  float localPosition = w - cellPosition;
45 
46  float minDistance = 8.0f;
47  float targetOffset = 0.0f;
48  float targetPosition = 0.0f;
49  for (int i = -1; i <= 1; i++) {
50  float cellOffset = i;
51  float pointPosition = cellOffset + hash_float_to_float(cellPosition + cellOffset) * randomness;
52  float distanceToPoint = voronoi_distance_1d(pointPosition, localPosition, metric, exponent);
53  if (distanceToPoint < minDistance) {
54  targetOffset = cellOffset;
55  minDistance = distanceToPoint;
56  targetPosition = pointPosition;
57  }
58  }
59  *outDistance = minDistance;
60  *outColor = hash_float_to_float3(cellPosition + targetOffset);
61  *outW = targetPosition + cellPosition;
62 }
63 
65  float smoothness,
66  float exponent,
67  float randomness,
69  ccl_private float *outDistance,
70  ccl_private float3 *outColor,
71  ccl_private float *outW)
72 {
73  float cellPosition = floorf(w);
74  float localPosition = w - cellPosition;
75 
76  float smoothDistance = 8.0f;
77  float smoothPosition = 0.0f;
78  float3 smoothColor = make_float3(0.0f, 0.0f, 0.0f);
79  for (int i = -2; i <= 2; i++) {
80  float cellOffset = i;
81  float pointPosition = cellOffset + hash_float_to_float(cellPosition + cellOffset) * randomness;
82  float distanceToPoint = voronoi_distance_1d(pointPosition, localPosition, metric, exponent);
83  float h = smoothstep(
84  0.0f, 1.0f, 0.5f + 0.5f * (smoothDistance - distanceToPoint) / smoothness);
85  float correctionFactor = smoothness * h * (1.0f - h);
86  smoothDistance = mix(smoothDistance, distanceToPoint, h) - correctionFactor;
87  correctionFactor /= 1.0f + 3.0f * smoothness;
88  float3 cellColor = hash_float_to_float3(cellPosition + cellOffset);
89  smoothColor = mix(smoothColor, cellColor, h) - correctionFactor;
90  smoothPosition = mix(smoothPosition, pointPosition, h) - correctionFactor;
91  }
92  *outDistance = smoothDistance;
93  *outColor = smoothColor;
94  *outW = cellPosition + smoothPosition;
95 }
96 
98  float exponent,
99  float randomness,
101  ccl_private float *outDistance,
102  ccl_private float3 *outColor,
103  ccl_private float *outW)
104 {
105  float cellPosition = floorf(w);
106  float localPosition = w - cellPosition;
107 
108  float distanceF1 = 8.0f;
109  float distanceF2 = 8.0f;
110  float offsetF1 = 0.0f;
111  float positionF1 = 0.0f;
112  float offsetF2 = 0.0f;
113  float positionF2 = 0.0f;
114  for (int i = -1; i <= 1; i++) {
115  float cellOffset = i;
116  float pointPosition = cellOffset + hash_float_to_float(cellPosition + cellOffset) * randomness;
117  float distanceToPoint = voronoi_distance_1d(pointPosition, localPosition, metric, exponent);
118  if (distanceToPoint < distanceF1) {
119  distanceF2 = distanceF1;
120  distanceF1 = distanceToPoint;
121  offsetF2 = offsetF1;
122  offsetF1 = cellOffset;
123  positionF2 = positionF1;
124  positionF1 = pointPosition;
125  }
126  else if (distanceToPoint < distanceF2) {
127  distanceF2 = distanceToPoint;
128  offsetF2 = cellOffset;
129  positionF2 = pointPosition;
130  }
131  }
132  *outDistance = distanceF2;
133  *outColor = hash_float_to_float3(cellPosition + offsetF2);
134  *outW = positionF2 + cellPosition;
135 }
136 
138  float randomness,
139  ccl_private float *outDistance)
140 {
141  float cellPosition = floorf(w);
142  float localPosition = w - cellPosition;
143 
144  float midPointPosition = hash_float_to_float(cellPosition) * randomness;
145  float leftPointPosition = -1.0f + hash_float_to_float(cellPosition - 1.0f) * randomness;
146  float rightPointPosition = 1.0f + hash_float_to_float(cellPosition + 1.0f) * randomness;
147  float distanceToMidLeft = fabsf((midPointPosition + leftPointPosition) / 2.0f - localPosition);
148  float distanceToMidRight = fabsf((midPointPosition + rightPointPosition) / 2.0f - localPosition);
149 
150  *outDistance = min(distanceToMidLeft, distanceToMidRight);
151 }
152 
153 ccl_device void voronoi_n_sphere_radius_1d(float w, float randomness, ccl_private float *outRadius)
154 {
155  float cellPosition = floorf(w);
156  float localPosition = w - cellPosition;
157 
158  float closestPoint = 0.0f;
159  float closestPointOffset = 0.0f;
160  float minDistance = 8.0f;
161  for (int i = -1; i <= 1; i++) {
162  float cellOffset = i;
163  float pointPosition = cellOffset + hash_float_to_float(cellPosition + cellOffset) * randomness;
164  float distanceToPoint = fabsf(pointPosition - localPosition);
165  if (distanceToPoint < minDistance) {
166  minDistance = distanceToPoint;
167  closestPoint = pointPosition;
168  closestPointOffset = cellOffset;
169  }
170  }
171 
172  minDistance = 8.0f;
173  float closestPointToClosestPoint = 0.0f;
174  for (int i = -1; i <= 1; i++) {
175  if (i == 0) {
176  continue;
177  }
178  float cellOffset = i + closestPointOffset;
179  float pointPosition = cellOffset + hash_float_to_float(cellPosition + cellOffset) * randomness;
180  float distanceToPoint = fabsf(closestPoint - pointPosition);
181  if (distanceToPoint < minDistance) {
182  minDistance = distanceToPoint;
183  closestPointToClosestPoint = pointPosition;
184  }
185  }
186  *outRadius = fabsf(closestPointToClosestPoint - closestPoint) / 2.0f;
187 }
188 
189 /* **** 2D Voronoi **** */
190 
192  float2 b,
194  float exponent)
195 {
196  if (metric == NODE_VORONOI_EUCLIDEAN) {
197  return distance(a, b);
198  }
199  else if (metric == NODE_VORONOI_MANHATTAN) {
200  return fabsf(a.x - b.x) + fabsf(a.y - b.y);
201  }
202  else if (metric == NODE_VORONOI_CHEBYCHEV) {
203  return max(fabsf(a.x - b.x), fabsf(a.y - b.y));
204  }
205  else if (metric == NODE_VORONOI_MINKOWSKI) {
206  return powf(powf(fabsf(a.x - b.x), exponent) + powf(fabsf(a.y - b.y), exponent),
207  1.0f / exponent);
208  }
209  else {
210  return 0.0f;
211  }
212 }
213 
215  float exponent,
216  float randomness,
218  ccl_private float *outDistance,
219  ccl_private float3 *outColor,
220  ccl_private float2 *outPosition)
221 {
222  float2 cellPosition = floor(coord);
223  float2 localPosition = coord - cellPosition;
224 
225  float minDistance = 8.0f;
226  float2 targetOffset = make_float2(0.0f, 0.0f);
227  float2 targetPosition = make_float2(0.0f, 0.0f);
228  for (int j = -1; j <= 1; j++) {
229  for (int i = -1; i <= 1; i++) {
230  float2 cellOffset = make_float2(i, j);
231  float2 pointPosition = cellOffset +
232  hash_float2_to_float2(cellPosition + cellOffset) * randomness;
233  float distanceToPoint = voronoi_distance_2d(pointPosition, localPosition, metric, exponent);
234  if (distanceToPoint < minDistance) {
235  targetOffset = cellOffset;
236  minDistance = distanceToPoint;
237  targetPosition = pointPosition;
238  }
239  }
240  }
241  *outDistance = minDistance;
242  *outColor = hash_float2_to_float3(cellPosition + targetOffset);
243  *outPosition = targetPosition + cellPosition;
244 }
245 
247  float smoothness,
248  float exponent,
249  float randomness,
251  ccl_private float *outDistance,
252  ccl_private float3 *outColor,
253  ccl_private float2 *outPosition)
254 {
255  float2 cellPosition = floor(coord);
256  float2 localPosition = coord - cellPosition;
257 
258  float smoothDistance = 8.0f;
259  float3 smoothColor = make_float3(0.0f, 0.0f, 0.0f);
260  float2 smoothPosition = make_float2(0.0f, 0.0f);
261  for (int j = -2; j <= 2; j++) {
262  for (int i = -2; i <= 2; i++) {
263  float2 cellOffset = make_float2(i, j);
264  float2 pointPosition = cellOffset +
265  hash_float2_to_float2(cellPosition + cellOffset) * randomness;
266  float distanceToPoint = voronoi_distance_2d(pointPosition, localPosition, metric, exponent);
267  float h = smoothstep(
268  0.0f, 1.0f, 0.5f + 0.5f * (smoothDistance - distanceToPoint) / smoothness);
269  float correctionFactor = smoothness * h * (1.0f - h);
270  smoothDistance = mix(smoothDistance, distanceToPoint, h) - correctionFactor;
271  correctionFactor /= 1.0f + 3.0f * smoothness;
272  float3 cellColor = hash_float2_to_float3(cellPosition + cellOffset);
273  smoothColor = mix(smoothColor, cellColor, h) - correctionFactor;
274  smoothPosition = mix(smoothPosition, pointPosition, h) - correctionFactor;
275  }
276  }
277  *outDistance = smoothDistance;
278  *outColor = smoothColor;
279  *outPosition = cellPosition + smoothPosition;
280 }
281 
283  float exponent,
284  float randomness,
286  ccl_private float *outDistance,
287  ccl_private float3 *outColor,
288  ccl_private float2 *outPosition)
289 {
290  float2 cellPosition = floor(coord);
291  float2 localPosition = coord - cellPosition;
292 
293  float distanceF1 = 8.0f;
294  float distanceF2 = 8.0f;
295  float2 offsetF1 = make_float2(0.0f, 0.0f);
296  float2 positionF1 = make_float2(0.0f, 0.0f);
297  float2 offsetF2 = make_float2(0.0f, 0.0f);
298  float2 positionF2 = make_float2(0.0f, 0.0f);
299  for (int j = -1; j <= 1; j++) {
300  for (int i = -1; i <= 1; i++) {
301  float2 cellOffset = make_float2(i, j);
302  float2 pointPosition = cellOffset +
303  hash_float2_to_float2(cellPosition + cellOffset) * randomness;
304  float distanceToPoint = voronoi_distance_2d(pointPosition, localPosition, metric, exponent);
305  if (distanceToPoint < distanceF1) {
306  distanceF2 = distanceF1;
307  distanceF1 = distanceToPoint;
308  offsetF2 = offsetF1;
309  offsetF1 = cellOffset;
310  positionF2 = positionF1;
311  positionF1 = pointPosition;
312  }
313  else if (distanceToPoint < distanceF2) {
314  distanceF2 = distanceToPoint;
315  offsetF2 = cellOffset;
316  positionF2 = pointPosition;
317  }
318  }
319  }
320  *outDistance = distanceF2;
321  *outColor = hash_float2_to_float3(cellPosition + offsetF2);
322  *outPosition = positionF2 + cellPosition;
323 }
324 
326  float randomness,
327  ccl_private float *outDistance)
328 {
329  float2 cellPosition = floor(coord);
330  float2 localPosition = coord - cellPosition;
331 
332  float2 vectorToClosest = make_float2(0.0f, 0.0f);
333  float minDistance = 8.0f;
334  for (int j = -1; j <= 1; j++) {
335  for (int i = -1; i <= 1; i++) {
336  float2 cellOffset = make_float2(i, j);
337  float2 vectorToPoint = cellOffset +
338  hash_float2_to_float2(cellPosition + cellOffset) * randomness -
339  localPosition;
340  float distanceToPoint = dot(vectorToPoint, vectorToPoint);
341  if (distanceToPoint < minDistance) {
342  minDistance = distanceToPoint;
343  vectorToClosest = vectorToPoint;
344  }
345  }
346  }
347 
348  minDistance = 8.0f;
349  for (int j = -1; j <= 1; j++) {
350  for (int i = -1; i <= 1; i++) {
351  float2 cellOffset = make_float2(i, j);
352  float2 vectorToPoint = cellOffset +
353  hash_float2_to_float2(cellPosition + cellOffset) * randomness -
354  localPosition;
355  float2 perpendicularToEdge = vectorToPoint - vectorToClosest;
356  if (dot(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {
357  float distanceToEdge = dot((vectorToClosest + vectorToPoint) / 2.0f,
358  normalize(perpendicularToEdge));
359  minDistance = min(minDistance, distanceToEdge);
360  }
361  }
362  }
363  *outDistance = minDistance;
364 }
365 
367  float randomness,
368  ccl_private float *outRadius)
369 {
370  float2 cellPosition = floor(coord);
371  float2 localPosition = coord - cellPosition;
372 
373  float2 closestPoint = make_float2(0.0f, 0.0f);
374  float2 closestPointOffset = make_float2(0.0f, 0.0f);
375  float minDistance = 8.0f;
376  for (int j = -1; j <= 1; j++) {
377  for (int i = -1; i <= 1; i++) {
378  float2 cellOffset = make_float2(i, j);
379  float2 pointPosition = cellOffset +
380  hash_float2_to_float2(cellPosition + cellOffset) * randomness;
381  float distanceToPoint = distance(pointPosition, localPosition);
382  if (distanceToPoint < minDistance) {
383  minDistance = distanceToPoint;
384  closestPoint = pointPosition;
385  closestPointOffset = cellOffset;
386  }
387  }
388  }
389 
390  minDistance = 8.0f;
391  float2 closestPointToClosestPoint = make_float2(0.0f, 0.0f);
392  for (int j = -1; j <= 1; j++) {
393  for (int i = -1; i <= 1; i++) {
394  if (i == 0 && j == 0) {
395  continue;
396  }
397  float2 cellOffset = make_float2(i, j) + closestPointOffset;
398  float2 pointPosition = cellOffset +
399  hash_float2_to_float2(cellPosition + cellOffset) * randomness;
400  float distanceToPoint = distance(closestPoint, pointPosition);
401  if (distanceToPoint < minDistance) {
402  minDistance = distanceToPoint;
403  closestPointToClosestPoint = pointPosition;
404  }
405  }
406  }
407  *outRadius = distance(closestPointToClosestPoint, closestPoint) / 2.0f;
408 }
409 
410 /* **** 3D Voronoi **** */
411 
413  float3 b,
415  float exponent)
416 {
417  if (metric == NODE_VORONOI_EUCLIDEAN) {
418  return distance(a, b);
419  }
420  else if (metric == NODE_VORONOI_MANHATTAN) {
421  return fabsf(a.x - b.x) + fabsf(a.y - b.y) + fabsf(a.z - b.z);
422  }
423  else if (metric == NODE_VORONOI_CHEBYCHEV) {
424  return max(fabsf(a.x - b.x), max(fabsf(a.y - b.y), fabsf(a.z - b.z)));
425  }
426  else if (metric == NODE_VORONOI_MINKOWSKI) {
427  return powf(powf(fabsf(a.x - b.x), exponent) + powf(fabsf(a.y - b.y), exponent) +
428  powf(fabsf(a.z - b.z), exponent),
429  1.0f / exponent);
430  }
431  else {
432  return 0.0f;
433  }
434 }
435 
437  float exponent,
438  float randomness,
440  ccl_private float *outDistance,
441  ccl_private float3 *outColor,
442  ccl_private float3 *outPosition)
443 {
444  float3 cellPosition = floor(coord);
445  float3 localPosition = coord - cellPosition;
446 
447  float minDistance = 8.0f;
448  float3 targetOffset = make_float3(0.0f, 0.0f, 0.0f);
449  float3 targetPosition = make_float3(0.0f, 0.0f, 0.0f);
450  for (int k = -1; k <= 1; k++) {
451  for (int j = -1; j <= 1; j++) {
452  for (int i = -1; i <= 1; i++) {
453  float3 cellOffset = make_float3(i, j, k);
454  float3 pointPosition = cellOffset +
455  hash_float3_to_float3(cellPosition + cellOffset) * randomness;
456  float distanceToPoint = voronoi_distance_3d(
457  pointPosition, localPosition, metric, exponent);
458  if (distanceToPoint < minDistance) {
459  targetOffset = cellOffset;
460  minDistance = distanceToPoint;
461  targetPosition = pointPosition;
462  }
463  }
464  }
465  }
466  *outDistance = minDistance;
467  *outColor = hash_float3_to_float3(cellPosition + targetOffset);
468  *outPosition = targetPosition + cellPosition;
469 }
470 
472  float smoothness,
473  float exponent,
474  float randomness,
476  ccl_private float *outDistance,
477  ccl_private float3 *outColor,
478  ccl_private float3 *outPosition)
479 {
480  float3 cellPosition = floor(coord);
481  float3 localPosition = coord - cellPosition;
482 
483  float smoothDistance = 8.0f;
484  float3 smoothColor = make_float3(0.0f, 0.0f, 0.0f);
485  float3 smoothPosition = make_float3(0.0f, 0.0f, 0.0f);
486  for (int k = -2; k <= 2; k++) {
487  for (int j = -2; j <= 2; j++) {
488  for (int i = -2; i <= 2; i++) {
489  float3 cellOffset = make_float3(i, j, k);
490  float3 pointPosition = cellOffset +
491  hash_float3_to_float3(cellPosition + cellOffset) * randomness;
492  float distanceToPoint = voronoi_distance_3d(
493  pointPosition, localPosition, metric, exponent);
494  float h = smoothstep(
495  0.0f, 1.0f, 0.5f + 0.5f * (smoothDistance - distanceToPoint) / smoothness);
496  float correctionFactor = smoothness * h * (1.0f - h);
497  smoothDistance = mix(smoothDistance, distanceToPoint, h) - correctionFactor;
498  correctionFactor /= 1.0f + 3.0f * smoothness;
499  float3 cellColor = hash_float3_to_float3(cellPosition + cellOffset);
500  smoothColor = mix(smoothColor, cellColor, h) - correctionFactor;
501  smoothPosition = mix(smoothPosition, pointPosition, h) - correctionFactor;
502  }
503  }
504  }
505  *outDistance = smoothDistance;
506  *outColor = smoothColor;
507  *outPosition = cellPosition + smoothPosition;
508 }
509 
511  float exponent,
512  float randomness,
514  ccl_private float *outDistance,
515  ccl_private float3 *outColor,
516  ccl_private float3 *outPosition)
517 {
518  float3 cellPosition = floor(coord);
519  float3 localPosition = coord - cellPosition;
520 
521  float distanceF1 = 8.0f;
522  float distanceF2 = 8.0f;
523  float3 offsetF1 = make_float3(0.0f, 0.0f, 0.0f);
524  float3 positionF1 = make_float3(0.0f, 0.0f, 0.0f);
525  float3 offsetF2 = make_float3(0.0f, 0.0f, 0.0f);
526  float3 positionF2 = make_float3(0.0f, 0.0f, 0.0f);
527  for (int k = -1; k <= 1; k++) {
528  for (int j = -1; j <= 1; j++) {
529  for (int i = -1; i <= 1; i++) {
530  float3 cellOffset = make_float3(i, j, k);
531  float3 pointPosition = cellOffset +
532  hash_float3_to_float3(cellPosition + cellOffset) * randomness;
533  float distanceToPoint = voronoi_distance_3d(
534  pointPosition, localPosition, metric, exponent);
535  if (distanceToPoint < distanceF1) {
536  distanceF2 = distanceF1;
537  distanceF1 = distanceToPoint;
538  offsetF2 = offsetF1;
539  offsetF1 = cellOffset;
540  positionF2 = positionF1;
541  positionF1 = pointPosition;
542  }
543  else if (distanceToPoint < distanceF2) {
544  distanceF2 = distanceToPoint;
545  offsetF2 = cellOffset;
546  positionF2 = pointPosition;
547  }
548  }
549  }
550  }
551  *outDistance = distanceF2;
552  *outColor = hash_float3_to_float3(cellPosition + offsetF2);
553  *outPosition = positionF2 + cellPosition;
554 }
555 
557  float randomness,
558  ccl_private float *outDistance)
559 {
560  float3 cellPosition = floor(coord);
561  float3 localPosition = coord - cellPosition;
562 
563  float3 vectorToClosest = make_float3(0.0f, 0.0f, 0.0f);
564  float minDistance = 8.0f;
565  for (int k = -1; k <= 1; k++) {
566  for (int j = -1; j <= 1; j++) {
567  for (int i = -1; i <= 1; i++) {
568  float3 cellOffset = make_float3(i, j, k);
569  float3 vectorToPoint = cellOffset +
570  hash_float3_to_float3(cellPosition + cellOffset) * randomness -
571  localPosition;
572  float distanceToPoint = dot(vectorToPoint, vectorToPoint);
573  if (distanceToPoint < minDistance) {
574  minDistance = distanceToPoint;
575  vectorToClosest = vectorToPoint;
576  }
577  }
578  }
579  }
580 
581  minDistance = 8.0f;
582  for (int k = -1; k <= 1; k++) {
583  for (int j = -1; j <= 1; j++) {
584  for (int i = -1; i <= 1; i++) {
585  float3 cellOffset = make_float3(i, j, k);
586  float3 vectorToPoint = cellOffset +
587  hash_float3_to_float3(cellPosition + cellOffset) * randomness -
588  localPosition;
589  float3 perpendicularToEdge = vectorToPoint - vectorToClosest;
590  if (dot(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {
591  float distanceToEdge = dot((vectorToClosest + vectorToPoint) / 2.0f,
592  normalize(perpendicularToEdge));
593  minDistance = min(minDistance, distanceToEdge);
594  }
595  }
596  }
597  }
598  *outDistance = minDistance;
599 }
600 
602  float randomness,
603  ccl_private float *outRadius)
604 {
605  float3 cellPosition = floor(coord);
606  float3 localPosition = coord - cellPosition;
607 
608  float3 closestPoint = make_float3(0.0f, 0.0f, 0.0f);
609  float3 closestPointOffset = make_float3(0.0f, 0.0f, 0.0f);
610  float minDistance = 8.0f;
611  for (int k = -1; k <= 1; k++) {
612  for (int j = -1; j <= 1; j++) {
613  for (int i = -1; i <= 1; i++) {
614  float3 cellOffset = make_float3(i, j, k);
615  float3 pointPosition = cellOffset +
616  hash_float3_to_float3(cellPosition + cellOffset) * randomness;
617  float distanceToPoint = distance(pointPosition, localPosition);
618  if (distanceToPoint < minDistance) {
619  minDistance = distanceToPoint;
620  closestPoint = pointPosition;
621  closestPointOffset = cellOffset;
622  }
623  }
624  }
625  }
626 
627  minDistance = 8.0f;
628  float3 closestPointToClosestPoint = make_float3(0.0f, 0.0f, 0.0f);
629  for (int k = -1; k <= 1; k++) {
630  for (int j = -1; j <= 1; j++) {
631  for (int i = -1; i <= 1; i++) {
632  if (i == 0 && j == 0 && k == 0) {
633  continue;
634  }
635  float3 cellOffset = make_float3(i, j, k) + closestPointOffset;
636  float3 pointPosition = cellOffset +
637  hash_float3_to_float3(cellPosition + cellOffset) * randomness;
638  float distanceToPoint = distance(closestPoint, pointPosition);
639  if (distanceToPoint < minDistance) {
640  minDistance = distanceToPoint;
641  closestPointToClosestPoint = pointPosition;
642  }
643  }
644  }
645  }
646  *outRadius = distance(closestPointToClosestPoint, closestPoint) / 2.0f;
647 }
648 
649 /* **** 4D Voronoi **** */
650 
652  float4 b,
654  float exponent)
655 {
656  if (metric == NODE_VORONOI_EUCLIDEAN) {
657  return distance(a, b);
658  }
659  else if (metric == NODE_VORONOI_MANHATTAN) {
660  return fabsf(a.x - b.x) + fabsf(a.y - b.y) + fabsf(a.z - b.z) + fabsf(a.w - b.w);
661  }
662  else if (metric == NODE_VORONOI_CHEBYCHEV) {
663  return max(fabsf(a.x - b.x), max(fabsf(a.y - b.y), max(fabsf(a.z - b.z), fabsf(a.w - b.w))));
664  }
665  else if (metric == NODE_VORONOI_MINKOWSKI) {
666  return powf(powf(fabsf(a.x - b.x), exponent) + powf(fabsf(a.y - b.y), exponent) +
667  powf(fabsf(a.z - b.z), exponent) + powf(fabsf(a.w - b.w), exponent),
668  1.0f / exponent);
669  }
670  else {
671  return 0.0f;
672  }
673 }
674 
676  float exponent,
677  float randomness,
679  ccl_private float *outDistance,
680  ccl_private float3 *outColor,
681  ccl_private float4 *outPosition)
682 {
683  float4 cellPosition = floor(coord);
684  float4 localPosition = coord - cellPosition;
685 
686  float minDistance = 8.0f;
687  float4 targetOffset = zero_float4();
688  float4 targetPosition = zero_float4();
689  for (int u = -1; u <= 1; u++) {
690  for (int k = -1; k <= 1; k++) {
691  ccl_loop_no_unroll for (int j = -1; j <= 1; j++)
692  {
693  for (int i = -1; i <= 1; i++) {
694  float4 cellOffset = make_float4(i, j, k, u);
695  float4 pointPosition = cellOffset +
696  hash_float4_to_float4(cellPosition + cellOffset) * randomness;
697  float distanceToPoint = voronoi_distance_4d(
698  pointPosition, localPosition, metric, exponent);
699  if (distanceToPoint < minDistance) {
700  targetOffset = cellOffset;
701  minDistance = distanceToPoint;
702  targetPosition = pointPosition;
703  }
704  }
705  }
706  }
707  }
708  *outDistance = minDistance;
709  *outColor = hash_float4_to_float3(cellPosition + targetOffset);
710  *outPosition = targetPosition + cellPosition;
711 }
712 
714  float smoothness,
715  float exponent,
716  float randomness,
718  ccl_private float *outDistance,
719  ccl_private float3 *outColor,
720  ccl_private float4 *outPosition)
721 {
722  float4 cellPosition = floor(coord);
723  float4 localPosition = coord - cellPosition;
724 
725  float smoothDistance = 8.0f;
726  float3 smoothColor = make_float3(0.0f, 0.0f, 0.0f);
727  float4 smoothPosition = zero_float4();
728  for (int u = -2; u <= 2; u++) {
729  for (int k = -2; k <= 2; k++) {
730  ccl_loop_no_unroll for (int j = -2; j <= 2; j++)
731  {
732  for (int i = -2; i <= 2; i++) {
733  float4 cellOffset = make_float4(i, j, k, u);
734  float4 pointPosition = cellOffset +
735  hash_float4_to_float4(cellPosition + cellOffset) * randomness;
736  float distanceToPoint = voronoi_distance_4d(
737  pointPosition, localPosition, metric, exponent);
738  float h = smoothstep(
739  0.0f, 1.0f, 0.5f + 0.5f * (smoothDistance - distanceToPoint) / smoothness);
740  float correctionFactor = smoothness * h * (1.0f - h);
741  smoothDistance = mix(smoothDistance, distanceToPoint, h) - correctionFactor;
742  correctionFactor /= 1.0f + 3.0f * smoothness;
743  float3 cellColor = hash_float4_to_float3(cellPosition + cellOffset);
744  smoothColor = mix(smoothColor, cellColor, h) - correctionFactor;
745  smoothPosition = mix(smoothPosition, pointPosition, h) - correctionFactor;
746  }
747  }
748  }
749  }
750  *outDistance = smoothDistance;
751  *outColor = smoothColor;
752  *outPosition = cellPosition + smoothPosition;
753 }
754 
756  float exponent,
757  float randomness,
759  ccl_private float *outDistance,
760  ccl_private float3 *outColor,
761  ccl_private float4 *outPosition)
762 {
763  float4 cellPosition = floor(coord);
764  float4 localPosition = coord - cellPosition;
765 
766  float distanceF1 = 8.0f;
767  float distanceF2 = 8.0f;
768  float4 offsetF1 = zero_float4();
769  float4 positionF1 = zero_float4();
770  float4 offsetF2 = zero_float4();
771  float4 positionF2 = zero_float4();
772  for (int u = -1; u <= 1; u++) {
773  for (int k = -1; k <= 1; k++) {
774  ccl_loop_no_unroll for (int j = -1; j <= 1; j++)
775  {
776  for (int i = -1; i <= 1; i++) {
777  float4 cellOffset = make_float4(i, j, k, u);
778  float4 pointPosition = cellOffset +
779  hash_float4_to_float4(cellPosition + cellOffset) * randomness;
780  float distanceToPoint = voronoi_distance_4d(
781  pointPosition, localPosition, metric, exponent);
782  if (distanceToPoint < distanceF1) {
783  distanceF2 = distanceF1;
784  distanceF1 = distanceToPoint;
785  offsetF2 = offsetF1;
786  offsetF1 = cellOffset;
787  positionF2 = positionF1;
788  positionF1 = pointPosition;
789  }
790  else if (distanceToPoint < distanceF2) {
791  distanceF2 = distanceToPoint;
792  offsetF2 = cellOffset;
793  positionF2 = pointPosition;
794  }
795  }
796  }
797  }
798  }
799  *outDistance = distanceF2;
800  *outColor = hash_float4_to_float3(cellPosition + offsetF2);
801  *outPosition = positionF2 + cellPosition;
802 }
803 
805  float randomness,
806  ccl_private float *outDistance)
807 {
808  float4 cellPosition = floor(coord);
809  float4 localPosition = coord - cellPosition;
810 
811  float4 vectorToClosest = zero_float4();
812  float minDistance = 8.0f;
813  for (int u = -1; u <= 1; u++) {
814  for (int k = -1; k <= 1; k++) {
815  ccl_loop_no_unroll for (int j = -1; j <= 1; j++)
816  {
817  for (int i = -1; i <= 1; i++) {
818  float4 cellOffset = make_float4(i, j, k, u);
819  float4 vectorToPoint = cellOffset +
820  hash_float4_to_float4(cellPosition + cellOffset) * randomness -
821  localPosition;
822  float distanceToPoint = dot(vectorToPoint, vectorToPoint);
823  if (distanceToPoint < minDistance) {
824  minDistance = distanceToPoint;
825  vectorToClosest = vectorToPoint;
826  }
827  }
828  }
829  }
830  }
831 
832  minDistance = 8.0f;
833  for (int u = -1; u <= 1; u++) {
834  for (int k = -1; k <= 1; k++) {
835  ccl_loop_no_unroll for (int j = -1; j <= 1; j++)
836  {
837  for (int i = -1; i <= 1; i++) {
838  float4 cellOffset = make_float4(i, j, k, u);
839  float4 vectorToPoint = cellOffset +
840  hash_float4_to_float4(cellPosition + cellOffset) * randomness -
841  localPosition;
842  float4 perpendicularToEdge = vectorToPoint - vectorToClosest;
843  if (dot(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {
844  float distanceToEdge = dot((vectorToClosest + vectorToPoint) / 2.0f,
845  normalize(perpendicularToEdge));
846  minDistance = min(minDistance, distanceToEdge);
847  }
848  }
849  }
850  }
851  }
852  *outDistance = minDistance;
853 }
854 
856  float randomness,
857  ccl_private float *outRadius)
858 {
859  float4 cellPosition = floor(coord);
860  float4 localPosition = coord - cellPosition;
861 
862  float4 closestPoint = zero_float4();
863  float4 closestPointOffset = zero_float4();
864  float minDistance = 8.0f;
865  for (int u = -1; u <= 1; u++) {
866  for (int k = -1; k <= 1; k++) {
867  ccl_loop_no_unroll for (int j = -1; j <= 1; j++)
868  {
869  for (int i = -1; i <= 1; i++) {
870  float4 cellOffset = make_float4(i, j, k, u);
871  float4 pointPosition = cellOffset +
872  hash_float4_to_float4(cellPosition + cellOffset) * randomness;
873  float distanceToPoint = distance(pointPosition, localPosition);
874  if (distanceToPoint < minDistance) {
875  minDistance = distanceToPoint;
876  closestPoint = pointPosition;
877  closestPointOffset = cellOffset;
878  }
879  }
880  }
881  }
882  }
883 
884  minDistance = 8.0f;
885  float4 closestPointToClosestPoint = zero_float4();
886  for (int u = -1; u <= 1; u++) {
887  for (int k = -1; k <= 1; k++) {
888  ccl_loop_no_unroll for (int j = -1; j <= 1; j++)
889  {
890  for (int i = -1; i <= 1; i++) {
891  if (i == 0 && j == 0 && k == 0 && u == 0) {
892  continue;
893  }
894  float4 cellOffset = make_float4(i, j, k, u) + closestPointOffset;
895  float4 pointPosition = cellOffset +
896  hash_float4_to_float4(cellPosition + cellOffset) * randomness;
897  float distanceToPoint = distance(closestPoint, pointPosition);
898  if (distanceToPoint < minDistance) {
899  minDistance = distanceToPoint;
900  closestPointToClosestPoint = pointPosition;
901  }
902  }
903  }
904  }
905  }
906  *outRadius = distance(closestPointToClosestPoint, closestPoint) / 2.0f;
907 }
908 
909 template<uint node_feature_mask>
912  ccl_private float *stack,
913  uint dimensions,
914  uint feature,
915  uint metric,
916  int offset)
917 {
918  uint4 stack_offsets = read_node(kg, &offset);
919  uint4 defaults = read_node(kg, &offset);
920 
921  uint coord_stack_offset, w_stack_offset, scale_stack_offset, smoothness_stack_offset;
922  uint exponent_stack_offset, randomness_stack_offset, distance_out_stack_offset,
923  color_out_stack_offset;
924  uint position_out_stack_offset, w_out_stack_offset, radius_out_stack_offset;
925 
926  svm_unpack_node_uchar4(stack_offsets.x,
927  &coord_stack_offset,
928  &w_stack_offset,
929  &scale_stack_offset,
930  &smoothness_stack_offset);
931  svm_unpack_node_uchar4(stack_offsets.y,
932  &exponent_stack_offset,
933  &randomness_stack_offset,
934  &distance_out_stack_offset,
935  &color_out_stack_offset);
937  stack_offsets.z, &position_out_stack_offset, &w_out_stack_offset, &radius_out_stack_offset);
938 
939  float3 coord = stack_load_float3(stack, coord_stack_offset);
940  float w = stack_load_float_default(stack, w_stack_offset, stack_offsets.w);
941  float scale = stack_load_float_default(stack, scale_stack_offset, defaults.x);
942  float smoothness = stack_load_float_default(stack, smoothness_stack_offset, defaults.y);
943  float exponent = stack_load_float_default(stack, exponent_stack_offset, defaults.z);
944  float randomness = stack_load_float_default(stack, randomness_stack_offset, defaults.w);
945 
946  NodeVoronoiFeature voronoi_feature = (NodeVoronoiFeature)feature;
947  NodeVoronoiDistanceMetric voronoi_metric = (NodeVoronoiDistanceMetric)metric;
948 
949  float distance_out = 0.0f, w_out = 0.0f, radius_out = 0.0f;
950  float3 color_out = make_float3(0.0f, 0.0f, 0.0f);
951  float3 position_out = make_float3(0.0f, 0.0f, 0.0f);
952 
953  randomness = clamp(randomness, 0.0f, 1.0f);
954  smoothness = clamp(smoothness / 2.0f, 0.0f, 0.5f);
955 
956  w *= scale;
957  coord *= scale;
958 
959  switch (dimensions) {
960  case 1: {
961  switch (voronoi_feature) {
962  case NODE_VORONOI_F1:
964  w, exponent, randomness, voronoi_metric, &distance_out, &color_out, &w_out);
965  break;
968  smoothness,
969  exponent,
970  randomness,
971  voronoi_metric,
972  &distance_out,
973  &color_out,
974  &w_out);
975  break;
976  case NODE_VORONOI_F2:
978  w, exponent, randomness, voronoi_metric, &distance_out, &color_out, &w_out);
979  break;
981  voronoi_distance_to_edge_1d(w, randomness, &distance_out);
982  break;
984  voronoi_n_sphere_radius_1d(w, randomness, &radius_out);
985  break;
986  default:
987  kernel_assert(0);
988  }
989  w_out = safe_divide(w_out, scale);
990  break;
991  }
992  case 2: {
993  float2 coord_2d = make_float2(coord.x, coord.y);
994  float2 position_out_2d = zero_float2();
995  switch (voronoi_feature) {
996  case NODE_VORONOI_F1:
997  voronoi_f1_2d(coord_2d,
998  exponent,
999  randomness,
1000  voronoi_metric,
1001  &distance_out,
1002  &color_out,
1003  &position_out_2d);
1004  break;
1006  IF_KERNEL_NODES_FEATURE(VORONOI_EXTRA)
1007  {
1008  voronoi_smooth_f1_2d(coord_2d,
1009  smoothness,
1010  exponent,
1011  randomness,
1012  voronoi_metric,
1013  &distance_out,
1014  &color_out,
1015  &position_out_2d);
1016  }
1017  break;
1018  case NODE_VORONOI_F2:
1019  voronoi_f2_2d(coord_2d,
1020  exponent,
1021  randomness,
1022  voronoi_metric,
1023  &distance_out,
1024  &color_out,
1025  &position_out_2d);
1026  break;
1028  voronoi_distance_to_edge_2d(coord_2d, randomness, &distance_out);
1029  break;
1031  voronoi_n_sphere_radius_2d(coord_2d, randomness, &radius_out);
1032  break;
1033  default:
1034  kernel_assert(0);
1035  }
1036  position_out_2d = safe_divide_float2_float(position_out_2d, scale);
1037  position_out = make_float3(position_out_2d.x, position_out_2d.y, 0.0f);
1038  break;
1039  }
1040  case 3: {
1041  switch (voronoi_feature) {
1042  case NODE_VORONOI_F1:
1043  voronoi_f1_3d(coord,
1044  exponent,
1045  randomness,
1046  voronoi_metric,
1047  &distance_out,
1048  &color_out,
1049  &position_out);
1050  break;
1052  IF_KERNEL_NODES_FEATURE(VORONOI_EXTRA)
1053  {
1054  voronoi_smooth_f1_3d(coord,
1055  smoothness,
1056  exponent,
1057  randomness,
1058  voronoi_metric,
1059  &distance_out,
1060  &color_out,
1061  &position_out);
1062  }
1063  break;
1064  case NODE_VORONOI_F2:
1065  voronoi_f2_3d(coord,
1066  exponent,
1067  randomness,
1068  voronoi_metric,
1069  &distance_out,
1070  &color_out,
1071  &position_out);
1072  break;
1074  voronoi_distance_to_edge_3d(coord, randomness, &distance_out);
1075  break;
1077  voronoi_n_sphere_radius_3d(coord, randomness, &radius_out);
1078  break;
1079  default:
1080  kernel_assert(0);
1081  }
1082  position_out = safe_divide(position_out, scale);
1083  break;
1084  }
1085 
1086  case 4: {
1087  IF_KERNEL_NODES_FEATURE(VORONOI_EXTRA)
1088  {
1089  float4 coord_4d = make_float4(coord.x, coord.y, coord.z, w);
1090  float4 position_out_4d;
1091  switch (voronoi_feature) {
1092  case NODE_VORONOI_F1:
1093  voronoi_f1_4d(coord_4d,
1094  exponent,
1095  randomness,
1096  voronoi_metric,
1097  &distance_out,
1098  &color_out,
1099  &position_out_4d);
1100  break;
1102  voronoi_smooth_f1_4d(coord_4d,
1103  smoothness,
1104  exponent,
1105  randomness,
1106  voronoi_metric,
1107  &distance_out,
1108  &color_out,
1109  &position_out_4d);
1110  break;
1111  case NODE_VORONOI_F2:
1112  voronoi_f2_4d(coord_4d,
1113  exponent,
1114  randomness,
1115  voronoi_metric,
1116  &distance_out,
1117  &color_out,
1118  &position_out_4d);
1119  break;
1121  voronoi_distance_to_edge_4d(coord_4d, randomness, &distance_out);
1122  break;
1124  voronoi_n_sphere_radius_4d(coord_4d, randomness, &radius_out);
1125  break;
1126  default:
1127  kernel_assert(0);
1128  }
1129  position_out_4d = safe_divide(position_out_4d, scale);
1130  position_out = make_float3(position_out_4d.x, position_out_4d.y, position_out_4d.z);
1131  w_out = position_out_4d.w;
1132  }
1133  break;
1134  }
1135  default:
1136  kernel_assert(0);
1137  }
1138 
1139  if (stack_valid(distance_out_stack_offset))
1140  stack_store_float(stack, distance_out_stack_offset, distance_out);
1141  if (stack_valid(color_out_stack_offset))
1142  stack_store_float3(stack, color_out_stack_offset, color_out);
1143  if (stack_valid(position_out_stack_offset))
1144  stack_store_float3(stack, position_out_stack_offset, position_out);
1145  if (stack_valid(w_out_stack_offset))
1146  stack_store_float(stack, w_out_stack_offset, w_out);
1147  if (stack_valid(radius_out_stack_offset))
1148  stack_store_float(stack, radius_out_stack_offset, radius_out);
1149  return offset;
1150 }
1151 
unsigned int uint
Definition: BLI_sys_types.h:67
float float4[4]
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
#define kernel_assert(cond)
Definition: cpu/compat.h:34
#define ccl_loop_no_unroll
Definition: cuda/compat.h:51
#define ccl_device
Definition: cuda/compat.h:32
#define ccl_private
Definition: cuda/compat.h:48
#define powf(x, y)
Definition: cuda/compat.h:103
#define ccl_device_noinline
Definition: cuda/compat.h:40
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
const KernelGlobalsCPU *ccl_restrict KernelGlobals
ccl_device_inline float3 hash_float_to_float3(float k)
Definition: hash.h:184
ccl_device_inline float3 hash_float4_to_float3(float4 k)
Definition: hash.h:198
ccl_device_inline float3 hash_float2_to_float3(float2 k)
Definition: hash.h:191
ccl_device_inline float2 hash_float2_to_float2(float2 k)
Definition: hash.h:162
ccl_device_inline float4 hash_float4_to_float4(float4 k)
Definition: hash.h:174
ccl_device_inline float3 hash_float3_to_float3(float3 k)
Definition: hash.h:167
#define mix(a, b, c)
Definition: hash.h:17
ccl_global float * color_out
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
ccl_device_inline void stack_store_float3(ccl_private float *stack, uint a, float3 f)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 stack_load_float3(ccl_private float *stack, uint a)
ccl_device_inline uint4 read_node(KernelGlobals kg, ccl_private int *offset)
ccl_device_forceinline void svm_unpack_node_uchar3(uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z)
ccl_device_inline float stack_load_float_default(ccl_private float *stack, uint a, uint value)
ccl_device_inline void stack_store_float(ccl_private float *stack, uint a, float f)
ccl_device_forceinline void svm_unpack_node_uchar4(uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z, ccl_private uint *w)
ccl_device_inline bool stack_valid(uint a)
NodeVoronoiFeature
@ NODE_VORONOI_SMOOTH_F1
@ NODE_VORONOI_N_SPHERE_RADIUS
@ NODE_VORONOI_F1
@ NODE_VORONOI_F2
@ NODE_VORONOI_DISTANCE_TO_EDGE
NodeVoronoiDistanceMetric
@ NODE_VORONOI_EUCLIDEAN
@ NODE_VORONOI_MANHATTAN
@ NODE_VORONOI_CHEBYCHEV
@ NODE_VORONOI_MINKOWSKI
#define IF_KERNEL_NODES_FEATURE(feature)
ShaderData
Definition: kernel/types.h:925
MINLINE float smoothstep(float edge0, float edge1, float x)
ccl_device_inline float2 zero_float2()
Definition: math_float2.h:62
ccl_device_inline float2 safe_divide_float2_float(const float2 a, const float b)
Definition: math_float2.h:254
ccl_device_inline float4 zero_float4()
Definition: math_float4.h:92
#define make_float2(x, y)
Definition: metal/compat.h:203
#define floorf(x)
Definition: metal/compat.h:224
#define make_float4(x, y, z, w)
Definition: metal/compat.h:205
#define fabsf(x)
Definition: metal/compat.h:219
#define make_float3(x, y, z)
Definition: metal/compat.h:204
static unsigned a[3]
Definition: RandGen.cpp:78
T dot(const vec_base< T, Size > &a, const vec_base< T, Size > &b)
T clamp(const T &a, const T &min, const T &max)
T distance(const T &a, const T &b)
vec_base< T, Size > normalize(const vec_base< T, Size > &v)
T floor(const T &a)
T safe_divide(const T &a, const T &b)
float hash_float_to_float(float k)
Definition: noise.cc:178
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
#define min(a, b)
Definition: sort.c:35
float x
Definition: types_float2.h:15
float y
Definition: types_float2.h:15
float z
float y
float x
uint x
Definition: types_uint4.h:15
uint y
Definition: types_uint4.h:15
uint z
Definition: types_uint4.h:15
uint w
Definition: types_uint4.h:15
float max
ccl_device float voronoi_distance_4d(float4 a, float4 b, NodeVoronoiDistanceMetric metric, float exponent)
Definition: voronoi.h:651
ccl_device void voronoi_f2_4d(float4 coord, float exponent, float randomness, NodeVoronoiDistanceMetric metric, ccl_private float *outDistance, ccl_private float3 *outColor, ccl_private float4 *outPosition)
Definition: voronoi.h:755
ccl_device void voronoi_smooth_f1_2d(float2 coord, float smoothness, float exponent, float randomness, NodeVoronoiDistanceMetric metric, ccl_private float *outDistance, ccl_private float3 *outColor, ccl_private float2 *outPosition)
Definition: voronoi.h:246
ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint dimensions, uint feature, uint metric, int offset)
Definition: voronoi.h:910
ccl_device void voronoi_n_sphere_radius_2d(float2 coord, float randomness, ccl_private float *outRadius)
Definition: voronoi.h:366
ccl_device void voronoi_smooth_f1_4d(float4 coord, float smoothness, float exponent, float randomness, NodeVoronoiDistanceMetric metric, ccl_private float *outDistance, ccl_private float3 *outColor, ccl_private float4 *outPosition)
Definition: voronoi.h:713
ccl_device void voronoi_n_sphere_radius_4d(float4 coord, float randomness, ccl_private float *outRadius)
Definition: voronoi.h:855
ccl_device float voronoi_distance_2d(float2 a, float2 b, NodeVoronoiDistanceMetric metric, float exponent)
Definition: voronoi.h:191
ccl_device void voronoi_f1_2d(float2 coord, float exponent, float randomness, NodeVoronoiDistanceMetric metric, ccl_private float *outDistance, ccl_private float3 *outColor, ccl_private float2 *outPosition)
Definition: voronoi.h:214
ccl_device void voronoi_f2_2d(float2 coord, float exponent, float randomness, NodeVoronoiDistanceMetric metric, ccl_private float *outDistance, ccl_private float3 *outColor, ccl_private float2 *outPosition)
Definition: voronoi.h:282
ccl_device void voronoi_distance_to_edge_4d(float4 coord, float randomness, ccl_private float *outDistance)
Definition: voronoi.h:804
ccl_device void voronoi_f2_1d(float w, float exponent, float randomness, NodeVoronoiDistanceMetric metric, ccl_private float *outDistance, ccl_private float3 *outColor, ccl_private float *outW)
Definition: voronoi.h:97
ccl_device void voronoi_distance_to_edge_3d(float3 coord, float randomness, ccl_private float *outDistance)
Definition: voronoi.h:556
ccl_device void voronoi_f1_1d(float w, float exponent, float randomness, NodeVoronoiDistanceMetric metric, ccl_private float *outDistance, ccl_private float3 *outColor, ccl_private float *outW)
Definition: voronoi.h:35
ccl_device void voronoi_f2_3d(float3 coord, float exponent, float randomness, NodeVoronoiDistanceMetric metric, ccl_private float *outDistance, ccl_private float3 *outColor, ccl_private float3 *outPosition)
Definition: voronoi.h:510
ccl_device void voronoi_f1_4d(float4 coord, float exponent, float randomness, NodeVoronoiDistanceMetric metric, ccl_private float *outDistance, ccl_private float3 *outColor, ccl_private float4 *outPosition)
Definition: voronoi.h:675
ccl_device float voronoi_distance_3d(float3 a, float3 b, NodeVoronoiDistanceMetric metric, float exponent)
Definition: voronoi.h:412
CCL_NAMESPACE_BEGIN ccl_device float voronoi_distance_1d(float a, float b, NodeVoronoiDistanceMetric metric, float exponent)
Definition: voronoi.h:27
ccl_device void voronoi_n_sphere_radius_1d(float w, float randomness, ccl_private float *outRadius)
Definition: voronoi.h:153
ccl_device void voronoi_distance_to_edge_1d(float w, float randomness, ccl_private float *outDistance)
Definition: voronoi.h:137
ccl_device void voronoi_smooth_f1_3d(float3 coord, float smoothness, float exponent, float randomness, NodeVoronoiDistanceMetric metric, ccl_private float *outDistance, ccl_private float3 *outColor, ccl_private float3 *outPosition)
Definition: voronoi.h:471
ccl_device void voronoi_distance_to_edge_2d(float2 coord, float randomness, ccl_private float *outDistance)
Definition: voronoi.h:325
ccl_device void voronoi_smooth_f1_1d(float w, float smoothness, float exponent, float randomness, NodeVoronoiDistanceMetric metric, ccl_private float *outDistance, ccl_private float3 *outColor, ccl_private float *outW)
Definition: voronoi.h:64
ccl_device void voronoi_f1_3d(float3 coord, float exponent, float randomness, NodeVoronoiDistanceMetric metric, ccl_private float *outDistance, ccl_private float3 *outColor, ccl_private float3 *outPosition)
Definition: voronoi.h:436
ccl_device void voronoi_n_sphere_radius_3d(float3 coord, float randomness, ccl_private float *outRadius)
Definition: voronoi.h:601