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_f;
277 for (
int j = -1; j <= 1; j++) {
278 for (
int i = -1;
i <= 1;
i++) {
284 if (distanceToPoint < minDistance) {
285 targetOffset = cellOffset;
286 minDistance = distanceToPoint;
287 targetPosition = pointPosition;
303 const float2 localPosition = coord - cellPosition_f;
306 float smoothDistance = 0.0f;
310 for (
int j = -2; j <= 2; j++) {
311 for (
int i = -2;
i <= 2;
i++) {
321 0.5f + 0.5f * (smoothDistance - distanceToPoint) /
params.smoothness);
322 float correctionFactor =
params.smoothness * h * (1.0f - h);
323 smoothDistance =
mix(smoothDistance, distanceToPoint, h) - correctionFactor;
324 correctionFactor /= 1.0f + 3.0f *
params.smoothness;
326 smoothColor =
mix(smoothColor, cellColor, h) - correctionFactor;
327 smoothPosition =
mix(smoothPosition, pointPosition, h) - correctionFactor;
333 octave.
color = smoothColor;
341 const float2 localPosition = coord - cellPosition_f;
350 for (
int j = -1; j <= 1; j++) {
351 for (
int i = -1;
i <= 1;
i++) {
357 if (distanceToPoint < distanceF1) {
358 distanceF2 = distanceF1;
359 distanceF1 = distanceToPoint;
361 offsetF1 = cellOffset;
362 positionF2 = positionF1;
363 positionF1 = pointPosition;
365 else if (distanceToPoint < distanceF2) {
366 distanceF2 = distanceToPoint;
367 offsetF2 = cellOffset;
368 positionF2 = pointPosition;
384 const float2 localPosition = coord - cellPosition_f;
389 for (
int j = -1; j <= 1; j++) {
390 for (
int i = -1;
i <= 1;
i++) {
396 const float distanceToPoint =
dot(vectorToPoint, vectorToPoint);
397 if (distanceToPoint < minDistance) {
398 minDistance = distanceToPoint;
399 vectorToClosest = vectorToPoint;
405 for (
int j = -1; j <= 1; j++) {
406 for (
int i = -1;
i <= 1;
i++) {
412 const float2 perpendicularToEdge = vectorToPoint - vectorToClosest;
413 if (
dot(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {
414 const float distanceToEdge =
dot((vectorToClosest + vectorToPoint) / 2.0f,
416 minDistance =
min(minDistance, distanceToEdge);
428 const float2 localPosition = coord - cellPosition_f;
434 for (
int j = -1; j <= 1; j++) {
435 for (
int i = -1;
i <= 1;
i++) {
440 const float distanceToPointSq =
len_squared(pointPosition - localPosition);
441 if (distanceToPointSq < minDistanceSq) {
442 minDistanceSq = distanceToPointSq;
443 closestPoint = pointPosition;
444 closestPointOffset = cellOffset;
451 for (
int j = -1; j <= 1; j++) {
452 for (
int i = -1;
i <= 1;
i++) {
453 if (
i == 0 && j == 0) {
460 const float distanceToPointSq =
len_squared(closestPoint - pointPosition);
461 if (distanceToPointSq < minDistanceSq) {
462 minDistanceSq = distanceToPointSq;
463 closestPointToClosestPoint = pointPosition;
468 return distance(closestPointToClosestPoint, closestPoint) / 2.0f;
481 const float3 localPosition = coord - cellPosition_f;
487 for (
int k = -1; k <= 1; k++) {
488 for (
int j = -1; j <= 1; j++) {
489 for (
int i = -1;
i <= 1;
i++) {
495 if (distanceToPoint < minDistance) {
496 targetOffset = cellOffset;
497 minDistance = distanceToPoint;
498 targetPosition = pointPosition;
515 const float3 localPosition = coord - cellPosition_f;
518 float smoothDistance = 0.0f;
522 for (
int k = -2; k <= 2; k++) {
523 for (
int j = -2; j <= 2; j++) {
524 for (
int i = -2;
i <= 2;
i++) {
534 0.5f + 0.5f * (smoothDistance - distanceToPoint) /
params.smoothness);
535 float correctionFactor =
params.smoothness * h * (1.0f - h);
536 smoothDistance =
mix(smoothDistance, distanceToPoint, h) - correctionFactor;
537 correctionFactor /= 1.0f + 3.0f *
params.smoothness;
539 smoothColor =
mix(smoothColor, cellColor, h) - correctionFactor;
540 smoothPosition =
mix(smoothPosition, pointPosition, h) - correctionFactor;
547 octave.
color = smoothColor;
555 const float3 localPosition = coord - cellPosition_f;
564 for (
int k = -1; k <= 1; k++) {
565 for (
int j = -1; j <= 1; j++) {
566 for (
int i = -1;
i <= 1;
i++) {
572 if (distanceToPoint < distanceF1) {
573 distanceF2 = distanceF1;
574 distanceF1 = distanceToPoint;
576 offsetF1 = cellOffset;
577 positionF2 = positionF1;
578 positionF1 = pointPosition;
580 else if (distanceToPoint < distanceF2) {
581 distanceF2 = distanceToPoint;
582 offsetF2 = cellOffset;
583 positionF2 = pointPosition;
600 const float3 localPosition = coord - cellPosition_f;
605 for (
int k = -1; k <= 1; k++) {
606 for (
int j = -1; j <= 1; j++) {
607 for (
int i = -1;
i <= 1;
i++) {
613 const float distanceToPoint =
dot(vectorToPoint, vectorToPoint);
614 if (distanceToPoint < minDistance) {
615 minDistance = distanceToPoint;
616 vectorToClosest = vectorToPoint;
623 for (
int k = -1; k <= 1; k++) {
624 for (
int j = -1; j <= 1; j++) {
625 for (
int i = -1;
i <= 1;
i++) {
631 const float3 perpendicularToEdge = vectorToPoint - vectorToClosest;
632 if (
dot(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {
633 const float distanceToEdge =
dot((vectorToClosest + vectorToPoint) / 2.0f,
635 minDistance =
min(minDistance, distanceToEdge);
648 const float3 localPosition = coord - cellPosition_f;
654 for (
int k = -1; k <= 1; k++) {
655 for (
int j = -1; j <= 1; j++) {
656 for (
int i = -1;
i <= 1;
i++) {
661 const float distanceToPointSq =
len_squared(pointPosition - localPosition);
662 if (distanceToPointSq < minDistanceSq) {
663 minDistanceSq = distanceToPointSq;
664 closestPoint = pointPosition;
665 closestPointOffset = cellOffset;
673 for (
int k = -1; k <= 1; k++) {
674 for (
int j = -1; j <= 1; j++) {
675 for (
int i = -1;
i <= 1;
i++) {
676 if (
i == 0 && j == 0 && k == 0) {
683 const float distanceToPointSq =
len_squared(closestPoint - pointPosition);
684 if (distanceToPointSq < minDistanceSq) {
685 minDistanceSq = distanceToPointSq;
686 closestPointToClosestPoint = pointPosition;
692 return distance(closestPointToClosestPoint, closestPoint) / 2.0f;
705 const float4 localPosition = coord - cellPosition_f;
711 for (
int u = -1; u <= 1; u++) {
712 for (
int k = -1; k <= 1; k++) {
713 for (
int j = -1; j <= 1; j++) {
714 for (
int i = -1;
i <= 1;
i++) {
720 pointPosition, localPosition,
params);
721 if (distanceToPoint < minDistance) {
722 targetOffset = cellOffset;
723 minDistance = distanceToPoint;
724 targetPosition = pointPosition;
742 const float4 localPosition = coord - cellPosition_f;
745 float smoothDistance = 0.0f;
749 for (
int u = -2; u <= 2; u++) {
750 for (
int k = -2; k <= 2; k++) {
751 for (
int j = -2; j <= 2; j++) {
752 for (
int i = -2;
i <= 2;
i++) {
762 0.5f + 0.5f * (smoothDistance - distanceToPoint) /
params.smoothness);
763 float correctionFactor =
params.smoothness * h * (1.0f - h);
764 smoothDistance =
mix(smoothDistance, distanceToPoint, h) - correctionFactor;
765 correctionFactor /= 1.0f + 3.0f *
params.smoothness;
767 smoothColor =
mix(smoothColor, cellColor, h) - correctionFactor;
768 smoothPosition =
mix(smoothPosition, pointPosition, h) - correctionFactor;
776 octave.
color = smoothColor;
784 const float4 localPosition = coord - cellPosition_f;
793 for (
int u = -1; u <= 1; u++) {
794 for (
int k = -1; k <= 1; k++) {
795 for (
int j = -1; j <= 1; j++) {
796 for (
int i = -1;
i <= 1;
i++) {
802 if (distanceToPoint < distanceF1) {
803 distanceF2 = distanceF1;
804 distanceF1 = distanceToPoint;
806 offsetF1 = cellOffset;
807 positionF2 = positionF1;
808 positionF1 = pointPosition;
810 else if (distanceToPoint < distanceF2) {
811 distanceF2 = distanceToPoint;
812 offsetF2 = cellOffset;
813 positionF2 = pointPosition;
831 const float4 localPosition = coord - cellPosition_f;
836 for (
int u = -1; u <= 1; u++) {
837 for (
int k = -1; k <= 1; k++) {
838 for (
int j = -1; j <= 1; j++) {
839 for (
int i = -1;
i <= 1;
i++) {
845 const float distanceToPoint =
dot(vectorToPoint, vectorToPoint);
846 if (distanceToPoint < minDistance) {
847 minDistance = distanceToPoint;
848 vectorToClosest = vectorToPoint;
856 for (
int u = -1; u <= 1; u++) {
857 for (
int k = -1; k <= 1; k++) {
858 for (
int j = -1; j <= 1; j++) {
859 for (
int i = -1;
i <= 1;
i++) {
865 const float4 perpendicularToEdge = vectorToPoint - vectorToClosest;
866 if (
dot(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {
867 const float distanceToEdge =
dot((vectorToClosest + vectorToPoint) / 2.0f,
869 minDistance =
min(minDistance, distanceToEdge);
883 const float4 localPosition = coord - cellPosition_f;
889 for (
int u = -1; u <= 1; u++) {
890 for (
int k = -1; k <= 1; k++) {
891 for (
int j = -1; j <= 1; j++) {
892 for (
int i = -1;
i <= 1;
i++) {
897 const float distanceToPointSq =
len_squared(pointPosition - localPosition);
898 if (distanceToPointSq < minDistanceSq) {
899 minDistanceSq = distanceToPointSq;
900 closestPoint = pointPosition;
901 closestPointOffset = cellOffset;
910 for (
int u = -1; u <= 1; u++) {
911 for (
int k = -1; k <= 1; k++) {
912 for (
int j = -1; j <= 1; j++) {
913 for (
int i = -1;
i <= 1;
i++) {
914 if (
i == 0 && j == 0 && k == 0 && u == 0) {
917 const int4 cellOffset =
make_int4(
i, j, k, u) + closestPointOffset;
921 const float distanceToPointSq =
len_squared(closestPoint - pointPosition);
922 if (distanceToPointSq < minDistanceSq) {
923 minDistanceSq = distanceToPointSq;
924 closestPointToClosestPoint = pointPosition;
931 return distance(closestPointToClosestPoint, closestPoint) / 2.0f;
942 float amplitude = 1.0f;
943 float max_amplitude = 0.0f;
947 const bool zero_input =
params.detail == 0.0f ||
params.roughness == 0.0f;
953 params.smoothness != 0.0f) ?
958 max_amplitude = 1.0f;
963 max_amplitude += amplitude;
967 scale *=
params.lacunarity;
968 amplitude *=
params.roughness;
972 if (remainder != 0.0f) {
973 max_amplitude =
mix(max_amplitude, max_amplitude + amplitude, remainder);
985 output.color /= max_amplitude;
999 float amplitude = 1.0f;
1000 float max_amplitude =
params.max_distance;
1004 const bool zero_input =
params.detail == 0.0f ||
params.roughness == 0.0f;
1014 max_amplitude =
mix(max_amplitude,
params.max_distance / scale, amplitude);
1016 scale *=
params.lacunarity;
1017 amplitude *=
params.roughness;
1021 if (remainder != 0.0f) {
1022 const float lerp_amplitude =
mix(max_amplitude,
params.max_distance / scale, amplitude);
1023 max_amplitude =
mix(max_amplitude, lerp_amplitude, remainder);
1024 const float lerp_distance =
mix(
1046 uint distance_stack_offset;
1047 uint color_stack_offset;
1048 uint position_stack_offset;
1049 uint w_out_stack_offset;
1050 uint radius_stack_offset;
1054 stack_offsets.
z, &unused, &unused, &distance_stack_offset, &color_stack_offset);
1056 stack_offsets.
w, &position_stack_offset, &w_out_stack_offset, &radius_stack_offset);
1075template<u
int node_feature_mask>
1078 const uint dimensions,
1088 uint coord_stack_offset;
1089 uint w_stack_offset;
1090 uint scale_stack_offset;
1091 uint detail_stack_offset;
1092 uint roughness_stack_offset;
1093 uint lacunarity_stack_offset;
1094 uint smoothness_stack_offset;
1095 uint exponent_stack_offset;
1096 uint randomness_stack_offset;
1100 &coord_stack_offset,
1102 &scale_stack_offset,
1103 &detail_stack_offset);
1105 &roughness_stack_offset,
1106 &lacunarity_stack_offset,
1107 &smoothness_stack_offset,
1108 &exponent_stack_offset);
1125 params.max_distance = 0.0f;
1137 switch (
params.feature) {
1141 switch (dimensions) {
1163 float radius = 0.0f;
1164 switch (dimensions) {
1187 switch (dimensions) {
1189 params.max_distance = (0.5f + 0.5f *
params.randomness) *
1198 0.5f + 0.5f *
params.randomness),
1209 0.5f + 0.5f *
params.randomness,
1210 0.5f + 0.5f *
params.randomness),
1221 0.5f + 0.5f *
params.randomness,
1222 0.5f + 0.5f *
params.randomness,
1223 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, 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 float3 hash_int3_to_float3(const int3 k)
ccl_device_inline float3 hash_int4_to_float3(const int4 k)
ccl_device_inline float2 hash_int2_to_float2(const int2 k)
ccl_device_inline float3 hash_int2_to_float3(const int2 k)
ccl_device_inline float4 hash_int4_to_float4(const int4 k)
@ NODE_VORONOI_N_SPHERE_RADIUS
@ NODE_VORONOI_DISTANCE_TO_EDGE
NodeVoronoiDistanceMetric
MINLINE float smoothstep(float edge0, float edge1, float x)
ccl_device_inline dual1 reduce_add(const dual< T > a)
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 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_inline int4 zero_int4()
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 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)