From 2c1bffa286b9551c0533081cb16f497058974b03 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 16 Jun 2022 19:39:13 +0200 Subject: Cleanup: add verbose logging category names instead of numbers And use them more consistently than before. --- intern/cycles/scene/shader_nodes.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'intern/cycles/scene/shader_nodes.cpp') diff --git a/intern/cycles/scene/shader_nodes.cpp b/intern/cycles/scene/shader_nodes.cpp index 3b58556f601..f93a1a5231a 100644 --- a/intern/cycles/scene/shader_nodes.cpp +++ b/intern/cycles/scene/shader_nodes.cpp @@ -2391,7 +2391,7 @@ void GlossyBsdfNode::simplify_settings(Scene *scene) * NOTE: Keep the epsilon in sync with kernel! */ if (!roughness_input->link && roughness <= 1e-4f) { - VLOG(3) << "Using sharp glossy BSDF."; + VLOG_DEBUG << "Using sharp glossy BSDF."; distribution = CLOSURE_BSDF_REFLECTION_ID; } } @@ -2400,7 +2400,7 @@ void GlossyBsdfNode::simplify_settings(Scene *scene) * benefit from closure blur to remove unwanted noise. */ if (roughness_input->link == NULL && distribution == CLOSURE_BSDF_REFLECTION_ID) { - VLOG(3) << "Using GGX glossy with filter glossy."; + VLOG_DEBUG << "Using GGX glossy with filter glossy."; distribution = CLOSURE_BSDF_MICROFACET_GGX_ID; roughness = 0.0f; } @@ -2484,7 +2484,7 @@ void GlassBsdfNode::simplify_settings(Scene *scene) * NOTE: Keep the epsilon in sync with kernel! */ if (!roughness_input->link && roughness <= 1e-4f) { - VLOG(3) << "Using sharp glass BSDF."; + VLOG_DEBUG << "Using sharp glass BSDF."; distribution = CLOSURE_BSDF_SHARP_GLASS_ID; } } @@ -2493,7 +2493,7 @@ void GlassBsdfNode::simplify_settings(Scene *scene) * benefit from closure blur to remove unwanted noise. */ if (roughness_input->link == NULL && distribution == CLOSURE_BSDF_SHARP_GLASS_ID) { - VLOG(3) << "Using GGX glass with filter glossy."; + VLOG_DEBUG << "Using GGX glass with filter glossy."; distribution = CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID; roughness = 0.0f; } @@ -2577,7 +2577,7 @@ void RefractionBsdfNode::simplify_settings(Scene *scene) * NOTE: Keep the epsilon in sync with kernel! */ if (!roughness_input->link && roughness <= 1e-4f) { - VLOG(3) << "Using sharp refraction BSDF."; + VLOG_DEBUG << "Using sharp refraction BSDF."; distribution = CLOSURE_BSDF_REFRACTION_ID; } } @@ -2586,7 +2586,7 @@ void RefractionBsdfNode::simplify_settings(Scene *scene) * benefit from closure blur to remove unwanted noise. */ if (roughness_input->link == NULL && distribution == CLOSURE_BSDF_REFRACTION_ID) { - VLOG(3) << "Using GGX refraction with filter glossy."; + VLOG_DEBUG << "Using GGX refraction with filter glossy."; distribution = CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID; roughness = 0.0f; } -- cgit v1.2.3 From 5653c5fcdd9f424dc05ddf73b18ba8294daf4788 Mon Sep 17 00:00:00 2001 From: Michael Jones Date: Tue, 12 Jul 2022 17:22:36 +0200 Subject: Cycles: keep track of SVM nodes used in kernels To be used for specialization in Metal, to automatically leave out unused nodes from the kernel. Ref D14645 --- intern/cycles/scene/shader_nodes.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'intern/cycles/scene/shader_nodes.cpp') diff --git a/intern/cycles/scene/shader_nodes.cpp b/intern/cycles/scene/shader_nodes.cpp index f93a1a5231a..bedb0fe2902 100644 --- a/intern/cycles/scene/shader_nodes.cpp +++ b/intern/cycles/scene/shader_nodes.cpp @@ -6671,7 +6671,7 @@ void CurvesNode::compile(SVMCompiler &compiler, ShaderInput *fac_in = input("Fac"); - compiler.add_node(type, + compiler.add_node(ShaderNodeType(type), compiler.encode_uchar4(compiler.stack_assign(fac_in), compiler.stack_assign(value_in), compiler.stack_assign(value_out), @@ -6736,7 +6736,7 @@ void RGBCurvesNode::constant_fold(const ConstantFolder &folder) void RGBCurvesNode::compile(SVMCompiler &compiler) { - CurvesNode::compile(compiler, NODE_RGB_CURVES, input("Color"), output("Color")); + CurvesNode::compile(compiler, NODE_CURVES, input("Color"), output("Color")); } void RGBCurvesNode::compile(OSLCompiler &compiler) @@ -6774,7 +6774,7 @@ void VectorCurvesNode::constant_fold(const ConstantFolder &folder) void VectorCurvesNode::compile(SVMCompiler &compiler) { - CurvesNode::compile(compiler, NODE_VECTOR_CURVES, input("Vector"), output("Vector")); + CurvesNode::compile(compiler, NODE_CURVES, input("Vector"), output("Vector")); } void VectorCurvesNode::compile(OSLCompiler &compiler) -- cgit v1.2.3 From bfa0ee13d5395fa2cf622b6808e93d0a7cd4f3ea Mon Sep 17 00:00:00 2001 From: Charlie Jolly Date: Tue, 30 Aug 2022 11:05:46 +0100 Subject: Node: Mix node This patch is a response to T92588 and is implemented as a Function/Shader node. This node has support for Float, Vector and Color data types. For Vector it supports uniform and non-uniform mixing. For Color it now has the option to remove factor clamping. It replaces the Mix RGB for Shader and Geometry node trees. As discussed in T96219, this patch converts existing nodes in .blend files. The old node is still available in the Python API but hidden from the menus. Reviewed By: HooglyBoogly, JacquesLucke, simonthommes, brecht Maniphest Tasks: T92588 Differential Revision: https://developer.blender.org/D13749 --- intern/cycles/scene/shader_nodes.cpp | 244 ++++++++++++++++++++++++++++++++++- 1 file changed, 242 insertions(+), 2 deletions(-) (limited to 'intern/cycles/scene/shader_nodes.cpp') diff --git a/intern/cycles/scene/shader_nodes.cpp b/intern/cycles/scene/shader_nodes.cpp index bedb0fe2902..a9cd453947b 100644 --- a/intern/cycles/scene/shader_nodes.cpp +++ b/intern/cycles/scene/shader_nodes.cpp @@ -4950,7 +4950,7 @@ NODE_DEFINE(MixNode) type_enum.insert("hue", NODE_MIX_HUE); type_enum.insert("saturation", NODE_MIX_SAT); type_enum.insert("value", NODE_MIX_VAL); - type_enum.insert("color", NODE_MIX_COLOR); + type_enum.insert("color", NODE_MIX_COL); type_enum.insert("soft_light", NODE_MIX_SOFT); type_enum.insert("linear_light", NODE_MIX_LINEAR); SOCKET_ENUM(mix_type, "Type", type_enum, NODE_MIX_BLEND); @@ -4999,13 +4999,253 @@ void MixNode::compile(OSLCompiler &compiler) void MixNode::constant_fold(const ConstantFolder &folder) { if (folder.all_inputs_constant()) { - folder.make_constant_clamp(svm_mix(mix_type, fac, color1, color2), use_clamp); + folder.make_constant_clamp(svm_mix_clamped_factor(mix_type, fac, color1, color2), use_clamp); } else { folder.fold_mix(mix_type, use_clamp); } } +/* Mix Color */ + +NODE_DEFINE(MixColorNode) +{ + NodeType *type = NodeType::add("mix_color", create, NodeType::SHADER); + + static NodeEnum type_enum; + type_enum.insert("mix", NODE_MIX_BLEND); + type_enum.insert("add", NODE_MIX_ADD); + type_enum.insert("multiply", NODE_MIX_MUL); + type_enum.insert("screen", NODE_MIX_SCREEN); + type_enum.insert("overlay", NODE_MIX_OVERLAY); + type_enum.insert("subtract", NODE_MIX_SUB); + type_enum.insert("divide", NODE_MIX_DIV); + type_enum.insert("difference", NODE_MIX_DIFF); + type_enum.insert("darken", NODE_MIX_DARK); + type_enum.insert("lighten", NODE_MIX_LIGHT); + type_enum.insert("dodge", NODE_MIX_DODGE); + type_enum.insert("burn", NODE_MIX_BURN); + type_enum.insert("hue", NODE_MIX_HUE); + type_enum.insert("saturation", NODE_MIX_SAT); + type_enum.insert("value", NODE_MIX_VAL); + type_enum.insert("color", NODE_MIX_COL); + type_enum.insert("soft_light", NODE_MIX_SOFT); + type_enum.insert("linear_light", NODE_MIX_LINEAR); + SOCKET_ENUM(blend_type, "Type", type_enum, NODE_MIX_BLEND); + + SOCKET_IN_FLOAT(fac, "Factor", 0.5f); + SOCKET_IN_COLOR(a, "A", zero_float3()); + SOCKET_IN_COLOR(b, "B", zero_float3()); + SOCKET_BOOLEAN(use_clamp_result, "Use Clamp Result", false); + SOCKET_BOOLEAN(use_clamp, "Use Clamp", true); + + SOCKET_OUT_COLOR(result, "Result"); + + return type; +} + +MixColorNode::MixColorNode() : ShaderNode(get_node_type()) +{ +} + +void MixColorNode::compile(SVMCompiler &compiler) +{ + ShaderInput *fac_in = input("Factor"); + ShaderInput *a_in = input("A"); + ShaderInput *b_in = input("B"); + ShaderOutput *result_out = output("Result"); + + int fac_in_stack_offset = compiler.stack_assign(fac_in); + int a_in_stack_offset = compiler.stack_assign(a_in); + int b_in_stack_offset = compiler.stack_assign(b_in); + + compiler.add_node( + NODE_MIX_COLOR, + compiler.encode_uchar4(use_clamp, blend_type, use_clamp_result), + compiler.encode_uchar4(fac_in_stack_offset, a_in_stack_offset, b_in_stack_offset), + compiler.stack_assign(result_out)); +} + +void MixColorNode::compile(OSLCompiler &compiler) +{ + compiler.parameter(this, "blend_type"); + compiler.parameter(this, "use_clamp"); + compiler.parameter(this, "use_clamp_result"); + compiler.add(this, "node_mix_color"); +} + +void MixColorNode::constant_fold(const ConstantFolder &folder) +{ + if (folder.all_inputs_constant()) { + if (use_clamp) { + fac = clamp(fac, 0.0f, 1.0f); + } + folder.make_constant_clamp(svm_mix(blend_type, fac, a, b), use_clamp_result); + } + else { + folder.fold_mix_color(blend_type, use_clamp, use_clamp_result); + } +} + +/* Mix Float */ + +NODE_DEFINE(MixFloatNode) +{ + NodeType *type = NodeType::add("mix_float", create, NodeType::SHADER); + + SOCKET_IN_FLOAT(fac, "Factor", 0.5f); + SOCKET_IN_FLOAT(a, "A", 0.0f); + SOCKET_IN_FLOAT(b, "B", 0.0f); + SOCKET_BOOLEAN(use_clamp, "Use Clamp", true); + SOCKET_OUT_FLOAT(result, "Result"); + + return type; +} + +MixFloatNode::MixFloatNode() : ShaderNode(get_node_type()) +{ +} + +void MixFloatNode::compile(SVMCompiler &compiler) +{ + ShaderInput *fac_in = input("Factor"); + ShaderInput *a_in = input("A"); + ShaderInput *b_in = input("B"); + ShaderOutput *result_out = output("Result"); + + int fac_in_stack_offset = compiler.stack_assign(fac_in); + int a_in_stack_offset = compiler.stack_assign(a_in); + int b_in_stack_offset = compiler.stack_assign(b_in); + + compiler.add_node( + NODE_MIX_FLOAT, + use_clamp, + compiler.encode_uchar4(fac_in_stack_offset, a_in_stack_offset, b_in_stack_offset), + compiler.stack_assign(result_out)); +} + +void MixFloatNode::compile(OSLCompiler &compiler) +{ + compiler.parameter(this, "use_clamp"); + compiler.add(this, "node_mix_float"); +} + +void MixFloatNode::constant_fold(const ConstantFolder &folder) +{ + if (folder.all_inputs_constant()) { + if (use_clamp) { + fac = clamp(fac, 0.0f, 1.0f); + } + folder.make_constant(a * (1 - fac) + b * fac); + } +} + +/* Mix Vector */ + +NODE_DEFINE(MixVectorNode) +{ + NodeType *type = NodeType::add("mix_vector", create, NodeType::SHADER); + + SOCKET_IN_FLOAT(fac, "Factor", 0.5f); + SOCKET_IN_VECTOR(a, "A", zero_float3()); + SOCKET_IN_VECTOR(b, "B", zero_float3()); + SOCKET_BOOLEAN(use_clamp, "Use Clamp", true); + + SOCKET_OUT_VECTOR(result, "Result"); + + return type; +} + +MixVectorNode::MixVectorNode() : ShaderNode(get_node_type()) +{ +} + +void MixVectorNode::compile(SVMCompiler &compiler) +{ + ShaderInput *fac_in = input("Factor"); + ShaderInput *a_in = input("A"); + ShaderInput *b_in = input("B"); + ShaderOutput *result_out = output("Result"); + + int fac_in_stack_offset = compiler.stack_assign(fac_in); + int a_in_stack_offset = compiler.stack_assign(a_in); + int b_in_stack_offset = compiler.stack_assign(b_in); + + compiler.add_node( + NODE_MIX_VECTOR, + compiler.encode_uchar4(use_clamp, fac_in_stack_offset, a_in_stack_offset, b_in_stack_offset), + compiler.stack_assign(result_out)); +} + +void MixVectorNode::compile(OSLCompiler &compiler) +{ + compiler.parameter(this, "use_clamp"); + compiler.add(this, "node_mix_vector"); +} + +void MixVectorNode::constant_fold(const ConstantFolder &folder) +{ + if (folder.all_inputs_constant()) { + if (use_clamp) { + fac = clamp(fac, 0.0f, 1.0f); + } + folder.make_constant(a * (one_float3() - fac) + b * fac); + } +} + +/* Mix Vector Non Uniform */ + +NODE_DEFINE(MixVectorNonUniformNode) +{ + NodeType *type = NodeType::add("mix_vector_non_uniform", create, NodeType::SHADER); + + SOCKET_IN_VECTOR(fac, "Factor", make_float3(0.5f, 0.5f, 0.5f)); + SOCKET_IN_VECTOR(a, "A", zero_float3()); + SOCKET_IN_VECTOR(b, "B", zero_float3()); + SOCKET_BOOLEAN(use_clamp, "Use Clamp", true); + + SOCKET_OUT_VECTOR(result, "Result"); + + return type; +} + +MixVectorNonUniformNode::MixVectorNonUniformNode() : ShaderNode(get_node_type()) +{ +} + +void MixVectorNonUniformNode::compile(SVMCompiler &compiler) +{ + ShaderInput *fac_in = input("Factor"); + ShaderInput *a_in = input("A"); + ShaderInput *b_in = input("B"); + ShaderOutput *result_out = output("Result"); + + int fac_in_stack_offset = compiler.stack_assign(fac_in); + int a_in_stack_offset = compiler.stack_assign(a_in); + int b_in_stack_offset = compiler.stack_assign(b_in); + + compiler.add_node( + NODE_MIX_VECTOR_NON_UNIFORM, + compiler.encode_uchar4(use_clamp, fac_in_stack_offset, a_in_stack_offset, b_in_stack_offset), + compiler.stack_assign(result_out)); +} + +void MixVectorNonUniformNode::compile(OSLCompiler &compiler) +{ + compiler.parameter(this, "use_clamp"); + compiler.add(this, "node_mix_vector_non_uniform"); +} + +void MixVectorNonUniformNode::constant_fold(const ConstantFolder &folder) +{ + if (folder.all_inputs_constant()) { + if (use_clamp) { + fac = saturate(fac); + } + folder.make_constant(a * (one_float3() - fac) + b * fac); + } +} + /* Combine Color */ NODE_DEFINE(CombineColorNode) -- cgit v1.2.3