Add Fractal Voronoi Noise V.2 #106827

Merged
Jacques Lucke merged 77 commits from Hoshinova/blender:add-fractal-voronoi into main 2023-06-13 09:18:18 +02:00
4 changed files with 2966 additions and 609 deletions
Showing only changes of commit f370d29622 - Show all commits

View File

@ -964,9 +964,75 @@ shader node_voronoi_texture(
}
else if (feature == "smooth_f1") {
voronoi_smooth_f1_1d(w, smoothness, Exponent, randomness, metric, Distance, Color, WOut);
float max_amplitude = 1.0;
if(detail!=0.0&&roughness != 0.0 && Lacunarity != 0.0)
{
float octave_scale = Lacunarity;
float octave_amplitude = roughness;
float octave_distance = 0.0;
for(int i = 0; i < int(detail);++i)
{
voronoi_smooth_f1_1d(w*octave_scale,smoothness, Exponent, randomness, metric, octave_distance, Color, WOut);
max_amplitude += octave_amplitude;
Distance += octave_distance * octave_amplitude;
octave_scale *= Lacunarity;
octave_amplitude *= roughness;
}
WOut /= octave_scale / Lacunarity;
float remainder = detail - int(detail);
if (remainder != 0.0)
{
voronoi_smooth_f1_1d(w*octave_scale,smoothness, Exponent, randomness, metric, octave_distance, Color, WOut);
max_amplitude += octave_amplitude;
float lerp_distance = Distance + octave_distance * octave_amplitude;
Distance = (1.0 - remainder) * Distance + remainder * lerp_distance;
WOut /= octave_scale;
}
}
if (normalize) {
Distance /= max_amplitude;
}
}
else if (feature == "f2") {
voronoi_f2_1d(w, Exponent, randomness, metric, Distance, Color, WOut);
float max_amplitude = 1.0;
if(detail!=0.0&&roughness != 0.0 && Lacunarity != 0.0)
{
float octave_scale = Lacunarity;
float octave_amplitude = roughness;
float octave_distance = 0.0;
for(int i = 0; i < int(detail);++i)
{
voronoi_f2_1d(w*octave_scale, Exponent, randomness, metric, octave_distance, Color, WOut);
max_amplitude += octave_amplitude;
Distance += octave_distance * octave_amplitude;
octave_scale *= Lacunarity;
octave_amplitude *= roughness;
}
WOut /= octave_scale / Lacunarity;
float remainder = detail - int(detail);
if (remainder != 0.0)
{
voronoi_f2_1d(w*octave_scale, Exponent, randomness, metric, octave_distance, Color, WOut);
max_amplitude += octave_amplitude;
float lerp_distance = Distance + octave_distance * octave_amplitude;
Distance = (1.0 - remainder) * Distance + remainder * lerp_distance;
WOut /= octave_scale;
}
}
if (normalize) {
Distance /= max_amplitude;
}
}
else if (feature == "distance_to_edge") {
voronoi_distance_to_edge_1d(w, randomness, Distance);
@ -985,7 +1051,8 @@ shader node_voronoi_texture(
if (feature == "f1") {
voronoi_f1_2d(coord2D, Exponent, randomness, metric, Distance, Color, outPosition2D);
float max_amplitude = 1.41421356237; /* 1.41421356237 == sqrt(2) */
float max_distance = voronoi_distance(vector2(1.0,1.0), vector2(0.0,0.0), metric, Exponent);
float max_amplitude = max_distance;
if(detail!=0.0&&roughness != 0.0 && Lacunarity != 0.0)
{
float octave_scale = Lacunarity;
@ -996,7 +1063,7 @@ shader node_voronoi_texture(
{
voronoi_f1_2d(coord2D*octave_scale, Exponent, randomness, metric, octave_distance, Color, outPosition2D);
max_amplitude += 1.41421356237 * octave_amplitude;
max_amplitude += max_distance * octave_amplitude;
Distance += octave_distance * octave_amplitude;
octave_scale *= Lacunarity;
octave_amplitude *= roughness;
@ -1008,7 +1075,7 @@ shader node_voronoi_texture(
if (remainder != 0.0)
{
voronoi_f1_2d(coord2D*octave_scale, Exponent, randomness, metric, octave_distance, Color, outPosition2D);
max_amplitude += 1.41421356237 * octave_amplitude;
max_amplitude += max_distance * octave_amplitude;
float lerp_distance = Distance + octave_distance * octave_amplitude;
Distance = (1.0 - remainder) * Distance + remainder * lerp_distance;
outPosition2D /= octave_scale;
@ -1021,9 +1088,77 @@ shader node_voronoi_texture(
else if (feature == "smooth_f1") {
voronoi_smooth_f1_2d(
coord2D, smoothness, Exponent, randomness, metric, Distance, Color, outPosition2D);
float max_distance = voronoi_distance(vector2(1.0,1.0), vector2(0.0,0.0), metric, Exponent);
float max_amplitude = max_distance;
if(detail!=0.0&&roughness != 0.0 && Lacunarity != 0.0)
{
float octave_scale = Lacunarity;
float octave_amplitude = roughness;
float octave_distance = 0.0;
for(int i = 0; i < int(detail);++i)
{
voronoi_smooth_f1_2d(coord2D*octave_scale, smoothness,Exponent, randomness, metric, octave_distance, Color, outPosition2D);
max_amplitude += max_distance * octave_amplitude;
Distance += octave_distance * octave_amplitude;
octave_scale *= Lacunarity;
octave_amplitude *= roughness;
}
outPosition2D /= octave_scale / Lacunarity;
float remainder = detail - int(detail);
if (remainder != 0.0)
{
voronoi_smooth_f1_2d(coord2D*octave_scale, smoothness,Exponent, randomness, metric, octave_distance, Color, outPosition2D);
max_amplitude += max_distance * octave_amplitude;
float lerp_distance = Distance + octave_distance * octave_amplitude;
Distance = (1.0 - remainder) * Distance + remainder * lerp_distance;
outPosition2D /= octave_scale;
}
}
if (normalize) {
Distance /= max_amplitude;
}
}
else if (feature == "f2") {
voronoi_f2_2d(coord2D, Exponent, randomness, metric, Distance, Color, outPosition2D);
float max_distance = voronoi_distance(vector2(1.0,1.0), vector2(0.0,0.0), metric, Exponent);
float max_amplitude = max_distance;
if(detail!=0.0&&roughness != 0.0 && Lacunarity != 0.0)
{
float octave_scale = Lacunarity;
float octave_amplitude = roughness;
float octave_distance = 0.0;
for(int i = 0; i < int(detail);++i)
{
voronoi_f2_2d(coord2D*octave_scale, Exponent, randomness, metric, octave_distance, Color, outPosition2D);
max_amplitude += max_distance * octave_amplitude;
Distance += octave_distance * octave_amplitude;
octave_scale *= Lacunarity;
octave_amplitude *= roughness;
}
outPosition2D /= octave_scale / Lacunarity;
float remainder = detail - int(detail);
if (remainder != 0.0)
{
voronoi_f2_2d(coord2D*octave_scale, Exponent, randomness, metric, octave_distance, Color, outPosition2D);
max_amplitude += max_distance * octave_amplitude;
float lerp_distance = Distance + octave_distance * octave_amplitude;
Distance = (1.0 - remainder) * Distance + remainder * lerp_distance;
outPosition2D /= octave_scale;
}
}
if (normalize) {
Distance /= max_amplitude;
}
}
else if (feature == "distance_to_edge") {
voronoi_distance_to_edge_2d(coord2D, randomness, Distance);
@ -1041,7 +1176,8 @@ shader node_voronoi_texture(
if (feature == "f1") {
voronoi_f1_3d(coord, Exponent, randomness, metric, Distance, Color, Position);
float max_amplitude = 1.73205080757; /* 1.73205080757 == sqrt(3) */
float max_distance = voronoi_distance(vector3(1.0,1.0,1.0), vector3(0.0,0.0,0.0), metric, Exponent);
float max_amplitude = max_distance;
if(detail!=0.0&&roughness != 0.0 && Lacunarity != 0.0)
{
float octave_scale = Lacunarity;
@ -1052,7 +1188,7 @@ shader node_voronoi_texture(
{
voronoi_f1_3d(coord*octave_scale, Exponent, randomness, metric, octave_distance, Color, Position);
max_amplitude += 1.73205080757 * octave_amplitude;
max_amplitude += max_distance * octave_amplitude;
Distance += octave_distance * octave_amplitude;
octave_scale *= Lacunarity;
octave_amplitude *= roughness;
@ -1064,7 +1200,7 @@ shader node_voronoi_texture(
if (remainder != 0.0)
{
voronoi_f1_3d(coord*octave_scale, Exponent, randomness, metric, octave_distance, Color, Position);
max_amplitude += 1.73205080757 * octave_amplitude;
max_amplitude += max_distance * octave_amplitude;
float lerp_distance = Distance + octave_distance * octave_amplitude;
Distance = (1.0 - remainder) * Distance + remainder * lerp_distance;
Position /= octave_scale;
@ -1077,9 +1213,77 @@ shader node_voronoi_texture(
else if (feature == "smooth_f1") {
voronoi_smooth_f1_3d(
coord, smoothness, Exponent, randomness, metric, Distance, Color, Position);
float max_distance = voronoi_distance(vector3(1.0,1.0,1.0), vector3(0.0,0.0,0.0), metric, Exponent);
float max_amplitude = max_distance;
if(detail!=0.0&&roughness != 0.0 && Lacunarity != 0.0)
{
float octave_scale = Lacunarity;
float octave_amplitude = roughness;
float octave_distance = 0.0;
for(int i = 0; i < int(detail);++i)
{
voronoi_smooth_f1_3d(coord*octave_scale,smoothness, Exponent, randomness, metric, octave_distance, Color, Position);
max_amplitude += max_distance * octave_amplitude;
Distance += octave_distance * octave_amplitude;
octave_scale *= Lacunarity;
octave_amplitude *= roughness;
}
Position /= octave_scale / Lacunarity;
float remainder = detail - int(detail);
if (remainder != 0.0)
{
voronoi_smooth_f1_3d(coord*octave_scale,smoothness, Exponent, randomness, metric, octave_distance, Color, Position);
max_amplitude += max_distance * octave_amplitude;
float lerp_distance = Distance + octave_distance * octave_amplitude;
Distance = (1.0 - remainder) * Distance + remainder * lerp_distance;
Position /= octave_scale;
}
}
if (normalize) {
Distance /= max_amplitude;
}
}
else if (feature == "f2") {
voronoi_f2_3d(coord, Exponent, randomness, metric, Distance, Color, Position);
float max_distance = voronoi_distance(vector3(1.0,1.0,1.0), vector3(0.0,0.0,0.0), metric, Exponent);
float max_amplitude = max_distance;
if(detail!=0.0&&roughness != 0.0 && Lacunarity != 0.0)
{
float octave_scale = Lacunarity;
float octave_amplitude = roughness;
float octave_distance = 0.0;
for(int i = 0; i < int(detail);++i)
{
voronoi_f2_3d(coord*octave_scale, Exponent, randomness, metric, octave_distance, Color, Position);
max_amplitude += max_distance * octave_amplitude;
Distance += octave_distance * octave_amplitude;
octave_scale *= Lacunarity;
octave_amplitude *= roughness;
}
Position /= octave_scale / Lacunarity;
float remainder = detail - int(detail);
if (remainder != 0.0)
{
voronoi_f2_3d(coord*octave_scale, Exponent, randomness, metric, octave_distance, Color, Position);
max_amplitude += max_distance * octave_amplitude;
float lerp_distance = Distance + octave_distance * octave_amplitude;
Distance = (1.0 - remainder) * Distance + remainder * lerp_distance;
Position /= octave_scale;
}
}
if (normalize) {
Distance /= max_amplitude;
}
}
else if (feature == "distance_to_edge") {
voronoi_distance_to_edge_3d(coord, randomness, Distance);
@ -1098,7 +1302,8 @@ shader node_voronoi_texture(
if (feature == "f1") {
voronoi_f1_4d(coord4D, Exponent, randomness, metric, Distance, Color, outPosition4D);
float max_amplitude = 2.0;
float max_distance = voronoi_distance(vector4(1.0,1.0,1.0,1.0), vector4(0.0,0.0,0.0,0.0), metric, Exponent);
float max_amplitude = max_distance;
if(detail!=0.0&&roughness != 0.0 && Lacunarity != 0.0)
{
float octave_scale = Lacunarity;
@ -1109,7 +1314,7 @@ shader node_voronoi_texture(
{
voronoi_f1_4d(coord4D * octave_scale, Exponent, randomness, metric, octave_distance, Color, outPosition4D);
max_amplitude += 2.0 * octave_amplitude;
max_amplitude += max_distance * octave_amplitude;
Distance += octave_distance * octave_amplitude;
octave_scale *= Lacunarity;
octave_amplitude *= roughness;
@ -1121,7 +1326,7 @@ shader node_voronoi_texture(
if (remainder != 0.0)
{
voronoi_f1_4d(coord4D * octave_scale, Exponent, randomness, metric, octave_distance, Color, outPosition4D);
max_amplitude += 2.0 * octave_amplitude;
max_amplitude += max_distance * octave_amplitude;
float lerp_distance = Distance + octave_distance * octave_amplitude;
Distance = (1.0 - remainder) * Distance + remainder * lerp_distance;
outPosition4D /= octave_scale;
@ -1134,9 +1339,77 @@ shader node_voronoi_texture(
else if (feature == "smooth_f1") {
voronoi_smooth_f1_4d(
coord4D, smoothness, Exponent, randomness, metric, Distance, Color, outPosition4D);
float max_distance = voronoi_distance(vector4(1.0,1.0,1.0,1.0), vector4(0.0,0.0,0.0,0.0), metric, Exponent);
float max_amplitude = max_distance;
if(detail!=0.0&&roughness != 0.0 && Lacunarity != 0.0)
{
float octave_scale = Lacunarity;
float octave_amplitude = roughness;
float octave_distance = 0.0;
for(int i = 0; i < int(detail);++i)
{
voronoi_smooth_f1_4d(coord4D * octave_scale,smoothness, Exponent, randomness, metric, octave_distance, Color, outPosition4D);
max_amplitude += max_distance * octave_amplitude;
Distance += octave_distance * octave_amplitude;
octave_scale *= Lacunarity;
octave_amplitude *= roughness;
}
outPosition4D /= octave_scale / Lacunarity;
float remainder = detail - int(detail);
if (remainder != 0.0)
{
voronoi_smooth_f1_4d(coord4D * octave_scale, smoothness,Exponent, randomness, metric, octave_distance, Color, outPosition4D);
max_amplitude += max_distance * octave_amplitude;
float lerp_distance = Distance + octave_distance * octave_amplitude;
Distance = (1.0 - remainder) * Distance + remainder * lerp_distance;
outPosition4D /= octave_scale;
}
}
if (normalize) {
Distance /= max_amplitude;
}
}
else if (feature == "f2") {
voronoi_f2_4d(coord4D, Exponent, randomness, metric, Distance, Color, outPosition4D);
float max_distance = voronoi_distance(vector4(1.0,1.0,1.0,1.0), vector4(0.0,0.0,0.0,0.0), metric, Exponent);
float max_amplitude = max_distance;
if(detail!=0.0&&roughness != 0.0 && Lacunarity != 0.0)
{
float octave_scale = Lacunarity;
float octave_amplitude = roughness;
float octave_distance = 0.0;
for(int i = 0; i < int(detail);++i)
{
voronoi_f2_4d(coord4D * octave_scale, Exponent, randomness, metric, octave_distance, Color, outPosition4D);
max_amplitude += max_distance * octave_amplitude;
Distance += octave_distance * octave_amplitude;
octave_scale *= Lacunarity;
octave_amplitude *= roughness;
}
outPosition4D /= octave_scale / Lacunarity;
float remainder = detail - int(detail);
if (remainder != 0.0)
{
voronoi_f2_4d(coord4D * octave_scale, Exponent, randomness, metric, octave_distance, Color, outPosition4D);
max_amplitude += max_distance * octave_amplitude;
float lerp_distance = Distance + octave_distance * octave_amplitude;
Distance = (1.0 - remainder) * Distance + remainder * lerp_distance;
outPosition4D /= octave_scale;
}
}
if (normalize) {
Distance /= max_amplitude;
}
}
else if (feature == "distance_to_edge") {
voronoi_distance_to_edge_4d(coord4D, randomness, Distance);

View File

@ -974,10 +974,9 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
switch (dimensions) {
case 1: {
switch (voronoi_feature) {
case NODE_VORONOI_F1:
{
case NODE_VORONOI_F1: {
voronoi_f1_1d(
w, exponent, randomness, voronoi_metric, &distance_out, &color_out, &w_out);
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) {
@ -987,12 +986,12 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
for (int i = 0; i < int(detail); ++i) {
voronoi_f1_1d(w * octave_scale,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&w_out);
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&w_out);
max_amplitude += octave_amplitude;
distance_out += octave_distance * octave_amplitude;
octave_scale *= lacunarity;
@ -1004,12 +1003,12 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
float remainder = detail - int(detail);
if (remainder != 0.0f) {
voronoi_f1_1d(w * octave_scale,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&w_out);
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&w_out);
max_amplitude += octave_amplitude;
float lerp_distance = distance_out + octave_distance * octave_amplitude;
distance_out = (1.0f - remainder) * distance_out + remainder * lerp_distance;
@ -1022,7 +1021,7 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
break;
}
case NODE_VORONOI_SMOOTH_F1:
case NODE_VORONOI_SMOOTH_F1: {
voronoi_smooth_f1_1d(w,
smoothness,
exponent,
@ -1031,11 +1030,97 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
&distance_out,
&color_out,
&w_out);
float max_amplitude = 1.0f;
if (detail != 0.0f && roughness != 0.0f && lacunarity != 0.0f) {
float octave_scale = lacunarity;
float octave_amplitude = roughness;
float octave_distance = 0.0f;
for (int i = 0; i < int(detail); ++i) {
voronoi_smooth_f1_1d(w * octave_scale,
smoothness,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&w_out);
max_amplitude += octave_amplitude;
distance_out += octave_distance * octave_amplitude;
octave_scale *= lacunarity;
octave_amplitude *= roughness;
}
w_out /= octave_scale / lacunarity;
float remainder = detail - int(detail);
if (remainder != 0.0f) {
voronoi_smooth_f1_1d(w * octave_scale,
smoothness,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&w_out);
max_amplitude += octave_amplitude;
float lerp_distance = distance_out + octave_distance * octave_amplitude;
distance_out = (1.0f - remainder) * distance_out + remainder * lerp_distance;
w_out /= octave_scale;
}
}
if (normalize) {
distance_out /= max_amplitude;
}
break;
case NODE_VORONOI_F2:
}
case NODE_VORONOI_F2: {
voronoi_f2_1d(
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) {
float octave_scale = lacunarity;
float octave_amplitude = roughness;
float octave_distance = 0.0f;
for (int i = 0; i < int(detail); ++i) {
voronoi_f2_1d(w * octave_scale,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&w_out);
max_amplitude += octave_amplitude;
distance_out += octave_distance * octave_amplitude;
octave_scale *= lacunarity;
octave_amplitude *= roughness;
}
w_out /= octave_scale / lacunarity;
float remainder = detail - int(detail);
if (remainder != 0.0f) {
voronoi_f2_1d(w * octave_scale,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&w_out);
max_amplitude += octave_amplitude;
float lerp_distance = distance_out + octave_distance * octave_amplitude;
distance_out = (1.0f - remainder) * distance_out + remainder * lerp_distance;
w_out /= octave_scale;
}
}
if (normalize) {
distance_out /= max_amplitude;
}
break;
}
case NODE_VORONOI_DISTANCE_TO_EDGE:
voronoi_distance_to_edge_1d(w, randomness, &distance_out);
break;
@ -1060,7 +1145,9 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
&distance_out,
&color_out,
&position_out_2d);
float max_amplitude = 1.41421356237f; /* 1.41421356237f == sqrt(2) */
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) {
float octave_scale = lacunarity;
float octave_amplitude = roughness;
@ -1074,7 +1161,7 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
&octave_distance,
&color_out,
&position_out_2d);
max_amplitude += 1.41421356237f * octave_amplitude;
max_amplitude += max_distance * octave_amplitude;
distance_out += octave_distance * octave_amplitude;
octave_scale *= lacunarity;
octave_amplitude *= roughness;
@ -1091,7 +1178,7 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
&octave_distance,
&color_out,
&position_out_2d);
max_amplitude += 1.41421356237f * octave_amplitude;
max_amplitude += max_distance * octave_amplitude;
float lerp_distance = distance_out + octave_distance * octave_amplitude;
distance_out = (1.0f - remainder) * distance_out + remainder * lerp_distance;
position_out_2d /= octave_scale;
@ -1113,9 +1200,53 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
&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) {
float octave_scale = lacunarity;
float octave_amplitude = roughness;
float octave_distance = 0.0f;
for (int i = 0; i < int(detail); ++i) {
voronoi_smooth_f1_2d(coord_2d * octave_scale,
smoothness,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&position_out_2d);
max_amplitude += max_distance * octave_amplitude;
distance_out += octave_distance * octave_amplitude;
octave_scale *= lacunarity;
octave_amplitude *= roughness;
}
position_out_2d /= octave_scale / lacunarity;
float remainder = detail - int(detail);
if (remainder != 0.0f) {
voronoi_smooth_f1_2d(coord_2d * octave_scale,
smoothness,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&position_out_2d);
max_amplitude += max_distance * octave_amplitude;
float lerp_distance = distance_out + octave_distance * octave_amplitude;
distance_out = (1.0f - remainder) * distance_out + remainder * lerp_distance;
position_out_2d /= octave_scale;
}
}
if (normalize) {
distance_out /= max_amplitude;
}
}
break;
case NODE_VORONOI_F2:
case NODE_VORONOI_F2: {
voronoi_f2_2d(coord_2d,
exponent,
randomness,
@ -1123,7 +1254,50 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
&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) {
float octave_scale = lacunarity;
float octave_amplitude = roughness;
float octave_distance = 0.0f;
for (int i = 0; i < int(detail); ++i) {
voronoi_f2_2d(coord_2d * octave_scale,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&position_out_2d);
max_amplitude += max_distance * octave_amplitude;
distance_out += octave_distance * octave_amplitude;
octave_scale *= lacunarity;
octave_amplitude *= roughness;
}
position_out_2d /= octave_scale / lacunarity;
float remainder = detail - int(detail);
if (remainder != 0.0f) {
voronoi_f2_2d(coord_2d * octave_scale,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&position_out_2d);
max_amplitude += max_distance * octave_amplitude;
float lerp_distance = distance_out + octave_distance * octave_amplitude;
distance_out = (1.0f - remainder) * distance_out + remainder * lerp_distance;
position_out_2d /= octave_scale;
}
}
if (normalize) {
distance_out /= max_amplitude;
}
break;
}
case NODE_VORONOI_DISTANCE_TO_EDGE:
voronoi_distance_to_edge_2d(coord_2d, randomness, &distance_out);
break;
@ -1148,7 +1322,8 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
&color_out,
&position_out);
float max_amplitude = 1.73205080757f; /* 1.73205080757f == sqrt(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 = max_distance;
if (detail != 0.0f && roughness != 0.0f && lacunarity != 0.0f) {
float octave_scale = lacunarity;
float octave_amplitude = roughness;
@ -1162,7 +1337,7 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
&octave_distance,
&color_out,
&position_out);
max_amplitude += 1.73205080757f * octave_amplitude;
max_amplitude += max_distance * octave_amplitude;
distance_out += octave_distance * octave_amplitude;
octave_scale *= lacunarity;
octave_amplitude *= roughness;
@ -1179,7 +1354,7 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
&octave_distance,
&color_out,
&position_out);
max_amplitude += 1.73205080757f * octave_amplitude;
max_amplitude += max_distance * octave_amplitude;
float lerp_distance = distance_out + octave_distance * octave_amplitude;
distance_out = (1.0f - remainder) * distance_out + remainder * lerp_distance;
position_out /= octave_scale;
@ -1202,9 +1377,54 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
&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) {
float octave_scale = lacunarity;
float octave_amplitude = roughness;
float octave_distance = 0.0f;
for (int i = 0; i < int(detail); ++i) {
voronoi_smooth_f1_3d(coord * octave_scale,
smoothness,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&position_out);
max_amplitude += max_distance * octave_amplitude;
distance_out += octave_distance * octave_amplitude;
octave_scale *= lacunarity;
octave_amplitude *= roughness;
}
position_out /= octave_scale / lacunarity;
float remainder = detail - int(detail);
if (remainder != 0.0f) {
voronoi_smooth_f1_3d(coord * octave_scale,
smoothness,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&position_out);
max_amplitude += max_distance * octave_amplitude;
float lerp_distance = distance_out + octave_distance * octave_amplitude;
distance_out = (1.0f - remainder) * distance_out + remainder * lerp_distance;
position_out /= octave_scale;
}
}
if (normalize) {
distance_out /= max_amplitude;
}
}
break;
case NODE_VORONOI_F2:
case NODE_VORONOI_F2: {
voronoi_f2_3d(coord,
exponent,
randomness,
@ -1212,7 +1432,51 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
&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) {
float octave_scale = lacunarity;
float octave_amplitude = roughness;
float octave_distance = 0.0f;
for (int i = 0; i < int(detail); ++i) {
voronoi_f2_3d(coord * octave_scale,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&position_out);
max_amplitude += max_distance * octave_amplitude;
distance_out += octave_distance * octave_amplitude;
octave_scale *= lacunarity;
octave_amplitude *= roughness;
}
position_out /= octave_scale / lacunarity;
float remainder = detail - int(detail);
if (remainder != 0.0f) {
voronoi_f2_3d(coord * octave_scale,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&position_out);
max_amplitude += max_distance * octave_amplitude;
float lerp_distance = distance_out + octave_distance * octave_amplitude;
distance_out = (1.0f - remainder) * distance_out + remainder * lerp_distance;
position_out /= octave_scale;
}
}
if (normalize) {
distance_out /= max_amplitude;
}
break;
}
case NODE_VORONOI_DISTANCE_TO_EDGE:
voronoi_distance_to_edge_3d(coord, randomness, &distance_out);
break;
@ -1232,16 +1496,17 @@ 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;
switch (voronoi_feature) {
case NODE_VORONOI_F1:
{
case NODE_VORONOI_F1: {
voronoi_f1_4d(coord_4d,
exponent,
randomness,
voronoi_metric,
&distance_out,
&color_out,
&position_out_4d);
float max_amplitude = 2.0f;
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) {
float octave_scale = lacunarity;
float octave_amplitude = roughness;
@ -1249,13 +1514,13 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
for (int i = 0; i < int(detail); ++i) {
voronoi_f1_4d(coord_4d * octave_scale,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&position_out_4d);
max_amplitude += 2.0f * octave_amplitude;
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&position_out_4d);
max_amplitude += max_distance * octave_amplitude;
distance_out += octave_distance * octave_amplitude;
octave_scale *= lacunarity;
octave_amplitude *= roughness;
@ -1266,13 +1531,13 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
float remainder = detail - int(detail);
if (remainder != 0.0f) {
voronoi_f1_4d(coord_4d * octave_scale,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&position_out_4d);
max_amplitude += 2.0f * octave_amplitude;
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&position_out_4d);
max_amplitude += max_distance * octave_amplitude;
float lerp_distance = distance_out + octave_distance * octave_amplitude;
distance_out = (1.0f - remainder) * distance_out + remainder * lerp_distance;
position_out_4d /= octave_scale;
@ -1281,8 +1546,9 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
if (normalize) {
distance_out /= max_amplitude;
}
break; }
case NODE_VORONOI_SMOOTH_F1:
break;
}
case NODE_VORONOI_SMOOTH_F1: {
voronoi_smooth_f1_4d(coord_4d,
smoothness,
exponent,
@ -1291,8 +1557,53 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
&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) {
float octave_scale = lacunarity;
float octave_amplitude = roughness;
float octave_distance = 0.0f;
for (int i = 0; i < int(detail); ++i) {
voronoi_smooth_f1_4d(coord_4d * octave_scale,
smoothness,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&position_out_4d);
max_amplitude += max_distance * octave_amplitude;
distance_out += octave_distance * octave_amplitude;
octave_scale *= lacunarity;
octave_amplitude *= roughness;
}
position_out_4d /= octave_scale / lacunarity;
float remainder = detail - int(detail);
if (remainder != 0.0f) {
voronoi_smooth_f1_4d(coord_4d * octave_scale,
smoothness,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&position_out_4d);
max_amplitude += max_distance * octave_amplitude;
float lerp_distance = distance_out + octave_distance * octave_amplitude;
distance_out = (1.0f - remainder) * distance_out + remainder * lerp_distance;
position_out_4d /= octave_scale;
}
}
if (normalize) {
distance_out /= max_amplitude;
}
break;
case NODE_VORONOI_F2:
}
case NODE_VORONOI_F2: {
voronoi_f2_4d(coord_4d,
exponent,
randomness,
@ -1300,7 +1611,50 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
&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) {
float octave_scale = lacunarity;
float octave_amplitude = roughness;
float octave_distance = 0.0f;
for (int i = 0; i < int(detail); ++i) {
voronoi_f2_4d(coord_4d * octave_scale,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&position_out_4d);
max_amplitude += max_distance * octave_amplitude;
distance_out += octave_distance * octave_amplitude;
octave_scale *= lacunarity;
octave_amplitude *= roughness;
}
position_out_4d /= octave_scale / lacunarity;
float remainder = detail - int(detail);
if (remainder != 0.0f) {
voronoi_f2_4d(coord_4d * octave_scale,
exponent,
randomness,
voronoi_metric,
&octave_distance,
&color_out,
&position_out_4d);
max_amplitude += max_distance * octave_amplitude;
float lerp_distance = distance_out + octave_distance * octave_amplitude;
distance_out = (1.0f - remainder) * distance_out + remainder * lerp_distance;
position_out_4d /= octave_scale;
}
}
if (normalize) {
distance_out /= max_amplitude;
}
break;
}
case NODE_VORONOI_DISTANCE_TO_EDGE:
voronoi_distance_to_edge_4d(coord_4d, randomness, &distance_out);
break;

File diff suppressed because it is too large Load Diff