diff options
author | OmarSquircleArt <omar.squircleart@gmail.com> | 2019-09-12 14:09:31 +0300 |
---|---|---|
committer | OmarSquircleArt <omar.squircleart@gmail.com> | 2019-09-12 14:09:31 +0300 |
commit | 613b37bc2c81202a34346b40465923e8f47cebbf (patch) | |
tree | f567f30b59f475744575589f4330c61afc30a5a0 /intern/cycles/render/nodes.cpp | |
parent | 013750947657fcdea313782d82ec51cc111f0c06 (diff) |
Shading: Add More Features To The Voronoi Node.
This patch allows the Voronoi node to operate in 1D, 2D, and 4D space.
It also adds a Randomness input to control the randomness of the texture.
Additionally, it adds three new modes of operation:
- Smooth F1: A smooth version of F1 Voronoi with no discontinuities.
- Distance To Edge: Returns the distance to the edges of the cells.
- N-Sphere Radius: Returns the radius of the n-sphere inscribed in
the cells. In other words, it is half the distance between the
closest feature point and the feature point closest to it.
And it removes the following three modes of operation:
- F3.
- F4.
- Cracks.
The Distance metric is now called Euclidean, and it computes the actual
euclidean distance as opposed to the old method of computing the squared
euclidean distance.
This breaks backward compatibility in many ways, including the base case.
Reviewers: brecht, JacquesLucke
Differential Revision: https://developer.blender.org/D5743
Diffstat (limited to 'intern/cycles/render/nodes.cpp')
-rw-r--r-- | intern/cycles/render/nodes.cpp | 104 |
1 files changed, 65 insertions, 39 deletions
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 01661a6d1e0..1d98fabbc9f 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -965,33 +965,41 @@ NODE_DEFINE(VoronoiTextureNode) TEXTURE_MAPPING_DEFINE(VoronoiTextureNode); - static NodeEnum coloring_enum; - coloring_enum.insert("intensity", NODE_VORONOI_INTENSITY); - coloring_enum.insert("cells", NODE_VORONOI_CELLS); - SOCKET_ENUM(coloring, "Coloring", coloring_enum, NODE_VORONOI_INTENSITY); - - static NodeEnum metric; - metric.insert("distance", NODE_VORONOI_DISTANCE); - metric.insert("manhattan", NODE_VORONOI_MANHATTAN); - metric.insert("chebychev", NODE_VORONOI_CHEBYCHEV); - metric.insert("minkowski", NODE_VORONOI_MINKOWSKI); - SOCKET_ENUM(metric, "Distance Metric", metric, NODE_VORONOI_INTENSITY); + static NodeEnum dimensions_enum; + dimensions_enum.insert("1D", 1); + dimensions_enum.insert("2D", 2); + dimensions_enum.insert("3D", 3); + dimensions_enum.insert("4D", 4); + SOCKET_ENUM(dimensions, "Dimensions", dimensions_enum, 3); + + static NodeEnum metric_enum; + metric_enum.insert("euclidean", NODE_VORONOI_EUCLIDEAN); + metric_enum.insert("manhattan", NODE_VORONOI_MANHATTAN); + metric_enum.insert("chebychev", NODE_VORONOI_CHEBYCHEV); + metric_enum.insert("minkowski", NODE_VORONOI_MINKOWSKI); + SOCKET_ENUM(metric, "Distance Metric", metric_enum, NODE_VORONOI_EUCLIDEAN); static NodeEnum feature_enum; - feature_enum.insert("F1", NODE_VORONOI_F1); - feature_enum.insert("F2", NODE_VORONOI_F2); - feature_enum.insert("F3", NODE_VORONOI_F3); - feature_enum.insert("F4", NODE_VORONOI_F4); - feature_enum.insert("F2F1", NODE_VORONOI_F2F1); - SOCKET_ENUM(feature, "Feature", feature_enum, NODE_VORONOI_INTENSITY); + feature_enum.insert("f1", NODE_VORONOI_F1); + feature_enum.insert("f2", NODE_VORONOI_F2); + feature_enum.insert("smooth_f1", NODE_VORONOI_SMOOTH_F1); + feature_enum.insert("distance_to_edge", NODE_VORONOI_DISTANCE_TO_EDGE); + feature_enum.insert("n_sphere_radius", NODE_VORONOI_N_SPHERE_RADIUS); + SOCKET_ENUM(feature, "Feature", feature_enum, NODE_VORONOI_F1); - SOCKET_IN_FLOAT(scale, "Scale", 1.0f); - SOCKET_IN_FLOAT(exponent, "Exponent", 0.5f); SOCKET_IN_POINT( vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TEXTURE_GENERATED); + SOCKET_IN_FLOAT(w, "W", 0.0f); + SOCKET_IN_FLOAT(scale, "Scale", 5.0f); + SOCKET_IN_FLOAT(smoothness, "Smoothness", 5.0f); + SOCKET_IN_FLOAT(exponent, "Exponent", 0.5f); + SOCKET_IN_FLOAT(randomness, "Randomness", 1.0f); + SOCKET_OUT_FLOAT(distance, "Distance"); SOCKET_OUT_COLOR(color, "Color"); - SOCKET_OUT_FLOAT(fac, "Fac"); + SOCKET_OUT_POINT(position, "Position"); + SOCKET_OUT_FLOAT(w, "W"); + SOCKET_OUT_FLOAT(radius, "Radius"); return type; } @@ -1002,39 +1010,57 @@ VoronoiTextureNode::VoronoiTextureNode() : TextureNode(node_type) void VoronoiTextureNode::compile(SVMCompiler &compiler) { - ShaderInput *scale_in = input("Scale"); ShaderInput *vector_in = input("Vector"); + ShaderInput *w_in = input("W"); + ShaderInput *scale_in = input("Scale"); + ShaderInput *smoothness_in = input("Smoothness"); ShaderInput *exponent_in = input("Exponent"); + ShaderInput *randomness_in = input("Randomness"); + + ShaderOutput *distance_out = output("Distance"); ShaderOutput *color_out = output("Color"); - ShaderOutput *fac_out = output("Fac"); + ShaderOutput *position_out = output("Position"); + ShaderOutput *w_out = output("W"); + ShaderOutput *radius_out = output("Radius"); - if (vector_in->link) - compiler.stack_assign(vector_in); - if (scale_in->link) - compiler.stack_assign(scale_in); - if (exponent_in->link) - compiler.stack_assign(exponent_in); + int vector_stack_offset = tex_mapping.compile_begin(compiler, vector_in); + int w_in_stack_offset = compiler.stack_assign_if_linked(w_in); + int scale_stack_offset = compiler.stack_assign_if_linked(scale_in); + int smoothness_stack_offset = compiler.stack_assign_if_linked(smoothness_in); + int exponent_stack_offset = compiler.stack_assign_if_linked(exponent_in); + int randomness_stack_offset = compiler.stack_assign_if_linked(randomness_in); + int distance_stack_offset = compiler.stack_assign_if_linked(distance_out); + int color_stack_offset = compiler.stack_assign_if_linked(color_out); + int position_stack_offset = compiler.stack_assign_if_linked(position_out); + int w_out_stack_offset = compiler.stack_assign_if_linked(w_out); + int radius_stack_offset = compiler.stack_assign_if_linked(radius_out); - int vector_offset = tex_mapping.compile_begin(compiler, vector_in); + compiler.add_node(NODE_TEX_VORONOI, dimensions, feature, metric); + compiler.add_node( + compiler.encode_uchar4( + vector_stack_offset, w_in_stack_offset, scale_stack_offset, smoothness_stack_offset), + compiler.encode_uchar4(exponent_stack_offset, + randomness_stack_offset, + distance_stack_offset, + color_stack_offset), + compiler.encode_uchar4(position_stack_offset, w_out_stack_offset, radius_stack_offset), + __float_as_int(w)); - compiler.add_node(NODE_TEX_VORONOI, - compiler.encode_uchar4(vector_offset, coloring, metric, feature), - compiler.encode_uchar4(compiler.stack_assign_if_linked(scale_in), - compiler.stack_assign_if_linked(exponent_in), - compiler.stack_assign(fac_out), - compiler.stack_assign(color_out))); - compiler.add_node(__float_as_int(scale), __float_as_int(exponent)); + compiler.add_node(__float_as_int(scale), + __float_as_int(smoothness), + __float_as_int(exponent), + __float_as_int(randomness)); - tex_mapping.compile_end(compiler, vector_in, vector_offset); + tex_mapping.compile_end(compiler, vector_in, vector_stack_offset); } void VoronoiTextureNode::compile(OSLCompiler &compiler) { tex_mapping.compile(compiler); - compiler.parameter(this, "coloring"); - compiler.parameter(this, "metric"); + compiler.parameter(this, "dimensions"); compiler.parameter(this, "feature"); + compiler.parameter(this, "metric"); compiler.add(this, "node_voronoi_texture"); } |