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
3 changed files with 18 additions and 18 deletions
Showing only changes of commit 2a0b9c8633 - Show all commits

View File

@ -97,7 +97,7 @@ VoronoiOutput fractal_voronoi_x_fx(VoronoiParams params, float coord)
float fractal_voronoi_distance_to_edge(VoronoiParams params, float coord) float fractal_voronoi_distance_to_edge(VoronoiParams params, float coord)
{ {
float amplitude = 1.0; float amplitude = 1.0;
float max_amplitude = 2.0 - params.randomness; float max_amplitude = 1.5 - 0.5 * params.randomness;
float scale = 1.0; float scale = 1.0;
float distance = 8.0; float distance = 8.0;
@ -111,7 +111,7 @@ float fractal_voronoi_distance_to_edge(VoronoiParams params, float coord)
break; break;
} }
else if (i <= params.detail) { else if (i <= params.detail) {
max_amplitude = mix(max_amplitude, (2.0 - params.randomness) * scale, amplitude); max_amplitude = mix(max_amplitude, (1.5 - 0.5 * params.randomness) * scale, amplitude);
distance = mix(distance, min(distance, octave_distance / scale), amplitude); distance = mix(distance, min(distance, octave_distance / scale), amplitude);
scale *= params.lacunarity; scale *= params.lacunarity;
amplitude *= params.roughness; amplitude *= params.roughness;
@ -119,7 +119,7 @@ float fractal_voronoi_distance_to_edge(VoronoiParams params, float coord)
else { else {
float remainder = params.detail - floor(params.detail); float remainder = params.detail - floor(params.detail);
if (remainder != 0.0) { if (remainder != 0.0) {
float lerp_amplitude = mix(max_amplitude, (2.0 - params.randomness) * scale, amplitude); float lerp_amplitude = mix(max_amplitude, (1.5 - 0.5 * params.randomness) * scale, amplitude);
max_amplitude = mix(max_amplitude, lerp_amplitude, remainder); max_amplitude = mix(max_amplitude, lerp_amplitude, remainder);
float lerp_distance = mix(distance, min(distance, octave_distance / scale), amplitude); float lerp_distance = mix(distance, min(distance, octave_distance / scale), amplitude);
distance = mix(distance, min(distance, lerp_distance), remainder); distance = mix(distance, min(distance, lerp_distance), remainder);
@ -204,7 +204,7 @@ VoronoiOutput fractal_voronoi_x_fx(VoronoiParams params, vector2 coord)
float fractal_voronoi_distance_to_edge(VoronoiParams params, vector2 coord) float fractal_voronoi_distance_to_edge(VoronoiParams params, vector2 coord)
{ {
float amplitude = 1.0; float amplitude = 1.0;
float max_amplitude = 2.0 - params.randomness; float max_amplitude = 1.5 - 0.5 * params.randomness;
float scale = 1.0; float scale = 1.0;
float distance = 8.0; float distance = 8.0;
@ -218,7 +218,7 @@ float fractal_voronoi_distance_to_edge(VoronoiParams params, vector2 coord)
break; break;
} }
else if (i <= params.detail) { else if (i <= params.detail) {
max_amplitude = mix(max_amplitude, (2.0 - params.randomness) * scale, amplitude); max_amplitude = mix(max_amplitude, (1.5 - 0.5 * params.randomness) * scale, amplitude);
distance = mix(distance, min(distance, octave_distance / scale), amplitude); distance = mix(distance, min(distance, octave_distance / scale), amplitude);
scale *= params.lacunarity; scale *= params.lacunarity;
amplitude *= params.roughness; amplitude *= params.roughness;
@ -226,7 +226,7 @@ float fractal_voronoi_distance_to_edge(VoronoiParams params, vector2 coord)
else { else {
float remainder = params.detail - floor(params.detail); float remainder = params.detail - floor(params.detail);
if (remainder != 0.0) { if (remainder != 0.0) {
float lerp_amplitude = mix(max_amplitude, (2.0 - params.randomness) * scale, amplitude); float lerp_amplitude = mix(max_amplitude, (1.5 - 0.5 * params.randomness) * scale, amplitude);
max_amplitude = mix(max_amplitude, lerp_amplitude, remainder); max_amplitude = mix(max_amplitude, lerp_amplitude, remainder);
float lerp_distance = mix(distance, min(distance, octave_distance / scale), amplitude); float lerp_distance = mix(distance, min(distance, octave_distance / scale), amplitude);
distance = mix(distance, min(distance, lerp_distance), remainder); distance = mix(distance, min(distance, lerp_distance), remainder);
@ -311,7 +311,7 @@ VoronoiOutput fractal_voronoi_x_fx(VoronoiParams params, vector3 coord)
float fractal_voronoi_distance_to_edge(VoronoiParams params, vector3 coord) float fractal_voronoi_distance_to_edge(VoronoiParams params, vector3 coord)
{ {
float amplitude = 1.0; float amplitude = 1.0;
float max_amplitude = 2.0 - params.randomness; float max_amplitude = 1.5 - 0.5 * params.randomness;
float scale = 1.0; float scale = 1.0;
float distance = 8.0; float distance = 8.0;
@ -325,7 +325,7 @@ float fractal_voronoi_distance_to_edge(VoronoiParams params, vector3 coord)
break; break;
} }
else if (i <= params.detail) { else if (i <= params.detail) {
max_amplitude = mix(max_amplitude, (2.0 - params.randomness) * scale, amplitude); max_amplitude = mix(max_amplitude, (1.5 - 0.5 * params.randomness) * scale, amplitude);
distance = mix(distance, min(distance, octave_distance / scale), amplitude); distance = mix(distance, min(distance, octave_distance / scale), amplitude);
scale *= params.lacunarity; scale *= params.lacunarity;
amplitude *= params.roughness; amplitude *= params.roughness;
@ -333,7 +333,7 @@ float fractal_voronoi_distance_to_edge(VoronoiParams params, vector3 coord)
else { else {
float remainder = params.detail - floor(params.detail); float remainder = params.detail - floor(params.detail);
if (remainder != 0.0) { if (remainder != 0.0) {
float lerp_amplitude = mix(max_amplitude, (2.0 - params.randomness) * scale, amplitude); float lerp_amplitude = mix(max_amplitude, (1.5 - 0.5 * params.randomness) * scale, amplitude);
max_amplitude = mix(max_amplitude, lerp_amplitude, remainder); max_amplitude = mix(max_amplitude, lerp_amplitude, remainder);
float lerp_distance = mix(distance, min(distance, octave_distance / scale), amplitude); float lerp_distance = mix(distance, min(distance, octave_distance / scale), amplitude);
distance = mix(distance, min(distance, lerp_distance), remainder); distance = mix(distance, min(distance, lerp_distance), remainder);
@ -418,7 +418,7 @@ VoronoiOutput fractal_voronoi_x_fx(VoronoiParams params, vector4 coord)
float fractal_voronoi_distance_to_edge(VoronoiParams params, vector4 coord) float fractal_voronoi_distance_to_edge(VoronoiParams params, vector4 coord)
{ {
float amplitude = 1.0; float amplitude = 1.0;
float max_amplitude = 2.0 - params.randomness; float max_amplitude = 1.5 - 0.5 * params.randomness;
float scale = 1.0; float scale = 1.0;
float distance = 8.0; float distance = 8.0;
@ -432,7 +432,7 @@ float fractal_voronoi_distance_to_edge(VoronoiParams params, vector4 coord)
break; break;
} }
else if (i <= params.detail) { else if (i <= params.detail) {
max_amplitude = mix(max_amplitude, (2.0 - params.randomness) * scale, amplitude); max_amplitude = mix(max_amplitude, (1.5 - 0.5 * params.randomness) * scale, amplitude);
distance = mix(distance, min(distance, octave_distance / scale), amplitude); distance = mix(distance, min(distance, octave_distance / scale), amplitude);
scale *= params.lacunarity; scale *= params.lacunarity;
amplitude *= params.roughness; amplitude *= params.roughness;
@ -440,7 +440,7 @@ float fractal_voronoi_distance_to_edge(VoronoiParams params, vector4 coord)
else { else {
float remainder = params.detail - floor(params.detail); float remainder = params.detail - floor(params.detail);
if (remainder != 0.0) { if (remainder != 0.0) {
float lerp_amplitude = mix(max_amplitude, (2.0 - params.randomness) * scale, amplitude); float lerp_amplitude = mix(max_amplitude, (1.5 - 0.5 * params.randomness) * scale, amplitude);
max_amplitude = mix(max_amplitude, lerp_amplitude, remainder); max_amplitude = mix(max_amplitude, lerp_amplitude, remainder);
float lerp_distance = mix(distance, min(distance, octave_distance / scale), amplitude); float lerp_distance = mix(distance, min(distance, octave_distance / scale), amplitude);
distance = mix(distance, min(distance, lerp_distance), remainder); distance = mix(distance, min(distance, lerp_distance), remainder);

View File

@ -936,7 +936,7 @@ template<typename T>
ccl_device float fractal_voronoi_distance_to_edge(const VoronoiParams &params, const T coord) ccl_device float fractal_voronoi_distance_to_edge(const VoronoiParams &params, const T coord)
{ {
float amplitude = 1.0f; float amplitude = 1.0f;
float max_amplitude = 2.0f - params.randomness; float max_amplitude = 1.5f - 0.5f * params.randomness;
float scale = 1.0f; float scale = 1.0f;
float distance = 8.0f; float distance = 8.0f;
@ -950,7 +950,7 @@ ccl_device float fractal_voronoi_distance_to_edge(const VoronoiParams &params, c
break; break;
} }
else if (i <= params.detail) { else if (i <= params.detail) {
max_amplitude = lerp(max_amplitude, (2.0f - params.randomness) * scale, amplitude); max_amplitude = lerp(max_amplitude, (1.5f - 0.5f * params.randomness) * scale, amplitude);
distance = lerp(distance, min(distance, octave_distance / scale), amplitude); distance = lerp(distance, min(distance, octave_distance / scale), amplitude);
scale *= params.lacunarity; scale *= params.lacunarity;
amplitude *= params.roughness; amplitude *= params.roughness;
@ -958,7 +958,7 @@ ccl_device float fractal_voronoi_distance_to_edge(const VoronoiParams &params, c
else { else {
float remainder = params.detail - floorf(params.detail); float remainder = params.detail - floorf(params.detail);
if (remainder != 0.0f) { if (remainder != 0.0f) {
float lerp_amplitude = lerp(max_amplitude, (2.0f - params.randomness) * scale, amplitude); float lerp_amplitude = lerp(max_amplitude, (1.5f - 0.5f * params.randomness) * scale, amplitude);
max_amplitude = lerp(max_amplitude, lerp_amplitude, remainder); max_amplitude = lerp(max_amplitude, lerp_amplitude, remainder);
float lerp_distance = lerp(distance, min(distance, octave_distance / scale), amplitude); float lerp_distance = lerp(distance, min(distance, octave_distance / scale), amplitude);
distance = lerp(distance, min(distance, lerp_distance), remainder); distance = lerp(distance, min(distance, lerp_distance), remainder);

View File

@ -2310,7 +2310,7 @@ template<typename T>
float fractal_voronoi_distance_to_edge(const VoronoiParams &params, const T coord) float fractal_voronoi_distance_to_edge(const VoronoiParams &params, const T coord)
{ {
float amplitude = 1.0f; float amplitude = 1.0f;
float max_amplitude = 2.0f - params.randomness; float max_amplitude = 1.5f - 0.5f * params.randomness;
float scale = 1.0f; float scale = 1.0f;
float distance = 8.0f; float distance = 8.0f;
@ -2324,7 +2324,7 @@ float fractal_voronoi_distance_to_edge(const VoronoiParams &params, const T coor
break; break;
} }
else if (i <= params.detail) { else if (i <= params.detail) {
max_amplitude = lerp(max_amplitude, (2.0f - params.randomness) * scale, amplitude); max_amplitude = lerp(max_amplitude, (1.5f - 0.5f * params.randomness) * scale, amplitude);
distance = lerp(distance, math::min(distance, octave_distance / scale), amplitude); distance = lerp(distance, math::min(distance, octave_distance / scale), amplitude);
scale *= params.lacunarity; scale *= params.lacunarity;
amplitude *= params.roughness; amplitude *= params.roughness;
@ -2332,7 +2332,7 @@ float fractal_voronoi_distance_to_edge(const VoronoiParams &params, const T coor
else { else {
float remainder = params.detail - floorf(params.detail); float remainder = params.detail - floorf(params.detail);
if (remainder != 0.0f) { if (remainder != 0.0f) {
float lerp_amplitude = lerp(max_amplitude, (2.0f - params.randomness) * scale, amplitude); float lerp_amplitude = lerp(max_amplitude, (1.5f - 0.5f * params.randomness) * scale, amplitude);
max_amplitude = lerp(max_amplitude, lerp_amplitude, remainder); max_amplitude = lerp(max_amplitude, lerp_amplitude, remainder);
float lerp_distance = lerp( float lerp_distance = lerp(
distance, math::min(distance, octave_distance / scale), amplitude); distance, math::min(distance, octave_distance / scale), amplitude);