From d4dffef0f97715a9893780369b5bbb58bf55c75f Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Wed, 18 Dec 2024 22:59:35 +0000 Subject: [PATCH] Formatting --- generators/graph/nodes/noise.h | 262 ++++++++++++++++++++++----------- 1 file changed, 174 insertions(+), 88 deletions(-) diff --git a/generators/graph/nodes/noise.h b/generators/graph/nodes/noise.h index 416b5374c..3635a2a3f 100644 --- a/generators/graph/nodes/noise.h +++ b/generators/graph/nodes/noise.h @@ -22,49 +22,75 @@ Variant create_resource_to_variant() { void add_fast_noise_lite_state_config(ShaderGenContext &ctx, const FastNoiseLite &fnl) { // TODO Add missing options - ctx.add_format("fnl_state state = fnlCreateState({});\n" - "state.noise_type = {};\n" - "state.fractal_type = {};\n" - "state.octaves = {};\n" - "state.gain = {};\n" - "state.frequency = {};\n" - "state.lacunarity = {};\n" - "state.cellular_distance_func = {};\n" - "state.cellular_return_type = {};\n" - "state.cellular_jitter_mod = {};\n", - fnl.get_seed(), fnl.get_noise_type(), fnl.get_fractal_type(), fnl.get_fractal_octaves(), - fnl.get_fractal_gain(), fnl.get_frequency(), fnl.get_fractal_lacunarity(), - fnl.get_cellular_distance_function(), fnl.get_cellular_return_type(), fnl.get_cellular_jitter()); + ctx.add_format( + "fnl_state state = fnlCreateState({});\n" + "state.noise_type = {};\n" + "state.fractal_type = {};\n" + "state.octaves = {};\n" + "state.gain = {};\n" + "state.frequency = {};\n" + "state.lacunarity = {};\n" + "state.cellular_distance_func = {};\n" + "state.cellular_return_type = {};\n" + "state.cellular_jitter_mod = {};\n", + fnl.get_seed(), + fnl.get_noise_type(), + fnl.get_fractal_type(), + fnl.get_fractal_octaves(), + fnl.get_fractal_gain(), + fnl.get_frequency(), + fnl.get_fractal_lacunarity(), + fnl.get_cellular_distance_function(), + fnl.get_cellular_return_type(), + fnl.get_cellular_jitter() + ); } void add_fast_noise_lite_state_config(ShaderGenContext &ctx, const ZN_FastNoiseLite &fnl) { // TODO Add missing options - ctx.add_format("fnl_state state = fnlCreateState({});\n" - "state.noise_type = {};\n" - "state.fractal_type = {};\n" - "state.octaves = {};\n" - "state.gain = {};\n" - "state.frequency = {};\n" - "state.lacunarity = {};\n" - "state.cellular_distance_func = {};\n" - "state.cellular_return_type = {};\n" - "state.cellular_jitter_mod = {};\n", - fnl.get_seed(), fnl.get_noise_type(), fnl.get_fractal_type(), fnl.get_fractal_octaves(), - fnl.get_fractal_gain(), 1.0 / fnl.get_period(), fnl.get_fractal_lacunarity(), - fnl.get_cellular_distance_function(), fnl.get_cellular_return_type(), fnl.get_cellular_jitter()); + ctx.add_format( + "fnl_state state = fnlCreateState({});\n" + "state.noise_type = {};\n" + "state.fractal_type = {};\n" + "state.octaves = {};\n" + "state.gain = {};\n" + "state.frequency = {};\n" + "state.lacunarity = {};\n" + "state.cellular_distance_func = {};\n" + "state.cellular_return_type = {};\n" + "state.cellular_jitter_mod = {};\n", + fnl.get_seed(), + fnl.get_noise_type(), + fnl.get_fractal_type(), + fnl.get_fractal_octaves(), + fnl.get_fractal_gain(), + 1.0 / fnl.get_period(), + fnl.get_fractal_lacunarity(), + fnl.get_cellular_distance_function(), + fnl.get_cellular_return_type(), + fnl.get_cellular_jitter() + ); } void add_fast_noise_lite_gradient_state_config(ShaderGenContext &ctx, const ZN_FastNoiseLiteGradient &fnl) { - ctx.add_format("fnl_state state = fnlCreateState({});\n" - "state.domain_warp_type = {};\n" - "state.domain_warp_amp = {};\n" - "state.fractal_type = {};\n" - "state.octaves = {};\n" - "state.gain = {};\n" - "state.frequency = {};\n" - "state.lacunarity = {};\n", - fnl.get_seed(), fnl.get_noise_type(), fnl.get_amplitude(), fnl.get_fractal_type(), - fnl.get_fractal_octaves(), fnl.get_fractal_gain(), 1.0 / fnl.get_period(), fnl.get_fractal_lacunarity()); + ctx.add_format( + "fnl_state state = fnlCreateState({});\n" + "state.domain_warp_type = {};\n" + "state.domain_warp_amp = {};\n" + "state.fractal_type = {};\n" + "state.octaves = {};\n" + "state.gain = {};\n" + "state.frequency = {};\n" + "state.lacunarity = {};\n", + fnl.get_seed(), + fnl.get_noise_type(), + fnl.get_amplitude(), + fnl.get_fractal_type(), + fnl.get_fractal_octaves(), + fnl.get_fractal_gain(), + 1.0 / fnl.get_period(), + fnl.get_fractal_lacunarity() + ); } void register_noise_nodes(Span types) { @@ -84,7 +110,8 @@ void register_noise_nodes(Span types) { t.inputs.push_back(NodeType::Port("y", 0.f, VoxelGraphFunction::AUTO_CONNECT_Z)); t.outputs.push_back(NodeType::Port("out")); t.params.push_back( - NodeType::Param("noise", Noise::get_class_static(), &create_resource_to_variant)); + NodeType::Param("noise", Noise::get_class_static(), &create_resource_to_variant) + ); t.compile_func = [](CompileContext &ctx) { Ref noise = ctx.get_param(0); @@ -156,7 +183,8 @@ void register_noise_nodes(Span types) { t.inputs.push_back(NodeType::Port("z", 0.f, VoxelGraphFunction::AUTO_CONNECT_Z)); t.outputs.push_back(NodeType::Port("out")); t.params.push_back( - NodeType::Param("noise", Noise::get_class_static(), &create_resource_to_variant)); + NodeType::Param("noise", Noise::get_class_static(), &create_resource_to_variant) + ); t.compile_func = [](CompileContext &ctx) { Ref noise = ctx.get_param(0); @@ -204,16 +232,21 @@ void register_noise_nodes(Span types) { } if (fnl->is_domain_warp_enabled()) { // TODO Support domain warp shader generation with Godot's implementation of FastNoiseLite - ctx.make_error( - String(ZN_TTR("Shader generation from {0} with domain warp is not supported. Use {1}.")) - .format(varray(noise->get_class(), ZN_FastNoiseLiteGradient::get_class_static()))); + ctx.make_error(String(ZN_TTR("Shader generation from {0} with domain warp is not supported. Use {1}.")) + .format(varray(noise->get_class(), ZN_FastNoiseLiteGradient::get_class_static())) + ); return; } ctx.require_lib_code("vg_fnl", g_fast_noise_lite_shader); add_fast_noise_lite_state_config(ctx, **fnl); // TODO Add missing options - ctx.add_format("{} = fnlGetNoise3D(state, {}, {}, {});\n", ctx.get_output_name(0), ctx.get_input_name(0), - ctx.get_input_name(1), ctx.get_input_name(2)); + ctx.add_format( + "{} = fnlGetNoise3D(state, {}, {}, {});\n", + ctx.get_output_name(0), + ctx.get_input_name(0), + ctx.get_input_name(1), + ctx.get_input_name(2) + ); }; } { @@ -227,14 +260,17 @@ void register_noise_nodes(Span types) { t.inputs.push_back(NodeType::Port("x", 0.f, VoxelGraphFunction::AUTO_CONNECT_X)); t.inputs.push_back(NodeType::Port("y", 0.f, VoxelGraphFunction::AUTO_CONNECT_Z)); t.outputs.push_back(NodeType::Port("out")); - t.params.push_back(NodeType::Param( - "noise", ZN_FastNoiseLite::get_class_static(), &create_resource_to_variant)); + t.params.push_back(NodeType:: + Param("noise", + ZN_FastNoiseLite::get_class_static(), + &create_resource_to_variant)); t.compile_func = [](CompileContext &ctx) { Ref noise = ctx.get_param(0); if (noise.is_null()) { ctx.make_error( - String(ZN_TTR("{0} instance is null")).format(varray(ZN_FastNoiseLite::get_class_static()))); + String(ZN_TTR("{0} instance is null")).format(varray(ZN_FastNoiseLite::get_class_static())) + ); return; } Params p; @@ -265,13 +301,18 @@ void register_noise_nodes(Span types) { Ref noise = ctx.get_param(0); if (noise.is_null()) { ctx.make_error( - String(ZN_TTR("{0} instance is null")).format(varray(ZN_FastNoiseLite::get_class_static()))); + String(ZN_TTR("{0} instance is null")).format(varray(ZN_FastNoiseLite::get_class_static())) + ); return; } ctx.require_lib_code("vg_fnl", g_fast_noise_lite_shader); add_fast_noise_lite_state_config(ctx, **noise); - ctx.add_format("{} = fnlGetNoise2D(state, {}, {});\n", ctx.get_output_name(0), ctx.get_input_name(0), - ctx.get_input_name(1)); + ctx.add_format( + "{} = fnlGetNoise2D(state, {}, {});\n", + ctx.get_output_name(0), + ctx.get_input_name(0), + ctx.get_input_name(1) + ); }; } { @@ -286,14 +327,17 @@ void register_noise_nodes(Span types) { t.inputs.push_back(NodeType::Port("y", 0.f, VoxelGraphFunction::AUTO_CONNECT_Y)); t.inputs.push_back(NodeType::Port("z", 0.f, VoxelGraphFunction::AUTO_CONNECT_Z)); t.outputs.push_back(NodeType::Port("out")); - t.params.push_back(NodeType::Param( - "noise", ZN_FastNoiseLite::get_class_static(), &create_resource_to_variant)); + t.params.push_back(NodeType:: + Param("noise", + ZN_FastNoiseLite::get_class_static(), + &create_resource_to_variant)); t.compile_func = [](CompileContext &ctx) { Ref noise = ctx.get_param(0); if (noise.is_null()) { ctx.make_error( - String(ZN_TTR("{0} instance is null")).format(varray(ZN_FastNoiseLite::get_class_static()))); + String(ZN_TTR("{0} instance is null")).format(varray(ZN_FastNoiseLite::get_class_static())) + ); return; } Params p; @@ -326,13 +370,19 @@ void register_noise_nodes(Span types) { Ref noise = ctx.get_param(0); if (noise.is_null()) { ctx.make_error( - String(ZN_TTR("{0} instance is null")).format(varray(ZN_FastNoiseLite::get_class_static()))); + String(ZN_TTR("{0} instance is null")).format(varray(ZN_FastNoiseLite::get_class_static())) + ); return; } ctx.require_lib_code("vg_fnl", g_fast_noise_lite_shader); add_fast_noise_lite_state_config(ctx, **noise); - ctx.add_format("{} = fnlGetNoise3D(state, {}, {}, {});\n", ctx.get_output_name(0), ctx.get_input_name(0), - ctx.get_input_name(1), ctx.get_input_name(2)); + ctx.add_format( + "{} = fnlGetNoise3D(state, {}, {}, {});\n", + ctx.get_output_name(0), + ctx.get_input_name(0), + ctx.get_input_name(1), + ctx.get_input_name(2) + ); }; } { @@ -347,8 +397,10 @@ void register_noise_nodes(Span types) { t.inputs.push_back(NodeType::Port("y", 0.f, VoxelGraphFunction::AUTO_CONNECT_Z)); t.outputs.push_back(NodeType::Port("out_x")); t.outputs.push_back(NodeType::Port("out_y")); - t.params.push_back(NodeType::Param("noise", ZN_FastNoiseLiteGradient::get_class_static(), - &create_resource_to_variant)); + t.params.push_back(NodeType:: + Param("noise", + ZN_FastNoiseLiteGradient::get_class_static(), + &create_resource_to_variant)); t.compile_func = [](CompileContext &ctx) { Ref noise = ctx.get_param(0); @@ -397,12 +449,17 @@ void register_noise_nodes(Span types) { } ctx.require_lib_code("vg_fnl", g_fast_noise_lite_shader); add_fast_noise_lite_gradient_state_config(ctx, **noise); - ctx.add_format("float wx = {};\n" - "float wy = {};\n" - "fnlDomainWarp2D(state, wx, wy);\n" - "{} = wx;\n" - "{} = wy;\n", - ctx.get_input_name(0), ctx.get_input_name(1), ctx.get_output_name(0), ctx.get_output_name(1)); + ctx.add_format( + "float wx = {};\n" + "float wy = {};\n" + "fnlDomainWarp2D(state, wx, wy);\n" + "{} = wx;\n" + "{} = wy;\n", + ctx.get_input_name(0), + ctx.get_input_name(1), + ctx.get_output_name(0), + ctx.get_output_name(1) + ); }; } { @@ -419,8 +476,10 @@ void register_noise_nodes(Span types) { t.outputs.push_back(NodeType::Port("out_x")); t.outputs.push_back(NodeType::Port("out_y")); t.outputs.push_back(NodeType::Port("out_z")); - t.params.push_back(NodeType::Param("noise", ZN_FastNoiseLiteGradient::get_class_static(), - &create_resource_to_variant)); + t.params.push_back(NodeType:: + Param("noise", + ZN_FastNoiseLiteGradient::get_class_static(), + &create_resource_to_variant)); t.compile_func = [](CompileContext &ctx) { Ref noise = ctx.get_param(0); @@ -475,15 +534,21 @@ void register_noise_nodes(Span types) { } ctx.require_lib_code("vg_fnl", g_fast_noise_lite_shader); add_fast_noise_lite_gradient_state_config(ctx, **noise); - ctx.add_format("float wx = {};\n" - "float wy = {};\n" - "float wz = {};\n" - "fnlDomainWarp3D(state, wx, wy, wz);\n" - "{} = wx;\n" - "{} = wy;\n" - "{} = wz;\n", - ctx.get_input_name(0), ctx.get_input_name(1), ctx.get_input_name(2), ctx.get_output_name(0), - ctx.get_output_name(1), ctx.get_output_name(2)); + ctx.add_format( + "float wx = {};\n" + "float wy = {};\n" + "float wz = {};\n" + "fnlDomainWarp3D(state, wx, wy, wz);\n" + "{} = wx;\n" + "{} = wy;\n" + "{} = wz;\n", + ctx.get_input_name(0), + ctx.get_input_name(1), + ctx.get_input_name(2), + ctx.get_output_name(0), + ctx.get_output_name(1), + ctx.get_output_name(2) + ); }; } #ifdef VOXEL_ENABLE_FAST_NOISE_2 @@ -499,7 +564,8 @@ void register_noise_nodes(Span types) { t.inputs.push_back(NodeType::Port("y", 0.f, VoxelGraphFunction::AUTO_CONNECT_Z)); t.outputs.push_back(NodeType::Port("out")); t.params.push_back( - NodeType::Param("noise", FastNoise2::get_class_static(), &create_resource_to_variant)); + NodeType::Param("noise", FastNoise2::get_class_static(), &create_resource_to_variant) + ); t.compile_func = [](CompileContext &ctx) { Ref noise = ctx.get_param(0); @@ -523,8 +589,11 @@ void register_noise_nodes(Span types) { const Runtime::Buffer &y = ctx.get_input(1); Runtime::Buffer &out = ctx.get_output(0); const Params p = ctx.get_params(); - p.noise->get_noise_2d_series(Span(x.data, x.size), Span(y.data, y.size), - Span(out.data, out.size)); + p.noise->get_noise_2d_series( + Span(x.data, x.size), + Span(y.data, y.size), + Span(out.data, out.size) + ); }; t.range_analysis_func = [](Runtime::RangeAnalysisContext &ctx) { @@ -548,7 +617,8 @@ void register_noise_nodes(Span types) { t.inputs.push_back(NodeType::Port("z", 0.f, VoxelGraphFunction::AUTO_CONNECT_Z)); t.outputs.push_back(NodeType::Port("out")); t.params.push_back( - NodeType::Param("noise", FastNoise2::get_class_static(), &create_resource_to_variant)); + NodeType::Param("noise", FastNoise2::get_class_static(), &create_resource_to_variant) + ); t.compile_func = [](CompileContext &ctx) { Ref noise = ctx.get_param(0); @@ -573,8 +643,12 @@ void register_noise_nodes(Span types) { const Runtime::Buffer &z = ctx.get_input(2); Runtime::Buffer &out = ctx.get_output(0); const Params p = ctx.get_params(); - p.noise->get_noise_3d_series(Span(x.data, x.size), Span(y.data, y.size), - Span(z.data, z.size), Span(out.data, out.size)); + p.noise->get_noise_3d_series( + Span(x.data, x.size), + Span(y.data, y.size), + Span(z.data, z.size), + Span(out.data, out.size) + ); }; t.range_analysis_func = [](Runtime::RangeAnalysisContext &ctx) { @@ -653,8 +727,9 @@ void register_noise_nodes(Span types) { Runtime::Buffer &out = ctx.get_output(0); const Params params = ctx.get_params(); for (unsigned int i = 0; i < out.size; ++i) { - out.data[i] = SpotNoise::spot_noise_2d(Vector2f(x.data[i], y.data[i]), params.cell_size, - spot_size.data[i], params.jitter, params.seed); + out.data[i] = SpotNoise::spot_noise_2d( + Vector2f(x.data[i], y.data[i]), params.cell_size, spot_size.data[i], params.jitter, params.seed + ); } }; @@ -663,9 +738,12 @@ void register_noise_nodes(Span types) { const Interval y = ctx.get_input(1); const Interval spot_size = ctx.get_input(2); const Params params = ctx.get_params(); - ctx.set_output(0, + ctx.set_output( + 0, SpotNoise::spot_noise_2d_range( - Interval2{ x, y }, params.cell_size, spot_size, params.jitter, params.seed)); + Interval2{ x, y }, params.cell_size, spot_size, params.jitter, params.seed + ) + ); }; // TODO Support shader code for the Spots2D node @@ -739,8 +817,13 @@ void register_noise_nodes(Span types) { Runtime::Buffer &out = ctx.get_output(0); const Params params = ctx.get_params(); for (unsigned int i = 0; i < out.size; ++i) { - out.data[i] = SpotNoise::spot_noise_3d(Vector3f(x.data[i], y.data[i], z.data[i]), params.cell_size, - spot_size.data[i], params.jitter, params.seed); + out.data[i] = SpotNoise::spot_noise_3d( + Vector3f(x.data[i], y.data[i], z.data[i]), + params.cell_size, + spot_size.data[i], + params.jitter, + params.seed + ); } }; @@ -750,9 +833,12 @@ void register_noise_nodes(Span types) { const Interval z = ctx.get_input(2); const Interval spot_size = ctx.get_input(3); const Params params = ctx.get_params(); - ctx.set_output(0, + ctx.set_output( + 0, SpotNoise::spot_noise_3d_range( - Interval3{ x, y, z }, params.cell_size, spot_size, params.jitter, params.seed)); + Interval3{ x, y, z }, params.cell_size, spot_size, params.jitter, params.seed + ) + ); }; // TODO Support shader code for the Spots3D node