105 const float cellPosition =
floorf(coord);
106 const float localPosition = coord - cellPosition;
109 float targetOffset = 0.0f;
110 float targetPosition = 0.0f;
111 for (
int i = -1;
i <= 1;
i++) {
112 const float cellOffset =
i;
113 const float pointPosition = cellOffset +
115 const float distanceToPoint =
voronoi_distance(pointPosition, localPosition);
116 if (distanceToPoint < minDistance) {
117 targetOffset = cellOffset;
118 minDistance = distanceToPoint;
119 targetPosition = pointPosition;
133 const float cellPosition =
floorf(coord);
134 const float localPosition = coord - cellPosition;
136 float smoothDistance = 0.0f;
137 float smoothPosition = 0.0f;
140 for (
int i = -2;
i <= 2;
i++) {
141 const float cellOffset =
i;
142 const float pointPosition = cellOffset +
144 const float distanceToPoint =
voronoi_distance(pointPosition, localPosition);
148 0.0f, 1.0f, 0.5f + 0.5f * (smoothDistance - distanceToPoint) /
params.smoothness);
149 float correctionFactor =
params.smoothness * h * (1.0f - h);
150 smoothDistance =
mix(smoothDistance, distanceToPoint, h) - correctionFactor;
151 correctionFactor /= 1.0f + 3.0f *
params.smoothness;
153 smoothColor =
mix(smoothColor, cellColor, h) - correctionFactor;
154 smoothPosition =
mix(smoothPosition, pointPosition, h) - correctionFactor;
159 octave.
color = smoothColor;
166 const float cellPosition =
floorf(coord);
167 const float localPosition = coord - cellPosition;
171 float offsetF1 = 0.0f;
172 float positionF1 = 0.0f;
173 float offsetF2 = 0.0f;
174 float positionF2 = 0.0f;
175 for (
int i = -1;
i <= 1;
i++) {
176 const float cellOffset =
i;
177 const float pointPosition = cellOffset +
179 const float distanceToPoint =
voronoi_distance(pointPosition, localPosition);
180 if (distanceToPoint < distanceF1) {
181 distanceF2 = distanceF1;
182 distanceF1 = distanceToPoint;
184 offsetF1 = cellOffset;
185 positionF2 = positionF1;
186 positionF1 = pointPosition;
188 else if (distanceToPoint < distanceF2) {
189 distanceF2 = distanceToPoint;
190 offsetF2 = cellOffset;
191 positionF2 = pointPosition;
205 const float cellPosition =
floorf(coord);
206 const float localPosition = coord - cellPosition;
209 const float leftPointPosition = -1.0f +
211 const float rightPointPosition = 1.0f +
213 const float distanceToMidLeft =
fabsf((midPointPosition + leftPointPosition) / 2.0f -
215 const float distanceToMidRight =
fabsf((midPointPosition + rightPointPosition) / 2.0f -
218 return min(distanceToMidLeft, distanceToMidRight);
224 const float cellPosition =
floorf(coord);
225 const float localPosition = coord - cellPosition;
227 float closestPoint = 0.0f;
228 float closestPointOffset = 0.0f;
230 for (
int i = -1;
i <= 1;
i++) {
231 const float cellOffset =
i;
232 const float pointPosition = cellOffset +
234 const float distanceToPoint =
fabsf(pointPosition - localPosition);
235 if (distanceToPoint < minDistance) {
236 minDistance = distanceToPoint;
237 closestPoint = pointPosition;
238 closestPointOffset = cellOffset;
243 float closestPointToClosestPoint = 0.0f;
244 for (
int i = -1;
i <= 1;
i++) {
248 const float cellOffset =
i + closestPointOffset;
249 const float pointPosition = cellOffset +
251 const float distanceToPoint =
fabsf(closestPoint - pointPosition);
252 if (distanceToPoint < minDistance) {
253 minDistance = distanceToPoint;
254 closestPointToClosestPoint = pointPosition;
258 return fabsf(closestPointToClosestPoint - closestPoint) / 2.0f;
271 const float2 localPosition = coord - cellPosition;
276 for (
int j = -1; j <= 1; j++) {
277 for (
int i = -1;
i <= 1;
i++) {
282 if (distanceToPoint < minDistance) {
283 targetOffset = cellOffset;
284 minDistance = distanceToPoint;
285 targetPosition = pointPosition;
301 const float2 localPosition = coord - cellPosition;
303 float smoothDistance = 0.0f;
307 for (
int j = -2; j <= 2; j++) {
308 for (
int i = -2;
i <= 2;
i++) {
317 0.5f + 0.5f * (smoothDistance - distanceToPoint) /
params.smoothness);
318 float correctionFactor =
params.smoothness * h * (1.0f - h);
319 smoothDistance =
mix(smoothDistance, distanceToPoint, h) - correctionFactor;
320 correctionFactor /= 1.0f + 3.0f *
params.smoothness;
322 smoothColor =
mix(smoothColor, cellColor, h) - correctionFactor;
323 smoothPosition =
mix(smoothPosition, pointPosition, h) - correctionFactor;
329 octave.
color = smoothColor;
337 const float2 localPosition = coord - cellPosition;
345 for (
int j = -1; j <= 1; j++) {
346 for (
int i = -1;
i <= 1;
i++) {
351 if (distanceToPoint < distanceF1) {
352 distanceF2 = distanceF1;
353 distanceF1 = distanceToPoint;
355 offsetF1 = cellOffset;
356 positionF2 = positionF1;
357 positionF1 = pointPosition;
359 else if (distanceToPoint < distanceF2) {
360 distanceF2 = distanceToPoint;
361 offsetF2 = cellOffset;
362 positionF2 = pointPosition;
378 const float2 localPosition = coord - cellPosition;
382 for (
int j = -1; j <= 1; j++) {
383 for (
int i = -1;
i <= 1;
i++) {
385 const float2 vectorToPoint = cellOffset +
389 const float distanceToPoint =
dot(vectorToPoint, vectorToPoint);
390 if (distanceToPoint < minDistance) {
391 minDistance = distanceToPoint;
392 vectorToClosest = vectorToPoint;
398 for (
int j = -1; j <= 1; j++) {
399 for (
int i = -1;
i <= 1;
i++) {
401 const float2 vectorToPoint = cellOffset +
405 const float2 perpendicularToEdge = vectorToPoint - vectorToClosest;
406 if (
dot(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {
407 const float distanceToEdge =
dot((vectorToClosest + vectorToPoint) / 2.0f,
409 minDistance =
min(minDistance, distanceToEdge);
421 const float2 localPosition = coord - cellPosition;
426 for (
int j = -1; j <= 1; j++) {
427 for (
int i = -1;
i <= 1;
i++) {
431 const float distanceToPointSq =
len_squared(pointPosition - localPosition);
432 if (distanceToPointSq < minDistanceSq) {
433 minDistanceSq = distanceToPointSq;
434 closestPoint = pointPosition;
435 closestPointOffset = cellOffset;
442 for (
int j = -1; j <= 1; j++) {
443 for (
int i = -1;
i <= 1;
i++) {
444 if (
i == 0 && j == 0) {
450 const float distanceToPointSq =
len_squared(closestPoint - pointPosition);
451 if (distanceToPointSq < minDistanceSq) {
452 minDistanceSq = distanceToPointSq;
453 closestPointToClosestPoint = pointPosition;
458 return distance(closestPointToClosestPoint, closestPoint) / 2.0f;
471 const float3 localPosition = coord - cellPosition;
476 for (
int k = -1; k <= 1; k++) {
477 for (
int j = -1; j <= 1; j++) {
478 for (
int i = -1;
i <= 1;
i++) {
480 const float3 pointPosition = cellOffset +
484 if (distanceToPoint < minDistance) {
485 targetOffset = cellOffset;
486 minDistance = distanceToPoint;
487 targetPosition = pointPosition;
504 const float3 localPosition = coord - cellPosition;
506 float smoothDistance = 0.0f;
510 for (
int k = -2; k <= 2; k++) {
511 for (
int j = -2; j <= 2; j++) {
512 for (
int i = -2;
i <= 2;
i++) {
514 const float3 pointPosition = cellOffset +
522 0.5f + 0.5f * (smoothDistance - distanceToPoint) /
params.smoothness);
523 float correctionFactor =
params.smoothness * h * (1.0f - h);
524 smoothDistance =
mix(smoothDistance, distanceToPoint, h) - correctionFactor;
525 correctionFactor /= 1.0f + 3.0f *
params.smoothness;
527 smoothColor =
mix(smoothColor, cellColor, h) - correctionFactor;
528 smoothPosition =
mix(smoothPosition, pointPosition, h) - correctionFactor;
535 octave.
color = smoothColor;
543 const float3 localPosition = coord - cellPosition;
551 for (
int k = -1; k <= 1; k++) {
552 for (
int j = -1; j <= 1; j++) {
553 for (
int i = -1;
i <= 1;
i++) {
555 const float3 pointPosition = cellOffset +
559 if (distanceToPoint < distanceF1) {
560 distanceF2 = distanceF1;
561 distanceF1 = distanceToPoint;
563 offsetF1 = cellOffset;
564 positionF2 = positionF1;
565 positionF1 = pointPosition;
567 else if (distanceToPoint < distanceF2) {
568 distanceF2 = distanceToPoint;
569 offsetF2 = cellOffset;
570 positionF2 = pointPosition;
587 const float3 localPosition = coord - cellPosition;
591 for (
int k = -1; k <= 1; k++) {
592 for (
int j = -1; j <= 1; j++) {
593 for (
int i = -1;
i <= 1;
i++) {
595 const float3 vectorToPoint = cellOffset +
599 const float distanceToPoint =
dot(vectorToPoint, vectorToPoint);
600 if (distanceToPoint < minDistance) {
601 minDistance = distanceToPoint;
602 vectorToClosest = vectorToPoint;
609 for (
int k = -1; k <= 1; k++) {
610 for (
int j = -1; j <= 1; j++) {
611 for (
int i = -1;
i <= 1;
i++) {
613 const float3 vectorToPoint = cellOffset +
617 const float3 perpendicularToEdge = vectorToPoint - vectorToClosest;
618 if (
dot(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {
619 const float distanceToEdge =
dot((vectorToClosest + vectorToPoint) / 2.0f,
621 minDistance =
min(minDistance, distanceToEdge);
634 const float3 localPosition = coord - cellPosition;
639 for (
int k = -1; k <= 1; k++) {
640 for (
int j = -1; j <= 1; j++) {
641 for (
int i = -1;
i <= 1;
i++) {
643 const float3 pointPosition = cellOffset +
646 const float distanceToPointSq =
len_squared(pointPosition - localPosition);
647 if (distanceToPointSq < minDistanceSq) {
648 minDistanceSq = distanceToPointSq;
649 closestPoint = pointPosition;
650 closestPointOffset = cellOffset;
658 for (
int k = -1; k <= 1; k++) {
659 for (
int j = -1; j <= 1; j++) {
660 for (
int i = -1;
i <= 1;
i++) {
661 if (
i == 0 && j == 0 && k == 0) {
665 const float3 pointPosition = cellOffset +
668 const float distanceToPointSq =
len_squared(closestPoint - pointPosition);
669 if (distanceToPointSq < minDistanceSq) {
670 minDistanceSq = distanceToPointSq;
671 closestPointToClosestPoint = pointPosition;
677 return distance(closestPointToClosestPoint, closestPoint) / 2.0f;
690 const float4 localPosition = coord - cellPosition;
695 for (
int u = -1; u <= 1; u++) {
696 for (
int k = -1; k <= 1; k++) {
697 for (
int j = -1; j <= 1; j++) {
698 for (
int i = -1;
i <= 1;
i++) {
700 const float4 pointPosition = cellOffset +
704 pointPosition, localPosition,
params);
705 if (distanceToPoint < minDistance) {
706 targetOffset = cellOffset;
707 minDistance = distanceToPoint;
708 targetPosition = pointPosition;
726 const float4 localPosition = coord - cellPosition;
728 float smoothDistance = 0.0f;
732 for (
int u = -2; u <= 2; u++) {
733 for (
int k = -2; k <= 2; k++) {
734 for (
int j = -2; j <= 2; j++) {
735 for (
int i = -2;
i <= 2;
i++) {
737 const float4 pointPosition = cellOffset +
745 0.5f + 0.5f * (smoothDistance - distanceToPoint) /
params.smoothness);
746 float correctionFactor =
params.smoothness * h * (1.0f - h);
747 smoothDistance =
mix(smoothDistance, distanceToPoint, h) - correctionFactor;
748 correctionFactor /= 1.0f + 3.0f *
params.smoothness;
750 smoothColor =
mix(smoothColor, cellColor, h) - correctionFactor;
751 smoothPosition =
mix(smoothPosition, pointPosition, h) - correctionFactor;
759 octave.
color = smoothColor;
767 const float4 localPosition = coord - cellPosition;
775 for (
int u = -1; u <= 1; u++) {
776 for (
int k = -1; k <= 1; k++) {
777 for (
int j = -1; j <= 1; j++) {
778 for (
int i = -1;
i <= 1;
i++) {
780 const float4 pointPosition = cellOffset +
784 if (distanceToPoint < distanceF1) {
785 distanceF2 = distanceF1;
786 distanceF1 = distanceToPoint;
788 offsetF1 = cellOffset;
789 positionF2 = positionF1;
790 positionF1 = pointPosition;
792 else if (distanceToPoint < distanceF2) {
793 distanceF2 = distanceToPoint;
794 offsetF2 = cellOffset;
795 positionF2 = pointPosition;
813 const float4 localPosition = coord - cellPosition;
817 for (
int u = -1; u <= 1; u++) {
818 for (
int k = -1; k <= 1; k++) {
819 for (
int j = -1; j <= 1; j++) {
820 for (
int i = -1;
i <= 1;
i++) {
822 const float4 vectorToPoint = cellOffset +
826 const float distanceToPoint =
dot(vectorToPoint, vectorToPoint);
827 if (distanceToPoint < minDistance) {
828 minDistance = distanceToPoint;
829 vectorToClosest = vectorToPoint;
837 for (
int u = -1; u <= 1; u++) {
838 for (
int k = -1; k <= 1; k++) {
839 for (
int j = -1; j <= 1; j++) {
840 for (
int i = -1;
i <= 1;
i++) {
842 const float4 vectorToPoint = cellOffset +
846 const float4 perpendicularToEdge = vectorToPoint - vectorToClosest;
847 if (
dot(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {
848 const float distanceToEdge =
dot((vectorToClosest + vectorToPoint) / 2.0f,
850 minDistance =
min(minDistance, distanceToEdge);
864 const float4 localPosition = coord - cellPosition;
869 for (
int u = -1; u <= 1; u++) {
870 for (
int k = -1; k <= 1; k++) {
871 for (
int j = -1; j <= 1; j++) {
872 for (
int i = -1;
i <= 1;
i++) {
874 const float4 pointPosition = cellOffset +
877 const float distanceToPointSq =
len_squared(pointPosition - localPosition);
878 if (distanceToPointSq < minDistanceSq) {
879 minDistanceSq = distanceToPointSq;
880 closestPoint = pointPosition;
881 closestPointOffset = cellOffset;
890 for (
int u = -1; u <= 1; u++) {
891 for (
int k = -1; k <= 1; k++) {
892 for (
int j = -1; j <= 1; j++) {
893 for (
int i = -1;
i <= 1;
i++) {
894 if (
i == 0 && j == 0 && k == 0 && u == 0) {
898 const float4 pointPosition = cellOffset +
901 const float distanceToPointSq =
len_squared(closestPoint - pointPosition);
902 if (distanceToPointSq < minDistanceSq) {
903 minDistanceSq = distanceToPointSq;
904 closestPointToClosestPoint = pointPosition;
911 return distance(closestPointToClosestPoint, closestPoint) / 2.0f;
922 float amplitude = 1.0f;
923 float max_amplitude = 0.0f;
927 const bool zero_input =
params.detail == 0.0f ||
params.roughness == 0.0f;
933 params.smoothness != 0.0f) ?
938 max_amplitude = 1.0f;
943 max_amplitude += amplitude;
947 scale *=
params.lacunarity;
948 amplitude *=
params.roughness;
952 if (remainder != 0.0f) {
953 max_amplitude =
mix(max_amplitude, max_amplitude + amplitude, remainder);
965 output.color /= max_amplitude;
979 float amplitude = 1.0f;
980 float max_amplitude =
params.max_distance;
984 const bool zero_input =
params.detail == 0.0f ||
params.roughness == 0.0f;
994 max_amplitude =
mix(max_amplitude,
params.max_distance / scale, amplitude);
996 scale *=
params.lacunarity;
997 amplitude *=
params.roughness;
1001 if (remainder != 0.0f) {
1002 const float lerp_amplitude =
mix(max_amplitude,
params.max_distance / scale, amplitude);
1003 max_amplitude =
mix(max_amplitude, lerp_amplitude, remainder);
1004 const float lerp_distance =
mix(
1026 uint distance_stack_offset;
1027 uint color_stack_offset;
1028 uint position_stack_offset;
1029 uint w_out_stack_offset;
1030 uint radius_stack_offset;
1034 stack_offsets.
z, &unused, &unused, &distance_stack_offset, &color_stack_offset);
1036 stack_offsets.
w, &position_stack_offset, &w_out_stack_offset, &radius_stack_offset);
1055template<u
int node_feature_mask>
1059 const uint dimensions,
1069 uint coord_stack_offset;
1070 uint w_stack_offset;
1071 uint scale_stack_offset;
1072 uint detail_stack_offset;
1073 uint roughness_stack_offset;
1074 uint lacunarity_stack_offset;
1075 uint smoothness_stack_offset;
1076 uint exponent_stack_offset;
1077 uint randomness_stack_offset;
1081 &coord_stack_offset,
1083 &scale_stack_offset,
1084 &detail_stack_offset);
1086 &roughness_stack_offset,
1087 &lacunarity_stack_offset,
1088 &smoothness_stack_offset,
1089 &exponent_stack_offset);
1106 params.max_distance = 0.0f;
1118 switch (
params.feature) {
1122 switch (dimensions) {
1144 float radius = 0.0f;
1145 switch (dimensions) {
1168 switch (dimensions) {
1170 params.max_distance = (0.5f + 0.5f *
params.randomness) *
1179 0.5f + 0.5f *
params.randomness),
1190 0.5f + 0.5f *
params.randomness,
1191 0.5f + 0.5f *
params.randomness),
1202 0.5f + 0.5f *
params.randomness,
1203 0.5f + 0.5f *
params.randomness,
1204 0.5f + 0.5f *
params.randomness),
MINLINE float safe_divide(float a, float b)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
reduce_max(value.rgb)") DEFINE_VALUE("REDUCE(lhs
dot(value.rgb, luminance_coefficients)") DEFINE_VALUE("REDUCE(lhs
ccl_device_inline void stack_store_float(ccl_private float *stack, const uint a, const float f)
ccl_device_inline uint4 read_node(KernelGlobals kg, ccl_private int *const offset)
ccl_device_inline void stack_store_float3(ccl_private float *stack, const uint a, const float3 f)
ccl_device_inline float stack_load_float_default(const ccl_private float *stack, const uint a, const uint value)
ccl_device_forceinline void svm_unpack_node_uchar2(const uint i, ccl_private uint *x, ccl_private uint *y)
ccl_device_forceinline void svm_unpack_node_uchar3(const uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z)
ccl_device_forceinline void svm_unpack_node_uchar4(const uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z, ccl_private uint *w)
ccl_device_inline bool stack_valid(const uint a)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 stack_load_float3(const ccl_private float *stack, const uint a)
#define kernel_assert(cond)
#define IF_KERNEL_NODES_FEATURE(feature)
const ThreadKernelGlobalsCPU * KernelGlobals
#define ccl_device_noinline
#define CCL_NAMESPACE_END
VecBase< float, 4 > float4
VecBase< float, D > normalize(VecOp< float, D >) RET
constexpr T clamp(T, U, U) RET
float distance(VecOp< float, D >, VecOp< float, D >) RET
ccl_device_inline float3 hash_float_to_float3(const float k)
ccl_device_inline float2 hash_float2_to_float2(const float2 k)
ccl_device_inline float3 hash_float2_to_float3(const float2 k)
ccl_device_inline float4 hash_float4_to_float4(const float4 k)
ccl_device_inline float3 hash_float4_to_float3(const float4 k)
ccl_device_inline float3 hash_float3_to_float3(const float3 k)
@ NODE_VORONOI_N_SPHERE_RADIUS
@ NODE_VORONOI_DISTANCE_TO_EDGE
NodeVoronoiDistanceMetric
MINLINE float smoothstep(float edge0, float edge1, float x)
ccl_device_inline float2 power(const float2 v, const float e)
CCL_NAMESPACE_BEGIN ccl_device_inline float2 zero_float2()
ccl_device_inline float len_squared(const float2 a)
ccl_device_inline float reduce_add(const float2 a)
ccl_device_inline float2 fabs(const float2 a)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
CCL_NAMESPACE_BEGIN ccl_device_inline float4 zero_float4()
float hash_float_to_float(float k)
ccl_device VoronoiOutput voronoi_f1(const ccl_private VoronoiParams ¶ms, const float coord)
ccl_device float voronoi_distance_bound(const T a, const T b, const ccl_private VoronoiParams ¶ms)
ccl_device float voronoi_distance(const float a, const float b)
ccl_device VoronoiOutput voronoi_smooth_f1(const ccl_private VoronoiParams ¶ms, const float coord)
ccl_device float voronoi_n_sphere_radius(const ccl_private VoronoiParams ¶ms, const float coord)
ccl_device VoronoiOutput fractal_voronoi_x_fx(const ccl_private VoronoiParams ¶ms, const T coord)
ccl_device float4 voronoi_position(const float coord)
ccl_device void svm_voronoi_output(const uint4 stack_offsets, ccl_private float *stack, const float distance, const float3 color, const float3 position, const float w, const float radius)
ccl_device float fractal_voronoi_distance_to_edge(const ccl_private VoronoiParams ¶ms, const T coord)
ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, const uint dimensions, const uint feature, const uint metric, int offset)
ccl_device float voronoi_distance_to_edge(const ccl_private VoronoiParams ¶ms, const float coord)
ccl_device VoronoiOutput voronoi_f2(const ccl_private VoronoiParams ¶ms, const float coord)