diff options
author | Charlie Jolly <charlie> | 2021-09-30 21:05:08 +0300 |
---|---|---|
committer | Charlie Jolly <mistajolly@gmail.com> | 2021-09-30 21:24:40 +0300 |
commit | be70827e6f62763d524f00652f61da6fc86e2714 (patch) | |
tree | 72a673c31ac82ea03a18d126bb17d70ad5955690 /intern/cycles/blender | |
parent | 827e30bd1512f6917307195ccc934b57623f0f8b (diff) |
Nodes: Add Float Curve for GN and Shader nodes.
Replacement for float curve in legacy Attribute Curve Map node.
Float Curve defaults to [0.0-1.0] range.
Reviewed By: JacquesLucke, brecht
Differential Revision: https://developer.blender.org/D12683
Diffstat (limited to 'intern/cycles/blender')
-rw-r--r-- | intern/cycles/blender/blender_shader.cpp | 17 | ||||
-rw-r--r-- | intern/cycles/blender/blender_util.h | 28 |
2 files changed, 40 insertions, 5 deletions
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp index 8c4f789ffd0..0b8aea15d6c 100644 --- a/intern/cycles/blender/blender_shader.cpp +++ b/intern/cycles/blender/blender_shader.cpp @@ -279,7 +279,7 @@ static ShaderNode *add_node(Scene *scene, array<float3> curve_mapping_curves; float min_x, max_x; curvemapping_color_to_array(mapping, curve_mapping_curves, RAMP_TABLE_SIZE, true); - curvemapping_minmax(mapping, true, &min_x, &max_x); + curvemapping_minmax(mapping, 4, &min_x, &max_x); curves->set_min_x(min_x); curves->set_max_x(max_x); curves->set_curves(curve_mapping_curves); @@ -292,12 +292,25 @@ static ShaderNode *add_node(Scene *scene, array<float3> curve_mapping_curves; float min_x, max_x; curvemapping_color_to_array(mapping, curve_mapping_curves, RAMP_TABLE_SIZE, false); - curvemapping_minmax(mapping, false, &min_x, &max_x); + curvemapping_minmax(mapping, 3, &min_x, &max_x); curves->set_min_x(min_x); curves->set_max_x(max_x); curves->set_curves(curve_mapping_curves); node = curves; } + else if (b_node.is_a(&RNA_ShaderNodeFloatCurve)) { + BL::ShaderNodeFloatCurve b_curve_node(b_node); + BL::CurveMapping mapping(b_curve_node.mapping()); + FloatCurveNode *curve = graph->create_node<FloatCurveNode>(); + array<float> curve_mapping_curve; + float min_x, max_x; + curvemapping_float_to_array(mapping, curve_mapping_curve, RAMP_TABLE_SIZE); + curvemapping_minmax(mapping, 1, &min_x, &max_x); + curve->set_min_x(min_x); + curve->set_max_x(max_x); + curve->set_curve(curve_mapping_curve); + node = curve; + } else if (b_node.is_a(&RNA_ShaderNodeValToRGB)) { RGBRampNode *ramp = graph->create_node<RGBRampNode>(); BL::ShaderNodeValToRGB b_ramp_node(b_node); diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h index 128fcbd7055..77b2bd5ac4f 100644 --- a/intern/cycles/blender/blender_util.h +++ b/intern/cycles/blender/blender_util.h @@ -171,12 +171,11 @@ static inline void curvemap_minmax_curve(/*const*/ BL::CurveMap &curve, float *m } static inline void curvemapping_minmax(/*const*/ BL::CurveMapping &cumap, - bool rgb_curve, + int num_curves, float *min_x, float *max_x) { // const int num_curves = cumap.curves.length(); /* Gives linking error so far. */ - const int num_curves = rgb_curve ? 4 : 3; *min_x = FLT_MAX; *max_x = -FLT_MAX; for (int i = 0; i < num_curves; ++i) { @@ -196,6 +195,28 @@ static inline void curvemapping_to_array(BL::CurveMapping &cumap, array<float> & } } +static inline void curvemapping_float_to_array(BL::CurveMapping &cumap, + array<float> &data, + int size) +{ + float min = 0.0f, max = 1.0f; + + curvemapping_minmax(cumap, 1, &min, &max); + + const float range = max - min; + + cumap.update(); + + BL::CurveMap map = cumap.curves[0]; + + data.resize(size); + + for (int i = 0; i < size; i++) { + float t = min + (float)i / (float)(size - 1) * range; + data[i] = cumap.evaluate(map, t); + } +} + static inline void curvemapping_color_to_array(BL::CurveMapping &cumap, array<float3> &data, int size, @@ -214,7 +235,8 @@ static inline void curvemapping_color_to_array(BL::CurveMapping &cumap, * * There might be some better estimations here tho. */ - curvemapping_minmax(cumap, rgb_curve, &min_x, &max_x); + const int num_curves = rgb_curve ? 4 : 3; + curvemapping_minmax(cumap, num_curves, &min_x, &max_x); const float range_x = max_x - min_x; |