[Bf-blender-cvs] [31c3476fd31] soc-2018-hair-shader: Add separate sockets for managing melanin coefficients

L. E. Segovia noreply at git.blender.org
Sat Jun 2 20:05:46 CEST 2018


Commit: 31c3476fd31c2e497a3508e3b2390a3f9c18d945
Author: L. E. Segovia
Date:   Sat Jun 2 18:05:21 2018 +0000
Branches: soc-2018-hair-shader
https://developer.blender.org/rB31c3476fd31c2e497a3508e3b2390a3f9c18d945

Add separate sockets for managing melanin coefficients

This patch follows Arnold's nomenclature UI-side
(Melanin = Eumelanin, Melanin Redness = Pheomelanin)

This also disables the relevant sockets when changing parametrizations.

Ref T54796

===================================================================

M	intern/cycles/kernel/shaders/node_principled_hair_bsdf.osl
M	intern/cycles/kernel/svm/svm_closure.h
M	intern/cycles/render/nodes.cpp
M	intern/cycles/render/nodes.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/shader/nodes/node_shader_bsdf_hair_principled.c

===================================================================

diff --git a/intern/cycles/kernel/shaders/node_principled_hair_bsdf.osl b/intern/cycles/kernel/shaders/node_principled_hair_bsdf.osl
index 3b142b516bc..a390e50cbee 100644
--- a/intern/cycles/kernel/shaders/node_principled_hair_bsdf.osl
+++ b/intern/cycles/kernel/shaders/node_principled_hair_bsdf.osl
@@ -21,7 +21,9 @@ color log3 (color a) {
 }
 
 shader node_principled_hair_bsdf(
-	color Color = 0.8, 
+	color Color = 0.8,
+	float Melanin = 0.0,
+	float MelaninRedness = 0.0,
 	normal Normal = Ng,
 	string parametrization = "Absorption coefficient",
 	float Offset = 0,
@@ -41,7 +43,7 @@ shader node_principled_hair_bsdf(
 		Sigma = -log3(max(Color, 1e-5));
 	}
 	else if (parametrization == "Melanin concentration") {
-		Sigma = Color[0]*color(0.419, 0.697, 1.37) + Color[1]*color(0.187, 0.4, 1.05);
+		Sigma = Melanin*color(0.419, 0.697, 1.37) + MelaninRedness*color(0.187, 0.4, 1.05);
 	}
 	else {
 		float roughness_fac = (((((0.245*RoughnessU) + 5.574)*RoughnessU - 10.73)*RoughnessU + 2.532)*RoughnessU - 0.215)*RoughnessU + 5.969;
@@ -49,7 +51,7 @@ shader node_principled_hair_bsdf(
 		Sigma *= Sigma;
 	}
 
-	//printf("Info: color %f, incoming normal %f, parametrization %s, resulting sigma %f, Longitudinal %f, Azimuthal %f, Scale deviation %f, IOR %f\n", Color, Normal, parametrization, Sigma, RoughnessU, RoughnessV, Offset, IOR);
+	//printf("Info: color %f, incoming eumelanin %f, incoming pheomelanin %f, incoming normal %f, parametrization %s, resulting sigma %f, Longitudinal %f, Azimuthal %f, Scale deviation %f, IOR %f\n", Color, Melanin, MelaninRedness, Normal, parametrization, Sigma, RoughnessU, RoughnessV, Offset, IOR);
 
 	BSDF = principled_hair(Normal, Sigma, RoughnessU, RoughnessV, PrimaryReflectionRoughness, Offset, IOR);
 }
diff --git a/intern/cycles/kernel/svm/svm_closure.h b/intern/cycles/kernel/svm/svm_closure.h
index 15f0d997da9..8bbae6e361e 100644
--- a/intern/cycles/kernel/svm/svm_closure.h
+++ b/intern/cycles/kernel/svm/svm_closure.h
@@ -730,10 +730,16 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 			uint offset_ofs, ior_ofs, color_ofs, parametrization;
 			decode_node_uchar4(data_node.y, &offset_ofs, &ior_ofs, &color_ofs, &parametrization);
 
-			float m0_roughness = (stack_valid(data_node2.x))? stack_load_float(stack, data_node2.x): __uint_as_float(data_node2.y);
 			float alpha = (stack_valid(offset_ofs))? stack_load_float(stack, offset_ofs): __uint_as_float(data_node.z);
 			float ior = (stack_valid(ior_ofs))? stack_load_float(stack, ior_ofs): __uint_as_float(data_node.w);
 
+			uint primary_reflection_roughness_ofs, eumelanin_ofs, pheomelanin_ofs;
+			decode_node_uchar4(data_node2.x, &primary_reflection_roughness_ofs, &eumelanin_ofs, &pheomelanin_ofs, NULL);
+
+			float m0_roughness = (stack_valid(primary_reflection_roughness_ofs))? stack_load_float(stack, primary_reflection_roughness_ofs): __uint_as_float(data_node2.y);
+			float eumelanin = (stack_valid(eumelanin_ofs)) ? stack_load_float(stack, eumelanin_ofs) : __uint_as_float(data_node2.z);
+			float pheomelanin = (stack_valid(pheomelanin_ofs)) ? stack_load_float(stack, pheomelanin_ofs) : __uint_as_float(data_node2.w);
+
 			PrincipledHairBSDF *bsdf = (PrincipledHairBSDF*)bsdf_alloc(sd, sizeof(PrincipledHairBSDF), weight);
 			if(bsdf) {
 				PrincipledHairExtra *extra = (PrincipledHairExtra*)closure_alloc_extra(sd, sizeof(PrincipledHairExtra));
@@ -758,7 +764,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 						bsdf->sigma = -log3(max(color, make_float3(1e-5f, 1e-5f, 1e-5f)));
 						break;
 					case NODE_PRINCIPLED_HAIR_PIGMENT_CONCENTRATION:
-						bsdf->sigma = color.x*make_float3(0.419f, 0.697f, 1.37f) + color.y*make_float3(0.187f, 0.4f, 1.05f);
+						bsdf->sigma = eumelanin*make_float3(0.419f, 0.697f, 1.37f) + pheomelanin*make_float3(0.187f, 0.4f, 1.05f);
 						break;
 					default:
 						kernel_assert(!"Invalid Principled Hair parametrization!");
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index a66499db476..f1c440550fd 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -3043,6 +3043,8 @@ NODE_DEFINE(PrincipledHairBsdfNode)
 	NodeType* type = NodeType::add("principled_hair_bsdf", create, NodeType::SHADER);
 
 	SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f));
+	SOCKET_IN_FLOAT(eumelanin, "Melanin", 0.0f);
+	SOCKET_IN_FLOAT(pheomelanin, "Melanin Redness", 0.0f);
 	SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL);
 	SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
 
@@ -3079,6 +3081,8 @@ void PrincipledHairBsdfNode::compile(SVMCompiler& compiler)
 	ShaderInput *offset_in = input("Offset");
 	ShaderInput *primary_reflection_roughness_in = input("Primary Reflection Roughness");
 	ShaderInput *ior_in = input("IOR");
+	ShaderInput *eumelanin_in =  input("Melanin");
+	ShaderInput *pheomelanin_in = input("Melanin Redness");
 
 	int color_ofs = compiler.stack_assign(input("Color"));
 
@@ -3099,10 +3103,15 @@ void PrincipledHairBsdfNode::compile(SVMCompiler& compiler)
 		__float_as_int(offset),
 		__float_as_int(ior));
 
-    compiler.add_node(compiler.stack_assign_if_linked(primary_reflection_roughness_in),
-		__float_as_int(primary_reflection_roughness),
-		SVM_STACK_INVALID,
-		SVM_STACK_INVALID);
+		compiler.add_node(
+			compiler.encode_uchar4(
+				compiler.stack_assign_if_linked(primary_reflection_roughness_in),
+				compiler.stack_assign_if_linked(eumelanin_in),
+				compiler.stack_assign_if_linked(pheomelanin_in),
+				SVM_STACK_INVALID),
+			__float_as_int(primary_reflection_roughness),
+			__float_as_int(eumelanin),
+			__float_as_int(pheomelanin));
 }
 
 void PrincipledHairBsdfNode::compile(OSLCompiler& compiler)
diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h
index 4e55855b3a1..05ced5037ca 100644
--- a/intern/cycles/render/nodes.h
+++ b/intern/cycles/render/nodes.h
@@ -604,18 +604,20 @@ public:
 
 class PrincipledHairBsdfNode : public BsdfBaseNode {
 public:
-    SHADER_NODE_CLASS(PrincipledHairBsdfNode)
-
-    float roughness_u;
-    float roughness_v;
-    float primary_reflection_roughness;
-    float ior;
-    float offset;
-    float3 color;
-
-    float3 normal;
-    float surface_mix_weight;
-    NodePrincipledHairParametrization parametrization;
+	SHADER_NODE_CLASS(PrincipledHairBsdfNode)
+
+	float roughness_u;
+	float roughness_v;
+	float primary_reflection_roughness;
+	float ior;
+	float offset;
+	float3 color;
+	float eumelanin;
+	float pheomelanin;
+
+	float3 normal;
+	float surface_mix_weight;
+	NodePrincipledHairParametrization parametrization;
 };
 
 class HairBsdfNode : public BsdfNode {
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index bdfb166e32c..f338788a796 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -3060,6 +3060,15 @@ static void rna_ShaderNodePrincipled_update(Main *bmain, Scene *scene, PointerRN
 	rna_Node_update(bmain, scene, ptr);
 }
 
+static void rna_ShaderNodeHairPrincipled_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+	bNodeTree *ntree = (bNodeTree *)ptr->id.data;
+	bNode *node = (bNode *)ptr->data;
+	
+	nodeUpdate(ntree, node);
+	rna_Node_update(bmain, scene, ptr);
+}
+
 static void rna_ShaderNodeSubsurface_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
 	bNodeTree *ntree = (bNodeTree *)ptr->id.data;
@@ -3314,10 +3323,10 @@ static const EnumPropertyItem node_hair_items[] = {
 };
 
 static const EnumPropertyItem node_principled_hair_items[] = {
-	{SHD_PRINCIPLED_HAIR_DIRECT_ABSORPTION,     "ABSORPTION", 0, "Absorption coefficient",   "Absorption coefficient", "Directly set the absorption coefficient sigma_a. This is not the most intuitive way to color hair."},
-	{SHD_PRINCIPLED_HAIR_PHYSICAL,              "PHYSICAL",   0, "Physical",                 "Physical",               "Like Absorption, but uses a  logarithmic mapping. For debugging purposes."},
-	{SHD_PRINCIPLED_HAIR_REFLECTANCE,           "COLOR",      0, "Direct coloring",          "Direct coloring",        "Choose the color of your preference, and the shader will approximate the absorption coefficient to render lookalike hair."},
-	{SHD_PRINCIPLED_HAIR_PIGMENT_CONCENTRATION, "MELANIN",    0, "Melanin concentration",    "Melanin concentration",  "Define the melanin concentrations below to get the most realistic-looking hair. You can get the concentrations for different types of hair online."},
+	{SHD_PRINCIPLED_HAIR_DIRECT_ABSORPTION,     "ABSORPTION", 0, "Absorption coefficient",   "Directly set the absorption coefficient sigma_a. This is not the most intuitive way to color hair."},
+	{SHD_PRINCIPLED_HAIR_PHYSICAL,              "PHYSICAL",   0, "Physical",                 "Like Absorption, but uses a  logarithmic mapping. For debugging purposes."},
+	{SHD_PRINCIPLED_HAIR_REFLECTANCE,           "COLOR",      0, "Direct coloring",          "Choose the color of your preference, and the shader will approximate the absorption coefficient to render lookalike hair."},
+	{SHD_PRINCIPLED_HAIR_PIGMENT_CONCENTRATION, "MELANIN",    0, "Melanin concentration",    "Define the melanin concentrations below to get the most realistic-looking hair. You can get the concentrations for different types of hair online."},
 	{0, NULL, 0, NULL, NULL}
 };
 
@@ -4353,14 +4362,14 @@ static void def_hair(StructRNA *srna)
 
 static void def_hair_principled(StructRNA *srna)
 {
-    PropertyRNA *prop;
+	PropertyRNA *prop;
 
-    prop = RNA_def_property(srna, "parametrization", PROP_ENUM, PROP_NONE);
-    RNA_def_property_enum_sdna(prop, NULL, "custom1");
-    RNA_def_property_ui_text(prop, "Color parametrization", "Select the shader's color parametrization");
-    RNA_def_property_enum_items(prop, node_principled_hair_items);
-    RNA_def_property_enum_default(prop, SHD_PRINCIPLED_HAIR_REFLECTANCE);
-    RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+	prop = RNA_def_property(srna, "parametrization", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "custom1");
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list