Add Fractal Voronoi Noise V.2 #106827
|
@ -924,7 +924,9 @@ ccl_device void fractal_voronoi_f1(T coord,
|
|||
float octave_amplitude = 1.0f;
|
||||
float octave_distance = 0.0f;
|
||||
|
||||
for (int i = 0; i <= int(detail); ++i) {
|
||||
*max_amplitude = 0.0f;
|
||||
*outDistance = 0.0f;
|
||||
for (int i = 0; i <= ceilf(detail); ++i) {
|
||||
voronoi_f1(coord * octave_scale,
|
||||
exponent,
|
||||
randomness,
|
||||
|
@ -937,7 +939,7 @@ ccl_device void fractal_voronoi_f1(T coord,
|
|||
*outDistance = octave_distance;
|
||||
return;
|
||||
}
|
||||
else if (i != int(detail)) {
|
||||
else if (i <= detail) {
|
||||
*max_amplitude += max_distance * octave_amplitude;
|
||||
*outDistance += octave_distance * octave_amplitude;
|
||||
*outPosition /= octave_scale;
|
||||
|
@ -945,7 +947,7 @@ ccl_device void fractal_voronoi_f1(T coord,
|
|||
octave_amplitude *= roughness;
|
||||
}
|
||||
else {
|
||||
float remainder = detail - floor(detail);
|
||||
float remainder = detail - floorf(detail);
|
||||
if (remainder != 0.0f) {
|
||||
*max_amplitude += max_distance * octave_amplitude;
|
||||
float lerp_distance = *outDistance + octave_distance * octave_amplitude;
|
||||
|
@ -971,11 +973,13 @@ ccl_device void fractal_voronoi_smooth_f1(T coord,
|
|||
ccl_private float3 *outColor,
|
||||
ccl_private T *outPosition)
|
||||
{
|
||||
float octave_scale = lacunarity;
|
||||
float octave_amplitude = roughness;
|
||||
float octave_scale = 1.0f;
|
||||
float octave_amplitude = 1.0f;
|
||||
float octave_distance = 0.0f;
|
||||
|
||||
for (int i = 0; i < int(detail); ++i) {
|
||||
*max_amplitude = 0.0f;
|
||||
*outDistance = 0.0f;
|
||||
for (int i = 0; i <= ceilf(detail); ++i) {
|
||||
voronoi_smooth_f1(coord * octave_scale,
|
||||
smoothness,
|
||||
exponent,
|
||||
|
@ -984,27 +988,27 @@ ccl_device void fractal_voronoi_smooth_f1(T coord,
|
|||
&octave_distance,
|
||||
outColor,
|
||||
outPosition);
|
||||
*max_amplitude += max_distance * octave_amplitude;
|
||||
*outDistance += octave_distance * octave_amplitude;
|
||||
octave_scale *= lacunarity;
|
||||
octave_amplitude *= roughness;
|
||||
}
|
||||
*outPosition /= octave_scale / lacunarity;
|
||||
|
||||
float remainder = detail - int(detail);
|
||||
if (remainder != 0.0f) {
|
||||
voronoi_smooth_f1(coord * octave_scale,
|
||||
smoothness,
|
||||
exponent,
|
||||
randomness,
|
||||
metric,
|
||||
&octave_distance,
|
||||
outColor,
|
||||
outPosition);
|
||||
*max_amplitude += max_distance * octave_amplitude;
|
||||
float lerp_distance = *outDistance + octave_distance * octave_amplitude;
|
||||
*outDistance = (1.0f - remainder) * (*outDistance) + remainder * lerp_distance;
|
||||
*outPosition /= octave_scale;
|
||||
if (detail == 0.0f || roughness == 0.0f || lacunarity == 0.0f) {
|
||||
*max_amplitude = max_distance;
|
||||
*outDistance = octave_distance;
|
||||
return;
|
||||
}
|
||||
else if (i <= detail) {
|
||||
*max_amplitude += max_distance * octave_amplitude;
|
||||
*outDistance += octave_distance * octave_amplitude;
|
||||
*outPosition /= octave_scale;
|
||||
octave_scale *= lacunarity;
|
||||
octave_amplitude *= roughness;
|
||||
}
|
||||
else {
|
||||
float remainder = detail - floorf(detail);
|
||||
if (remainder != 0.0f) {
|
||||
*max_amplitude += max_distance * octave_amplitude;
|
||||
float lerp_distance = *outDistance + octave_distance * octave_amplitude;
|
||||
*outDistance = (1.0f - remainder) * (*outDistance) + remainder * lerp_distance;
|
||||
*outPosition /= octave_scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1022,11 +1026,13 @@ ccl_device void fractal_voronoi_f2(T coord,
|
|||
ccl_private float3 *outColor,
|
||||
ccl_private T *outPosition)
|
||||
{
|
||||
float octave_scale = lacunarity;
|
||||
float octave_amplitude = roughness;
|
||||
float octave_scale = 1.0f;
|
||||
float octave_amplitude = 1.0f;
|
||||
float octave_distance = 0.0f;
|
||||
|
||||
for (int i = 0; i < int(detail); ++i) {
|
||||
*max_amplitude = 0.0f;
|
||||
*outDistance = 0.0f;
|
||||
for (int i = 0; i <= ceilf(detail); ++i) {
|
||||
voronoi_f2(coord * octave_scale,
|
||||
exponent,
|
||||
randomness,
|
||||
|
@ -1034,26 +1040,27 @@ ccl_device void fractal_voronoi_f2(T coord,
|
|||
&octave_distance,
|
||||
outColor,
|
||||
outPosition);
|
||||
*max_amplitude += max_distance * octave_amplitude;
|
||||
*outDistance += octave_distance * octave_amplitude;
|
||||
octave_scale *= lacunarity;
|
||||
octave_amplitude *= roughness;
|
||||
}
|
||||
*outPosition /= octave_scale / lacunarity;
|
||||
|
||||
float remainder = detail - int(detail);
|
||||
if (remainder != 0.0f) {
|
||||
voronoi_f2(coord * octave_scale,
|
||||
exponent,
|
||||
randomness,
|
||||
metric,
|
||||
&octave_distance,
|
||||
outColor,
|
||||
outPosition);
|
||||
*max_amplitude += max_distance * octave_amplitude;
|
||||
float lerp_distance = *outDistance + octave_distance * octave_amplitude;
|
||||
*outDistance = (1.0f - remainder) * (*outDistance) + remainder * lerp_distance;
|
||||
*outPosition /= octave_scale;
|
||||
if (detail == 0.0f || roughness == 0.0f || lacunarity == 0.0f) {
|
||||
*max_amplitude = max_distance;
|
||||
*outDistance = octave_distance;
|
||||
return;
|
||||
}
|
||||
else if (i <= detail) {
|
||||
*max_amplitude += max_distance * octave_amplitude;
|
||||
*outDistance += octave_distance * octave_amplitude;
|
||||
*outPosition /= octave_scale;
|
||||
octave_scale *= lacunarity;
|
||||
octave_amplitude *= roughness;
|
||||
}
|
||||
else {
|
||||
float remainder = detail - floorf(detail);
|
||||
if (remainder != 0.0f) {
|
||||
*max_amplitude += max_distance * octave_amplitude;
|
||||
float lerp_distance = *outDistance + octave_distance * octave_amplitude;
|
||||
*outDistance = (1.0f - remainder) * (*outDistance) + remainder * lerp_distance;
|
||||
*outPosition /= octave_scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1065,15 +1072,17 @@ ccl_device void fractal_voronoi_distance_to_edge(T coord,
|
|||
bool normalize,
|
||||
ccl_private float *outDistance)
|
||||
{
|
||||
float octave_scale = lacunarity;
|
||||
float octave_scale = 1.0f;
|
||||
float octave_distance = 0.0f;
|
||||
for (int i = 0; i < detail; ++i) {
|
||||
|
||||
*outDistance = 8.0f;
|
||||
for (int i = 0; i <= ceilf(detail); ++i) {
|
||||
voronoi_distance_to_edge(coord * octave_scale, randomness, &octave_distance);
|
||||
*outDistance = min(*outDistance, octave_distance / octave_scale);
|
||||
octave_scale *= lacunarity;
|
||||
}
|
||||
if (normalize) {
|
||||
*outDistance *= octave_scale / lacunarity;
|
||||
*outDistance *= (2.0f - randomness) * octave_scale / lacunarity;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1142,89 +1151,76 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
|
|||
|
||||
switch (dimensions) {
|
||||
case 1: {
|
||||
float max_amplitude = 0.0f;
|
||||
|
||||
switch (voronoi_feature) {
|
||||
case NODE_VORONOI_F1: {
|
||||
float max_amplitude = 0.0f;
|
||||
if (detail != 0.0f && roughness != 0.0f && lacunarity != 0.0f) {
|
||||
fractal_voronoi_f1<float>(w,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
1.0f,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&w_out);
|
||||
}
|
||||
fractal_voronoi_f1<float>(w,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
1.0f,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&w_out);
|
||||
if (normalize) {
|
||||
distance_out /= max_amplitude;
|
||||
distance_out /= (0.5f + 0.5f * randomness) *
|
||||
max_amplitude; /* Optimized std::lerp(max_amplitude*0.5, max_amplitude,
|
||||
randomness) */
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NODE_VORONOI_SMOOTH_F1: {
|
||||
voronoi_smooth_f1(w,
|
||||
smoothness,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&w_out);
|
||||
|
||||
float max_amplitude = 1.0f;
|
||||
if (detail != 0.0f && roughness != 0.0f && lacunarity != 0.0f) {
|
||||
fractal_voronoi_smooth_f1<float>(w,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
smoothness,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
1.0f,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&w_out);
|
||||
}
|
||||
fractal_voronoi_smooth_f1<float>(w,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
smoothness,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
1.0f,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&w_out);
|
||||
if (normalize) {
|
||||
distance_out /= max_amplitude;
|
||||
distance_out /= (0.5f + 0.5f * randomness) *
|
||||
max_amplitude; /* Optimized std::lerp(max_amplitude*0.5, max_amplitude,
|
||||
randomness) */
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NODE_VORONOI_F2: {
|
||||
voronoi_f2(w, exponent, randomness, voronoi_metric, &distance_out, &color_out, &w_out);
|
||||
|
||||
float max_amplitude = 1.0f;
|
||||
if (detail != 0.0f && roughness != 0.0f && lacunarity != 0.0f) {
|
||||
fractal_voronoi_f2<float>(w,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
1.0f,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&w_out);
|
||||
}
|
||||
fractal_voronoi_f2<float>(w,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
1.0f,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&w_out);
|
||||
if (normalize) {
|
||||
distance_out /= max_amplitude;
|
||||
if (detail == 0.0f || roughness == 0.0f || lacunarity == 0.0f) {
|
||||
distance_out /= (1 - randomness) + randomness * max_amplitude;
|
||||
}
|
||||
else {
|
||||
distance_out /= (1 - randomness) * ceilf(detail + 1.0f) + randomness * max_amplitude;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NODE_VORONOI_DISTANCE_TO_EDGE: {
|
||||
voronoi_distance_to_edge(w, randomness, &distance_out);
|
||||
|
||||
if (detail != 0.0f && lacunarity != 0.0f) {
|
||||
fractal_voronoi_distance_to_edge<float>(
|
||||
w, detail, lacunarity, randomness, normalize, &distance_out);
|
||||
}
|
||||
fractal_voronoi_distance_to_edge<float>(
|
||||
w, detail, lacunarity, randomness, normalize, &distance_out);
|
||||
break;
|
||||
}
|
||||
case NODE_VORONOI_N_SPHERE_RADIUS:
|
||||
|
@ -1239,103 +1235,81 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
|
|||
case 2: {
|
||||
float2 coord_2d = make_float2(coord.x, coord.y);
|
||||
float2 position_out_2d = zero_float2();
|
||||
const float max_distance = voronoi_distance_2d(
|
||||
make_float2(1.0f, 1.0f), make_float2(0.0f, 0.0f), voronoi_metric, exponent);
|
||||
float max_amplitude = 0.0f;
|
||||
|
||||
switch (voronoi_feature) {
|
||||
case NODE_VORONOI_F1: {
|
||||
const float max_distance = voronoi_distance_2d(
|
||||
make_float2(1.0f, 1.0f), make_float2(0.0f, 0.0f), voronoi_metric, exponent);
|
||||
float max_amplitude = 0.0f;
|
||||
if (detail != 0.0f && roughness != 0.0f && lacunarity != 0.0f) {
|
||||
fractal_voronoi_f1<float2>(coord_2d,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
max_distance,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out_2d);
|
||||
}
|
||||
fractal_voronoi_f1<float2>(coord_2d,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
max_distance,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out_2d);
|
||||
if (normalize) {
|
||||
distance_out /= max_amplitude;
|
||||
distance_out /= (0.5f + 0.5f * randomness) *
|
||||
max_amplitude; /* Optimized std::lerp(max_amplitude*0.5, max_amplitude,
|
||||
randomness) */
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NODE_VORONOI_SMOOTH_F1:
|
||||
IF_KERNEL_NODES_FEATURE(VORONOI_EXTRA)
|
||||
{
|
||||
voronoi_smooth_f1(coord_2d,
|
||||
smoothness,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out_2d);
|
||||
|
||||
const float max_distance = voronoi_distance_2d(
|
||||
make_float2(1.0f, 1.0f), make_float2(0.0f, 0.0f), voronoi_metric, exponent);
|
||||
float max_amplitude = max_distance;
|
||||
if (detail != 0.0f && roughness != 0.0f && lacunarity != 0.0f) {
|
||||
fractal_voronoi_smooth_f1<float2>(coord_2d,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
smoothness,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
max_distance,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out_2d);
|
||||
}
|
||||
fractal_voronoi_smooth_f1<float2>(coord_2d,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
smoothness,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
max_distance,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out_2d);
|
||||
if (normalize) {
|
||||
distance_out /= max_amplitude;
|
||||
distance_out /= (0.5f + 0.5f * randomness) *
|
||||
max_amplitude; /* Optimized std::lerp(max_amplitude*0.5,
|
||||
max_amplitude, randomness) */
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case NODE_VORONOI_F2: {
|
||||
voronoi_f2(coord_2d,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out_2d);
|
||||
|
||||
const float max_distance = voronoi_distance_2d(
|
||||
make_float2(1.0f, 1.0f), make_float2(0.0f, 0.0f), voronoi_metric, exponent);
|
||||
float max_amplitude = max_distance;
|
||||
if (detail != 0.0f && roughness != 0.0f && lacunarity != 0.0f) {
|
||||
fractal_voronoi_f2<float2>(coord_2d,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
max_distance,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out_2d);
|
||||
}
|
||||
fractal_voronoi_f2<float2>(coord_2d,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
max_distance,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out_2d);
|
||||
if (normalize) {
|
||||
distance_out /= max_amplitude;
|
||||
if (detail == 0.0f || roughness == 0.0f || lacunarity == 0.0f) {
|
||||
distance_out /= (1 - randomness) + randomness * max_amplitude;
|
||||
}
|
||||
else {
|
||||
distance_out /= (1 - randomness) * ceilf(detail + 1.0f) + randomness * max_amplitude;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NODE_VORONOI_DISTANCE_TO_EDGE: {
|
||||
voronoi_distance_to_edge(coord_2d, randomness, &distance_out);
|
||||
|
||||
if (detail != 0.0f && lacunarity != 0.0f) {
|
||||
fractal_voronoi_distance_to_edge<float2>(
|
||||
coord_2d, detail, lacunarity, randomness, normalize, &distance_out);
|
||||
}
|
||||
fractal_voronoi_distance_to_edge<float2>(
|
||||
coord_2d, detail, lacunarity, randomness, normalize, &distance_out);
|
||||
break;
|
||||
}
|
||||
case NODE_VORONOI_N_SPHERE_RADIUS:
|
||||
|
@ -1349,112 +1323,81 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
|
|||
break;
|
||||
}
|
||||
case 3: {
|
||||
const float max_distance = voronoi_distance_3d(
|
||||
make_float3(1.0f, 1.0f, 1.0f), make_float3(0.0f, 0.0f, 0.0f), voronoi_metric, exponent);
|
||||
float max_amplitude = 0.0f;
|
||||
|
||||
switch (voronoi_feature) {
|
||||
case NODE_VORONOI_F1: {
|
||||
const float max_distance = voronoi_distance_3d(make_float3(1.0f, 1.0f, 1.0f),
|
||||
make_float3(0.0f, 0.0f, 0.0f),
|
||||
voronoi_metric,
|
||||
exponent);
|
||||
float max_amplitude = 0.0f;
|
||||
if (detail != 0.0f && roughness != 0.0f && lacunarity != 0.0f) {
|
||||
fractal_voronoi_f1<float3>(coord,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
max_distance,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out);
|
||||
}
|
||||
|
||||
fractal_voronoi_f1<float3>(coord,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
max_distance,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out);
|
||||
if (normalize) {
|
||||
distance_out /= max_amplitude;
|
||||
distance_out /= (0.5f + 0.5f * randomness) *
|
||||
max_amplitude; /* Optimized std::lerp(max_amplitude*0.5, max_amplitude,
|
||||
randomness) */
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NODE_VORONOI_SMOOTH_F1:
|
||||
IF_KERNEL_NODES_FEATURE(VORONOI_EXTRA)
|
||||
{
|
||||
voronoi_smooth_f1(coord,
|
||||
smoothness,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out);
|
||||
|
||||
const float max_distance = voronoi_distance_3d(make_float3(1.0f, 1.0f, 1.0f),
|
||||
make_float3(0.0f, 0.0f, 0.0f),
|
||||
voronoi_metric,
|
||||
exponent);
|
||||
float max_amplitude = max_distance;
|
||||
if (detail != 0.0f && roughness != 0.0f && lacunarity != 0.0f) {
|
||||
fractal_voronoi_smooth_f1<float3>(coord,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
smoothness,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
max_distance,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out);
|
||||
}
|
||||
|
||||
fractal_voronoi_smooth_f1<float3>(coord,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
smoothness,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
max_distance,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out);
|
||||
if (normalize) {
|
||||
distance_out /= max_amplitude;
|
||||
distance_out /= (0.5f + 0.5f * randomness) *
|
||||
max_amplitude; /* Optimized std::lerp(max_amplitude*0.5,
|
||||
max_amplitude, randomness) */
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case NODE_VORONOI_F2: {
|
||||
voronoi_f2(coord,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out);
|
||||
|
||||
const float max_distance = voronoi_distance_3d(make_float3(1.0f, 1.0f, 1.0f),
|
||||
make_float3(0.0f, 0.0f, 0.0f),
|
||||
voronoi_metric,
|
||||
exponent);
|
||||
float max_amplitude = max_distance;
|
||||
if (detail != 0.0f && roughness != 0.0f && lacunarity != 0.0f) {
|
||||
fractal_voronoi_f2<float3>(coord,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
max_distance,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out);
|
||||
}
|
||||
|
||||
fractal_voronoi_f2<float3>(coord,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
max_distance,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out);
|
||||
if (normalize) {
|
||||
distance_out /= max_amplitude;
|
||||
if (detail == 0.0f || roughness == 0.0f || lacunarity == 0.0f) {
|
||||
distance_out /= (1 - randomness) + randomness * max_amplitude;
|
||||
}
|
||||
else {
|
||||
distance_out /= (1 - randomness) * ceilf(detail + 1.0f) + randomness * max_amplitude;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NODE_VORONOI_DISTANCE_TO_EDGE: {
|
||||
voronoi_distance_to_edge(coord, randomness, &distance_out);
|
||||
|
||||
if (detail != 0.0f && lacunarity != 0.0f) {
|
||||
fractal_voronoi_distance_to_edge<float3>(
|
||||
coord, detail, lacunarity, randomness, normalize, &distance_out);
|
||||
}
|
||||
fractal_voronoi_distance_to_edge<float3>(
|
||||
coord, detail, lacunarity, randomness, normalize, &distance_out);
|
||||
break;
|
||||
}
|
||||
case NODE_VORONOI_N_SPHERE_RADIUS:
|
||||
|
@ -1472,106 +1415,81 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
|
|||
{
|
||||
float4 coord_4d = make_float4(coord.x, coord.y, coord.z, w);
|
||||
float4 position_out_4d;
|
||||
const float max_distance = voronoi_distance_4d(make_float4(1.0f, 1.0f, 1.0f, 1.0f),
|
||||
make_float4(0.0f, 0.0f, 0.0f, 0.0f),
|
||||
voronoi_metric,
|
||||
exponent);
|
||||
float max_amplitude = 0.0f;
|
||||
|
||||
switch (voronoi_feature) {
|
||||
const float max_distance = voronoi_distance_4d(make_float4(1.0f, 1.0f, 1.0f, 1.0f),
|
||||
make_float4(0.0f, 0.0f, 0.0f, 0.0f),
|
||||
voronoi_metric,
|
||||
exponent);
|
||||
float max_amplitude = 0.0f;
|
||||
if (detail != 0.0f && roughness != 0.0f && lacunarity != 0.0f) {
|
||||
fractal_voronoi_f1<float4>(coord_4d,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
max_distance,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out_4d);
|
||||
}
|
||||
case NODE_VORONOI_F1: {
|
||||
fractal_voronoi_f1<float4>(coord_4d,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
max_distance,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out_4d);
|
||||
if (normalize) {
|
||||
distance_out /= max_amplitude;
|
||||
distance_out /= (0.5f + 0.5f * randomness) *
|
||||
max_amplitude; /* Optimized std::lerp(max_amplitude*0.5,
|
||||
max_amplitude, randomness) */
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NODE_VORONOI_SMOOTH_F1: {
|
||||
voronoi_smooth_f1(coord_4d,
|
||||
smoothness,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out_4d);
|
||||
|
||||
const float max_distance = voronoi_distance_4d(make_float4(1.0f, 1.0f, 1.0f, 1.0f),
|
||||
make_float4(0.0f, 0.0f, 0.0f, 0.0f),
|
||||
voronoi_metric,
|
||||
exponent);
|
||||
float max_amplitude = max_distance;
|
||||
if (detail != 0.0f && roughness != 0.0f && lacunarity != 0.0f) {
|
||||
fractal_voronoi_smooth_f1<float4>(coord_4d,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
smoothness,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
max_distance,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out_4d);
|
||||
}
|
||||
fractal_voronoi_smooth_f1<float4>(coord_4d,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
smoothness,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
max_distance,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out_4d);
|
||||
if (normalize) {
|
||||
distance_out /= max_amplitude;
|
||||
distance_out /= (0.5f + 0.5f * randomness) *
|
||||
max_amplitude; /* Optimized std::lerp(max_amplitude*0.5,
|
||||
max_amplitude, randomness) */
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NODE_VORONOI_F2: {
|
||||
voronoi_f2(coord_4d,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out_4d);
|
||||
|
||||
const float max_distance = voronoi_distance_4d(make_float4(1.0f, 1.0f, 1.0f, 1.0f),
|
||||
make_float4(0.0f, 0.0f, 0.0f, 0.0f),
|
||||
voronoi_metric,
|
||||
exponent);
|
||||
float max_amplitude = max_distance;
|
||||
if (detail != 0.0f && roughness != 0.0f && lacunarity != 0.0f) {
|
||||
fractal_voronoi_f2<float4>(coord_4d,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
max_distance,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out_4d);
|
||||
}
|
||||
fractal_voronoi_f2<float4>(coord_4d,
|
||||
detail,
|
||||
roughness,
|
||||
lacunarity,
|
||||
exponent,
|
||||
randomness,
|
||||
voronoi_metric,
|
||||
max_distance,
|
||||
&max_amplitude,
|
||||
&distance_out,
|
||||
&color_out,
|
||||
&position_out_4d);
|
||||
if (normalize) {
|
||||
distance_out /= max_amplitude;
|
||||
if (detail == 0.0f || roughness == 0.0f || lacunarity == 0.0f) {
|
||||
distance_out /= (1 - randomness) + randomness * max_amplitude;
|
||||
}
|
||||
else {
|
||||
distance_out /= (1 - randomness) * ceilf(detail + 1.0f) +
|
||||
randomness * max_amplitude;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NODE_VORONOI_DISTANCE_TO_EDGE: {
|
||||
voronoi_distance_to_edge(coord_4d, randomness, &distance_out);
|
||||
|
||||
if (detail != 0.0f && lacunarity != 0.0f) {
|
||||
fractal_voronoi_distance_to_edge<float4>(
|
||||
coord_4d, detail, lacunarity, randomness, normalize, &distance_out);
|
||||
}
|
||||
fractal_voronoi_distance_to_edge<float4>(
|
||||
coord_4d, detail, lacunarity, randomness, normalize, &distance_out);
|
||||
break;
|
||||
}
|
||||
case NODE_VORONOI_N_SPHERE_RADIUS:
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit e398d3c4969a37ae2ecff388344dd780bc1cfe82
|
||||
Subproject commit 8b4e4e9190467e0d71f200681681b9d67281d01d
|
|
@ -1 +1 @@
|
|||
Subproject commit 90c87dd771e027e0ffa157a0e294399bfd605d99
|
||||
Subproject commit d4c8ec5cdff2337c34838b2ff83108697e1d4abe
|
|
@ -1 +1 @@
|
|||
Subproject commit 96143b1a8b037ea3c81f065f557025db9fe1ace3
|
||||
Subproject commit bdcfdd47ec3451822b21d1cff2ea2db751093c9a
|
|
@ -2365,35 +2365,47 @@ void fractal_voronoi_f1(const T coord,
|
|||
float3 *r_color,
|
||||
T *r_position)
|
||||
{
|
||||
float octave_scale = lacunarity;
|
||||
float octave_amplitude = roughness;
|
||||
float octave_scale = 1.0f;
|
||||
float octave_amplitude = 1.0f;
|
||||
float octave_distance = 0.0f;
|
||||
|
||||
for (int i = 0; i < int(detail); ++i) {
|
||||
if (r_distance != nullptr) {
|
||||
*r_max_amplitude = 0.0f;
|
||||
*r_distance = 0.0f;
|
||||
}
|
||||
for (int i = 0; i <= ceilf(detail); ++i) {
|
||||
voronoi_f1(
|
||||
coord * octave_scale, exponent, randomness, metric, &octave_distance, r_color, r_position);
|
||||
*r_max_amplitude += max_distance * octave_amplitude;
|
||||
if (r_distance != nullptr) {
|
||||
*r_distance += octave_distance * octave_amplitude;
|
||||
if (detail == 0.0f || roughness == 0.0f || lacunarity == 0.0f) {
|
||||
if (r_distance != nullptr) {
|
||||
*r_max_amplitude = max_distance;
|
||||
*r_distance = octave_distance;
|
||||
}
|
||||
return;
|
||||
}
|
||||
octave_scale *= lacunarity;
|
||||
octave_amplitude *= roughness;
|
||||
}
|
||||
if (r_position != nullptr) {
|
||||
*r_position /= octave_scale / lacunarity;
|
||||
}
|
||||
|
||||
float remainder = detail - int(detail);
|
||||
if (remainder != 0.0f) {
|
||||
voronoi_f1(
|
||||
coord * octave_scale, exponent, randomness, metric, &octave_distance, r_color, r_position);
|
||||
*r_max_amplitude += max_distance * octave_amplitude;
|
||||
if (r_distance != nullptr) {
|
||||
float lerp_distance = *r_distance + octave_distance * octave_amplitude;
|
||||
*r_distance = (1.0f - remainder) * (*r_distance) + remainder * lerp_distance;
|
||||
else if (i <= detail) {
|
||||
if (r_distance != nullptr) {
|
||||
*r_max_amplitude += max_distance * octave_amplitude;
|
||||
*r_distance += octave_distance * octave_amplitude;
|
||||
}
|
||||
if (r_position != nullptr) {
|
||||
*r_position /= octave_scale;
|
||||
}
|
||||
octave_scale *= lacunarity;
|
||||
octave_amplitude *= roughness;
|
||||
}
|
||||
if (r_position != nullptr) {
|
||||
*r_position /= octave_scale;
|
||||
else {
|
||||
float remainder = detail - std::floorf(detail);
|
||||
if (remainder != 0.0f) {
|
||||
if (r_distance != nullptr) {
|
||||
*r_max_amplitude += max_distance * octave_amplitude;
|
||||
float lerp_distance = *r_distance + octave_distance * octave_amplitude;
|
||||
*r_distance = (1.0f - remainder) * (*r_distance) + remainder * lerp_distance;
|
||||
}
|
||||
if (r_position != nullptr) {
|
||||
*r_position /= octave_scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2413,11 +2425,15 @@ void fractal_voronoi_smooth_f1(const T coord,
|
|||
float3 *r_color,
|
||||
T *r_position)
|
||||
{
|
||||
float octave_scale = lacunarity;
|
||||
float octave_amplitude = roughness;
|
||||
float octave_scale = 1.0f;
|
||||
float octave_amplitude = 1.0f;
|
||||
float octave_distance = 0.0f;
|
||||
|
||||
for (int i = 0; i < int(detail); ++i) {
|
||||
if (r_distance != nullptr) {
|
||||
*r_max_amplitude = 0.0f;
|
||||
*r_distance = 0.0f;
|
||||
}
|
||||
for (int i = 0; i <= ceilf(detail); ++i) {
|
||||
voronoi_smooth_f1(coord * octave_scale,
|
||||
smoothness,
|
||||
exponent,
|
||||
|
@ -2426,34 +2442,36 @@ void fractal_voronoi_smooth_f1(const T coord,
|
|||
&octave_distance,
|
||||
r_color,
|
||||
r_position);
|
||||
*r_max_amplitude += max_distance * octave_amplitude;
|
||||
if (r_distance != nullptr) {
|
||||
*r_distance += octave_distance * octave_amplitude;
|
||||
if (detail == 0.0f || roughness == 0.0f || lacunarity == 0.0f) {
|
||||
if (r_distance != nullptr) {
|
||||
*r_max_amplitude = max_distance;
|
||||
*r_distance = octave_distance;
|
||||
}
|
||||
return;
|
||||
}
|
||||
octave_scale *= lacunarity;
|
||||
octave_amplitude *= roughness;
|
||||
}
|
||||
if (r_position != nullptr) {
|
||||
*r_position /= octave_scale / lacunarity;
|
||||
}
|
||||
|
||||
float remainder = detail - int(detail);
|
||||
if (remainder != 0.0f) {
|
||||
voronoi_smooth_f1(coord * octave_scale,
|
||||
smoothness,
|
||||
exponent,
|
||||
randomness,
|
||||
metric,
|
||||
&octave_distance,
|
||||
r_color,
|
||||
r_position);
|
||||
*r_max_amplitude += max_distance * octave_amplitude;
|
||||
if (r_distance != nullptr) {
|
||||
float lerp_distance = *r_distance + octave_distance * octave_amplitude;
|
||||
*r_distance = (1.0f - remainder) * (*r_distance) + remainder * lerp_distance;
|
||||
else if (i <= detail) {
|
||||
if (r_distance != nullptr) {
|
||||
*r_max_amplitude += max_distance * octave_amplitude;
|
||||
*r_distance += octave_distance * octave_amplitude;
|
||||
}
|
||||
if (r_position != nullptr) {
|
||||
*r_position /= octave_scale;
|
||||
}
|
||||
octave_scale *= lacunarity;
|
||||
octave_amplitude *= roughness;
|
||||
}
|
||||
if (r_position != nullptr) {
|
||||
*r_position /= octave_scale;
|
||||
else {
|
||||
float remainder = detail - std::floorf(detail);
|
||||
if (remainder != 0.0f) {
|
||||
if (r_distance != nullptr) {
|
||||
*r_max_amplitude += max_distance * octave_amplitude;
|
||||
float lerp_distance = *r_distance + octave_distance * octave_amplitude;
|
||||
*r_distance = (1.0f - remainder) * (*r_distance) + remainder * lerp_distance;
|
||||
}
|
||||
if (r_position != nullptr) {
|
||||
*r_position /= octave_scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2472,35 +2490,47 @@ void fractal_voronoi_f2(const T coord,
|
|||
float3 *r_color,
|
||||
T *r_position)
|
||||
{
|
||||
float octave_scale = lacunarity;
|
||||
float octave_amplitude = roughness;
|
||||
float octave_scale = 1.0f;
|
||||
float octave_amplitude = 1.0f;
|
||||
float octave_distance = 0.0f;
|
||||
|
||||
for (int i = 0; i < int(detail); ++i) {
|
||||
if (r_distance != nullptr) {
|
||||
*r_max_amplitude = 0.0f;
|
||||
*r_distance = 0.0f;
|
||||
}
|
||||
for (int i = 0; i <= ceilf(detail); ++i) {
|
||||
voronoi_f2(
|
||||
coord * octave_scale, exponent, randomness, metric, &octave_distance, r_color, r_position);
|
||||
*r_max_amplitude += max_distance * octave_amplitude;
|
||||
if (r_distance != nullptr) {
|
||||
*r_distance += octave_distance * octave_amplitude;
|
||||
if (detail == 0.0f || roughness == 0.0f || lacunarity == 0.0f) {
|
||||
if (r_distance != nullptr) {
|
||||
*r_max_amplitude = max_distance;
|
||||
*r_distance = octave_distance;
|
||||
}
|
||||
return;
|
||||
}
|
||||
octave_scale *= lacunarity;
|
||||
octave_amplitude *= roughness;
|
||||
}
|
||||
if (r_position != nullptr) {
|
||||
*r_position /= octave_scale / lacunarity;
|
||||
}
|
||||
|
||||
float remainder = detail - int(detail);
|
||||
if (remainder != 0.0f) {
|
||||
voronoi_f2(
|
||||
coord * octave_scale, exponent, randomness, metric, &octave_distance, r_color, r_position);
|
||||
*r_max_amplitude += max_distance * octave_amplitude;
|
||||
if (r_distance != nullptr) {
|
||||
float lerp_distance = *r_distance + octave_distance * octave_amplitude;
|
||||
*r_distance = (1.0f - remainder) * (*r_distance) + remainder * lerp_distance;
|
||||
else if (i <= detail) {
|
||||
if (r_distance != nullptr) {
|
||||
*r_max_amplitude += max_distance * octave_amplitude;
|
||||
*r_distance += octave_distance * octave_amplitude;
|
||||
}
|
||||
if (r_position != nullptr) {
|
||||
*r_position /= octave_scale;
|
||||
}
|
||||
octave_scale *= lacunarity;
|
||||
octave_amplitude *= roughness;
|
||||
}
|
||||
if (r_position != nullptr) {
|
||||
*r_position /= octave_scale;
|
||||
else {
|
||||
float remainder = detail - std::floorf(detail);
|
||||
if (remainder != 0.0f) {
|
||||
if (r_distance != nullptr) {
|
||||
*r_max_amplitude += max_distance * octave_amplitude;
|
||||
float lerp_distance = *r_distance + octave_distance * octave_amplitude;
|
||||
*r_distance = (1.0f - remainder) * (*r_distance) + remainder * lerp_distance;
|
||||
}
|
||||
if (r_position != nullptr) {
|
||||
*r_position /= octave_scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2513,15 +2543,17 @@ void fractal_voronoi_distance_to_edge(const T coord,
|
|||
const bool normalize,
|
||||
float *r_distance)
|
||||
{
|
||||
float octave_scale = lacunarity;
|
||||
float octave_scale = 1.0f;
|
||||
float octave_distance = 0.0f;
|
||||
for (int i = 0; i < detail; ++i) {
|
||||
|
||||
*r_distance = 8.0f;
|
||||
for (int i = 0; i <= ceilf(detail); ++i) {
|
||||
voronoi_distance_to_edge(coord * octave_scale, randomness, &octave_distance);
|
||||
*r_distance = std::min(*r_distance, octave_distance / octave_scale);
|
||||
octave_scale *= lacunarity;
|
||||
}
|
||||
if (normalize) {
|
||||
*r_distance *= octave_scale / lacunarity;
|
||||
*r_distance *= (2.0f - randomness) * octave_scale / lacunarity;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1 +1 @@
|
|||
Subproject commit fdfa2fcb9495d87571f2dfe2ae9fa0e032536600
|
||||
Subproject commit f542f4d21a077d85ffb3e43aa7f170976dee20b6
|
Loading…
Reference in New Issue