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
2 changed files with 187 additions and 436 deletions
Showing only changes of commit 966e44d892 - Show all commits

View File

@ -1,4 +1,4 @@
"C:\Users\nucle\Desktop\General_Custom_Files\AUTO_GIT_COMMIT.exe" %cd% "\##AUTO_GIT_COMMIT.cmd" "C:\Users\nucle\Desktop\General_Custom_Files\AUTO_GIT_COMMIT.exe" %cd% "\##AUTO_GIT_COMMIT.cmd"
git add * git add *
git commit -m "AUTO_GIT_COMMIT commit message number: 4" git commit -m "AUTO_GIT_COMMIT commit message number: 5"

View File

@ -2,7 +2,22 @@
* Copyright 2011-2022 Blender Foundation */ * Copyright 2011-2022 Blender Foundation */
#pragma once #pragma once
#include "device/device.h"
#include "scene/background.h"
#include "scene/light.h"
#include "scene/mesh.h"
#include "scene/scene.h"
#include "scene/shader.h"
#include "scene/shader_graph.h"
#include "scene/shader_nodes.h"
#include "scene/stats.h"
#include "scene/svm.h"
#include "util/foreach.h"
#include "util/log.h"
#include "util/progress.h"
#include "util/task.h"
CCL_NAMESPACE_BEGIN CCL_NAMESPACE_BEGIN
/* /*
@ -950,21 +965,23 @@ ccl_device void fractal_voronoi_x_fx(VoronoiParams<T> &vp,
template<typename T> template<typename T>
ccl_device void fractal_voronoi_distance_to_edge(VoronoiParams<T> &vp, VoronoiOutput<T> &vo) ccl_device void fractal_voronoi_distance_to_edge(VoronoiParams<T> &vp, VoronoiOutput<T> &vo)
{ {
float octave_scale = 1.0f; vp.octave_scale = 1.0f;
float octave_amplitude = 1.0f; vp.octave_amplitude = 1.0f;
float octave_distance = 0.0f;
vp.max_amplitude = 2.0f - vp.randomness;
vp.octave_distance = 8.0f; vp.octave_distance = 8.0f;
for (int i = 0; i <= ceilf(detail); ++i) { bool zeroinput = vp.detail == 0.0f || vp.roughness == 0.0f || vp.lacunarity == 0.0f;
voronoi_distance_to_edge(coord * octave_scale, vp.randomness, &octave_distance);
if (detail == 0.0f || roughness == 0.0f || lacunarity == 0.0f) { T voronoi_coord = vp.octave_coord;
vp.octave_distance = octave_distance; vp.max_amplitude = 2.0f - vp.randomness;
return; for (int i = 0; i <= ceilf(vp.detail); ++i) {
vp.octave_coord = voronoi_coord * vp.octave_scale;
voronoi_distance_to_edge(vp);
if (zeroinput) {
vo.distance_out = vp.octave_distance;
break;
} }
else if (i <= detail) { else if (i <= detail) {
vp.max_amplitude = lerp( vp.max_amplitude = lerp(
vp.max_amplitude, (2.0f - vp.randomness) * octave_scale, octave_amplitude); vp.max_amplitude, (2.0f - vp.randomness) * vp.octave_scale, vp.octave_amplitude);
vp.octave_distance = lerp(vp.octave_distance, vp.octave_distance = lerp(vp.octave_distance,
min(vp.octave_distance, octave_distance / octave_scale), min(vp.octave_distance, octave_distance / octave_scale),
octave_amplitude); octave_amplitude);
@ -1052,10 +1069,10 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
VoronoiOutputBase vob; VoronoiOutputBase vob;
vob.distance_out = 0.0f; vob.distance_out = 0.0f;
float voronoi_w_out = 0.0f;
vob.radius_out = 0.0f; vob.radius_out = 0.0f;
vob.color_out = make_float3(0.0f, 0.0f, 0.0f); vob.color_out = make_float3(0.0f, 0.0f, 0.0f);
float3 voronoi_position_out = make_float3(0.0f, 0.0f, 0.0f); float3 voronoi_position_out = make_float3(0.0f, 0.0f, 0.0f);
float voronoi_w_out = 0.0f;
vpb.detail = clamp(vpb.detail, 0.0f, 15.0f); vpb.detail = clamp(vpb.detail, 0.0f, 15.0f);
vpb.roughness = clamp(vpb.roughness, 0.0f, 1.0f); vpb.roughness = clamp(vpb.roughness, 0.0f, 1.0f);
@ -1065,433 +1082,167 @@ ccl_device_noinline int svm_node_tex_voronoi(KernelGlobals kg,
voronoi_coord *= vpb.scale; voronoi_coord *= vpb.scale;
voronoi_w *= vpb.scale; voronoi_w *= vpb.scale;
VoronoiParams<float3> vp{vpb}; switch (dimensions) {
vp.octave_coord = voronoi_coord; case 1: {
vp.max_distance = voronoi_distance_3d(zero_float3(), one_float3(), vp.metric, vp.exponent); VoronoiParams<float> vp{vpb};
VoronoiOutput<float3> vo{vob}; vp.octave_coord = voronoi_w;
vo.position_out = zero_float3(); vp.max_distance = 1.0f;
fractal_voronoi_x_fx<float3>(vp, vo, voronoi_f1_3d); VoronoiOutput<float> vo{vob};
vob = vo; vo.position_out = 0.0f;
voronoi_position_out = vo.position_out;
voronoi_w_out = 0.0f;
// switch (dimensions) { switch (vpb.feature) {
// case 1: { case NODE_VORONOI_F1: {
// switch (voronoi_feature) { fractal_voronoi_x_fx<float>(vp, vo, voronoi_f1_1d);
// case NODE_VORONOI_F1: { break;
// fractal_voronoi_f1<float>(w, }
// detail, case NODE_VORONOI_SMOOTH_F1: {
// roughness, fractal_voronoi_x_fx<float>(vp, vo, voronoi_smooth_f1_1d);
// lacunarity, break;
// vp.exponent, }
// vp.randomness, case NODE_VORONOI_F2: {
// voronoi_metric, fractal_voronoi_x_fx<float>(vp, vo, voronoi_f2_1d);
// &max_amplitude, break;
// &distance_out, }
// &color_out, case NODE_VORONOI_DISTANCE_TO_EDGE: {
// &w_out); fractal_voronoi_distance_to_edge<float>(vp, vo);
// if (normalize) { break;
// distance_out /= (0.5f + 0.5f * vp.randomness) * max_amplitude; }
// color_out /= max_amplitude; case NODE_VORONOI_N_SPHERE_RADIUS:
// } voronoi_n_sphere_radius_1d(vp, vo);
// break; break;
// } default:
// case NODE_VORONOI_SMOOTH_F1: { kernel_assert(0);
// fractal_voronoi_smooth_f1<float>(w, }
// detail, vo.position_out = safe_divide(vo.position_out, vpb.scale);
// roughness,
// lacunarity,
// vp.smoothness,
// vp.exponent,
// vp.randomness,
// voronoi_metric,
// &max_amplitude,
// &distance_out,
// &color_out,
// &w_out);
// if (normalize) {
// distance_out /= (0.5f + 0.5f * vp.randomness) * max_amplitude;
// color_out /= max_amplitude;
// }
// break;
// }
// case NODE_VORONOI_F2: {
// fractal_voronoi_f2<float>(w,
// detail,
// roughness,
// lacunarity,
// vp.exponent,
// vp.randomness,
// voronoi_metric,
// &max_amplitude,
// &distance_out,
// &color_out,
// &w_out);
// if (normalize) {
// if (detail == 0.0f || roughness == 0.0f || lacunarity == 0.0f) {
// distance_out /= (1.0f - vp.randomness) + vp.randomness * max_amplitude;
// }
// else {
// distance_out /= (1.0f - vp.randomness) * ceilf(detail + 1.0f) +
// vp.randomness * max_amplitude;
// }
// color_out /= max_amplitude;
// }
// break;
// }
// case NODE_VORONOI_DISTANCE_TO_EDGE: {
// fractal_voronoi_distance_to_edge<float>(
// w, detail, roughness, lacunarity, vp.randomness, &max_amplitude, &distance_out);
// if (normalize) {
// /* max_amplitude is used here to keep the code consistent, however it has a
// different
// * meaning than in F1, Smooth F1 and F2. Instead of the highest possible amplitude,
// it
// * represents an abstract factor needed to cancel out the amplitude attenuation
// caused
// * by the higher layers. */
// distance_out *= max_amplitude;
// }
// break;
// }
// case NODE_VORONOI_N_SPHERE_RADIUS:
// voronoi_n_sphere_radius_1d(w, vp.randomness, &radius_out);
// break;
// default:
// kernel_assert(0);
// }
// w_out = safe_divide(w_out, scale);
// break;
// }
// case 2: {
// float2 coord_2d = make_float2(coord.x, coord.y);
// float2 position_out_2d = zero_float2();
// switch (voronoi_feature) { vob = vo;
// case NODE_VORONOI_F1: { voronoi_w = vo.position_out;
// fractal_voronoi_f1<float2>(coord_2d, break;
// detail, }
// roughness, case 2: {
// lacunarity, VoronoiParams<float2> vp{vpb};
// vp.exponent, vp.octave_coord = make_float2(voronoi_coord.x, voronoi_coord.y);
// vp.randomness, vp.max_distance = voronoi_distance_2d(zero_float2(), one_float2(), vp.metric, vp.exponent);
// voronoi_metric, VoronoiOutput<float2> vo{vob};
// &max_amplitude, vo.position_out = zero_float2();
// &distance_out,
// &color_out,
// &position_out_2d);
// if (normalize) {
// distance_out /= (0.5f + 0.5f * vp.randomness) * max_amplitude *
// voronoi_distance_2d(make_float2(1.0f, 1.0f),
// make_float2(0.0f, 0.0f),
// voronoi_metric,
// vp.exponent);
// color_out /= max_amplitude;
// }
// break;
// }
// case NODE_VORONOI_SMOOTH_F1:
// IF_KERNEL_NODES_FEATURE(VORONOI_EXTRA)
// {
// fractal_voronoi_smooth_f1<float2>(coord_2d,
// detail,
// roughness,
// lacunarity,
// vp.smoothness,
// vp.exponent,
// vp.randomness,
// voronoi_metric,
// &max_amplitude,
// &distance_out,
// &color_out,
// &position_out_2d);
// if (normalize) {
// distance_out /= (0.5f + 0.5f * vp.randomness) * max_amplitude *
// voronoi_distance_2d(make_float2(1.0f, 1.0f),
// make_float2(0.0f, 0.0f),
// voronoi_metric,
// vp.exponent);
// color_out /= max_amplitude;
// }
// break;
// }
// break;
// case NODE_VORONOI_F2: {
// fractal_voronoi_f2<float2>(coord_2d,
// detail,
// roughness,
// lacunarity,
// vp.exponent,
// vp.randomness,
// voronoi_metric,
// &max_amplitude,
// &distance_out,
// &color_out,
// &position_out_2d);
// if (normalize) {
// if (detail == 0.0f || roughness == 0.0f || lacunarity == 0.0f) {
// distance_out /= (1.0f - vp.randomness) +
// vp.randomness * max_amplitude *
// voronoi_distance_2d(make_float2(1.0f, 1.0f),
// make_float2(0.0f, 0.0f),
// voronoi_metric,
// vp.exponent);
// }
// else {
// distance_out /= (1.0f - vp.randomness) * ceilf(detail + 1.0f) +
// vp.randomness * max_amplitude *
// voronoi_distance_2d(make_float2(1.0f, 1.0f),
// make_float2(0.0f, 0.0f),
// voronoi_metric,
// vp.exponent);
// }
// color_out /= max_amplitude;
// }
// break;
// }
// case NODE_VORONOI_DISTANCE_TO_EDGE: {
// fractal_voronoi_distance_to_edge<float2>(
// coord_2d, detail, roughness, lacunarity, vp.randomness, &max_amplitude,
// &distance_out);
// if (normalize) {
// /* max_amplitude is used here to keep the code consistent, however it has a different
// * meaning than in F1, Smooth F1 and F2. Instead of the highest possible amplitude,
// it
// * represents an abstract factor needed to cancel out the amplitude attenuation
// caused
// * by the higher layers. */
// distance_out *= max_amplitude;
// }
// break;
// }
// case NODE_VORONOI_N_SPHERE_RADIUS:
// voronoi_n_sphere_radius_2d(coord_2d, vp.randomness, &radius_out);
// break;
// default:
// kernel_assert(0);
// }
// position_out_2d = safe_divide_float2_float(position_out_2d, scale);
// position_out = make_float3(position_out_2d.x, position_out_2d.y, 0.0f);
// break;
// }
// case 3: {
// switch (voronoi_feature) {
// case NODE_VORONOI_F1: {
// if (normalize) {
// distance_out /= (0.5f + 0.5f * vp.randomness) * max_amplitude *
// voronoi_distance_3d(make_float3(1.0f, 1.0f, 1.0f),
// make_float3(0.0f, 0.0f, 0.0f),
// voronoi_metric,
// vp.exponent);
// color_out /= max_amplitude;
// }
// break;
// }
// case NODE_VORONOI_SMOOTH_F1:
// IF_KERNEL_NODES_FEATURE(VORONOI_EXTRA)
// {
// fractal_voronoi_smooth_f1<float3>(coord,
// detail,
// roughness,
// lacunarity,
// vp.smoothness,
// vp.exponent,
// vp.randomness,
// voronoi_metric,
// &max_amplitude,
// &distance_out,
// &color_out,
// &position_out);
// if (normalize) {
// distance_out /= (0.5f + 0.5f * vp.randomness) * max_amplitude *
// voronoi_distance_3d(make_float3(1.0f, 1.0f, 1.0f),
// make_float3(0.0f, 0.0f, 0.0f),
// voronoi_metric,
// vp.exponent);
// color_out /= max_amplitude;
// }
// break;
// }
// break;
// case NODE_VORONOI_F2: {
// fractal_voronoi_f2<float3>(coord,
// detail,
// roughness,
// lacunarity,
// vp.exponent,
// vp.randomness,
// voronoi_metric,
// &max_amplitude,
// &distance_out,
// &color_out,
// &position_out);
// if (normalize) {
// if (detail == 0.0f || roughness == 0.0f || lacunarity == 0.0f) {
// distance_out /= (1.0f - vp.randomness) +
// vp.randomness * max_amplitude *
// voronoi_distance_3d(make_float3(1.0f, 1.0f, 1.0f),
// make_float3(0.0f, 0.0f, 0.0f),
// voronoi_metric,
// vp.exponent);
// }
// else {
// distance_out /= (1.0f - vp.randomness) * ceilf(detail + 1.0f) +
// vp.randomness * max_amplitude *
// voronoi_distance_3d(make_float3(1.0f, 1.0f, 1.0f),
// make_float3(0.0f, 0.0f, 0.0f),
// voronoi_metric,
// vp.exponent);
// }
// color_out /= max_amplitude;
// }
// break;
// }
// case NODE_VORONOI_DISTANCE_TO_EDGE: {
// fractal_voronoi_distance_to_edge<float3>(
// coord, detail, roughness, lacunarity, vp.randomness, &max_amplitude,
// &distance_out);
// if (normalize) {
// /* max_amplitude is used here to keep the code consistent, however it has a
// different
// * meaning than in F1, Smooth F1 and F2. Instead of the highest possible amplitude,
// it
// * represents an abstract factor needed to cancel out the amplitude attenuation
// caused
// * by the higher layers. */
// distance_out *= max_amplitude;
// }
// break;
// }
// case NODE_VORONOI_N_SPHERE_RADIUS:
// voronoi_n_sphere_radius_3d(coord, vp.randomness, &radius_out);
// break;
// default:
// kernel_assert(0);
// }
// position_out = safe_divide(position_out, scale);
// break;
// }
// case 4: { switch (vpb.feature) {
// IF_KERNEL_NODES_FEATURE(VORONOI_EXTRA) case NODE_VORONOI_F1: {
// { fractal_voronoi_x_fx<float2>(vp, vo, voronoi_f1_2d);
// float4 coord_4d = make_float4(coord.x, coord.y, coord.z, w); break;
// float4 position_out_4d; }
case NODE_VORONOI_SMOOTH_F1:
IF_KERNEL_NODES_FEATURE(VORONOI_EXTRA)
{
fractal_voronoi_x_fx<float2>(vp, vo, voronoi_smooth_f1_2d);
break;
}
break;
case NODE_VORONOI_F2: {
fractal_voronoi_x_fx<float2>(vp, vo, voronoi_f2_2d);
break;
}
case NODE_VORONOI_DISTANCE_TO_EDGE: {
fractal_voronoi_distance_to_edge<float2>(vp, vo);
break;
}
case NODE_VORONOI_N_SPHERE_RADIUS:
voronoi_n_sphere_radius_2d(vp, vo);
break;
default:
kernel_assert(0);
}
vo.position_out = safe_divide_float2_float(vo.position_out, vpb.scale);
// switch (voronoi_feature) { vob = vo;
// case NODE_VORONOI_F1: { voronoi_position_out = make_float3(vo.position_out.x, vo.position_out.y, 0.0f);
// fractal_voronoi_f1<float4>(coord_4d, break;
// detail, }
// roughness, case 3: {
// lacunarity, VoronoiParams<float3> vp{vpb};
// vp.exponent, vp.octave_coord = voronoi_coord;
// vp.randomness, vp.max_distance = voronoi_distance_3d(zero_float3(), one_float3(), vp.metric, vp.exponent);
// voronoi_metric, VoronoiOutput<float3> vo{vob};
// &max_amplitude, vo.position_out = zero_float3();
// &distance_out,
// &color_out, switch (vpb.feature) {
// &position_out_4d); case NODE_VORONOI_F1: {
// if (normalize) { fractal_voronoi_x_fx<float3>(vp, vo, voronoi_f1_3d);
// distance_out /= (0.5f + 0.5f * vp.randomness) * max_amplitude * break;
// voronoi_distance_4d(make_float4(1.0f, 1.0f, 1.0f, 1.0f), }
// make_float4(0.0f, 0.0f, 0.0f, 0.0f), case NODE_VORONOI_SMOOTH_F1:
// voronoi_metric, IF_KERNEL_NODES_FEATURE(VORONOI_EXTRA)
// vp.exponent); {
// color_out /= max_amplitude; fractal_voronoi_x_fx<float3>(vp, vo, voronoi_smooth_f1_3d);
// } break;
// break; }
// } break;
// case NODE_VORONOI_SMOOTH_F1: { case NODE_VORONOI_F2: {
// fractal_voronoi_smooth_f1<float4>(coord_4d, fractal_voronoi_x_fx<float3>(vp, vo, voronoi_f2_3d);
// detail, break;
// roughness, }
// lacunarity, case NODE_VORONOI_DISTANCE_TO_EDGE: {
// vp.smoothness, fractal_voronoi_distance_to_edge<float3>(vp, vo);
// vp.exponent, break;
// vp.randomness, }
// voronoi_metric, case NODE_VORONOI_N_SPHERE_RADIUS:
// &max_amplitude, voronoi_n_sphere_radius_3d(vp, vo);
// &distance_out, break;
// &color_out, default:
// &position_out_4d); kernel_assert(0);
// if (normalize) { }
// distance_out /= (0.5f + 0.5f * vp.randomness) * max_amplitude * vo.position_out = safe_divide(vo.position_out, vpb.scale);
// voronoi_distance_4d(make_float4(1.0f, 1.0f, 1.0f, 1.0f),
// make_float4(0.0f, 0.0f, 0.0f, 0.0f), vob = vo;
// voronoi_metric, voronoi_position_out = vo.position_out;
// vp.exponent); break;
// color_out /= max_amplitude; }
// }
// break; case 4: {
// } IF_KERNEL_NODES_FEATURE(VORONOI_EXTRA)
// case NODE_VORONOI_F2: { {
// fractal_voronoi_f2<float4>(coord_4d, VoronoiParams<float4> vp{vpb};
// detail, vp.octave_coord = make_float4(
// roughness, voronoi_coord.x, voronoi_coord.y, voronoi_coord.z, voronoi_w);
// lacunarity, vp.max_distance = voronoi_distance_4d(zero_float4(), one_float4(), vp.metric, vp.exponent);
// vp.exponent, VoronoiOutput<float4> vo{vob};
// vp.randomness, vo.position_out = zero_float4();
// voronoi_metric,
// &max_amplitude, switch (vpb.feature) {
// &distance_out, case NODE_VORONOI_F1: {
// &color_out, fractal_voronoi_x_fx<float4>(vp, vo, voronoi_f1_4d);
// &position_out_4d); break;
// if (normalize) { }
// if (detail == 0.0f || roughness == 0.0f || lacunarity == 0.0f) { case NODE_VORONOI_SMOOTH_F1: {
// distance_out /= (1.0f - vp.randomness) + fractal_voronoi_x_fx<float4>(vp, vo, voronoi_smooth_f1_4d);
// vp.randomness * max_amplitude * break;
// voronoi_distance_4d(make_float4(1.0f, 1.0f, 1.0f, 1.0f), }
// make_float4(0.0f, 0.0f, 0.0f, 0.0f), case NODE_VORONOI_F2: {
// voronoi_metric, fractal_voronoi_x_fx<float4>(vp, vo, voronoi_f2_4d);
// vp.exponent); break;
// } }
// else { case NODE_VORONOI_DISTANCE_TO_EDGE: {
// distance_out /= (1.0f - vp.randomness) * ceilf(detail + 1.0f) + fractal_voronoi_distance_to_edge<float4>(vp, vo);
// vp.randomness * max_amplitude * break;
// voronoi_distance_4d(make_float4(1.0f, 1.0f, 1.0f, 1.0f), }
// make_float4(0.0f, 0.0f, 0.0f, 0.0f), case NODE_VORONOI_N_SPHERE_RADIUS:
// voronoi_metric, voronoi_n_sphere_radius_4d(vp, vo);
// vp.exponent); break;
// } default:
// color_out /= max_amplitude; kernel_assert(0);
// } }
// break; vo.position_out = safe_divide(vo.position_out, vpb.scale);
// }
// case NODE_VORONOI_DISTANCE_TO_EDGE: { vob = vo;
// fractal_voronoi_distance_to_edge<float4>(coord_4d, voronoi_position_out = make_float3(
// detail, vo.position_out.x, vo.position_out.y, vo.position_out.z);
// roughness, voronoi_w_out = vo.position_out.w;
// lacunarity, }
// vp.randomness, break;
// &max_amplitude, }
// &distance_out); default:
// if (normalize) { kernel_assert(0);
// /* max_amplitude is used here to keep the code consistent, however it has a }
// different
// * meaning than in F1, Smooth F1 and F2. Instead of the highest possible
// amplitude,
// * it represents an abstract factor needed to cancel out the amplitude
// attenuation
// * caused by the higher layers. */
// distance_out *= max_amplitude;
// }
// break;
// }
// case NODE_VORONOI_N_SPHERE_RADIUS:
// voronoi_n_sphere_radius_4d(coord_4d, vp.randomness, &radius_out);
// break;
// default:
// kernel_assert(0);
// }
// position_out_4d = safe_divide(position_out_4d, scale);
// position_out = make_float3(position_out_4d.x, position_out_4d.y, position_out_4d.z);
// w_out = position_out_4d.w;
// }
// break;
// }
// default:
// kernel_assert(0);
//}
if (stack_valid(distance_out_stack_offset)) if (stack_valid(distance_out_stack_offset))
stack_store_float(stack, distance_out_stack_offset, vob.distance_out); stack_store_float(stack, distance_out_stack_offset, vob.distance_out);