diff options
author | OmarSquircleArt <omar.squircleart@gmail.com> | 2019-09-04 18:54:32 +0300 |
---|---|---|
committer | OmarSquircleArt <omar.squircleart@gmail.com> | 2019-09-04 18:54:32 +0300 |
commit | 23564583a4988778b4c43496fd21818b286f6ba1 (patch) | |
tree | 3dc149c4e5c26ea2aac460ed582cb31def988470 /intern/cycles/render/nodes.cpp | |
parent | 45d4c925799e94c6d442a9a9066af2d3305724e1 (diff) |
Shading: Extend Noise node to other dimenstions.
This patch extends perlin noise to operate in 1D, 2D, 3D, and 4D
space. The noise code has also been refactored to be more readable.
The Color output and distortion patterns changed, so this patch
breaks backward compatibility. This is due to the fact that we
now use random offsets as noise seeds, as opposed to swizzling
and constants offsets.
Reviewers: brecht, JacquesLucke
Differential Revision: https://developer.blender.org/D5560
Diffstat (limited to 'intern/cycles/render/nodes.cpp')
-rw-r--r-- | intern/cycles/render/nodes.cpp | 53 |
1 files changed, 35 insertions, 18 deletions
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index bf8185d2b38..24aa9589220 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -893,14 +893,22 @@ NODE_DEFINE(NoiseTextureNode) TEXTURE_MAPPING_DEFINE(NoiseTextureNode); + 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); + + 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", 1.0f); SOCKET_IN_FLOAT(detail, "Detail", 2.0f); SOCKET_IN_FLOAT(distortion, "Distortion", 0.0f); - SOCKET_IN_POINT( - vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TEXTURE_GENERATED); - SOCKET_OUT_COLOR(color, "Color"); SOCKET_OUT_FLOAT(fac, "Fac"); + SOCKET_OUT_COLOR(color, "Color"); return type; } @@ -911,31 +919,40 @@ NoiseTextureNode::NoiseTextureNode() : TextureNode(node_type) void NoiseTextureNode::compile(SVMCompiler &compiler) { - ShaderInput *distortion_in = input("Distortion"); - ShaderInput *detail_in = input("Detail"); - ShaderInput *scale_in = input("Scale"); ShaderInput *vector_in = input("Vector"); - ShaderOutput *color_out = output("Color"); + ShaderInput *w_in = input("W"); + ShaderInput *scale_in = input("Scale"); + ShaderInput *detail_in = input("Detail"); + ShaderInput *distortion_in = input("Distortion"); ShaderOutput *fac_out = output("Fac"); + ShaderOutput *color_out = output("Color"); - int vector_offset = tex_mapping.compile_begin(compiler, vector_in); + int vector_stack_offset = tex_mapping.compile_begin(compiler, vector_in); + int w_stack_offset = compiler.stack_assign_if_linked(w_in); + int scale_stack_offset = compiler.stack_assign_if_linked(scale_in); + int detail_stack_offset = compiler.stack_assign_if_linked(detail_in); + int distortion_stack_offset = compiler.stack_assign_if_linked(distortion_in); + int fac_stack_offset = compiler.stack_assign_if_linked(fac_out); + int color_stack_offset = compiler.stack_assign_if_linked(color_out); - compiler.add_node(NODE_TEX_NOISE, - compiler.encode_uchar4(vector_offset, - compiler.stack_assign_if_linked(scale_in), - compiler.stack_assign_if_linked(detail_in), - compiler.stack_assign_if_linked(distortion_in)), - compiler.encode_uchar4(compiler.stack_assign_if_linked(color_out), - compiler.stack_assign_if_linked(fac_out))); - compiler.add_node(__float_as_int(scale), __float_as_int(detail), __float_as_int(distortion)); + compiler.add_node( + NODE_TEX_NOISE, + dimensions, + compiler.encode_uchar4( + vector_stack_offset, w_stack_offset, scale_stack_offset, detail_stack_offset), + compiler.encode_uchar4(distortion_stack_offset, fac_stack_offset, color_stack_offset)); + compiler.add_node(__float_as_int(w), + __float_as_int(scale), + __float_as_int(detail), + __float_as_int(distortion)); - tex_mapping.compile_end(compiler, vector_in, vector_offset); + tex_mapping.compile_end(compiler, vector_in, vector_stack_offset); } void NoiseTextureNode::compile(OSLCompiler &compiler) { tex_mapping.compile(compiler); - + compiler.parameter(this, "dimensions"); compiler.add(this, "node_noise_texture"); } |