[Bf-blender-cvs] [0da0f29c171] microfacet_hair: Replace legacy custom fields with node storage struct

Weizhen Huang noreply at git.blender.org
Thu Jan 12 17:55:49 CET 2023


Commit: 0da0f29c1714db0001ea8c785fe2a625620db020
Author: Weizhen Huang
Date:   Thu Jan 12 17:55:01 2023 +0100
Branches: microfacet_hair
https://developer.blender.org/rB0da0f29c1714db0001ea8c785fe2a625620db020

Replace legacy custom fields with node storage struct

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

M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/shader/nodes/node_shader_bsdf_hair_microfacet.cc

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

diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 11e44cbf6f6..23755425ddf 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -322,8 +322,10 @@ typedef struct bNode {
    */
   int16_t type;
 
+  char _pad1[2];
+
   /** Used for some builtin nodes that store properties but don't have a storage struct . */
-  int16_t custom0, custom1, custom2;
+  int16_t custom1, custom2;
   float custom3, custom4;
 
   /** Optional link to libdata. */
@@ -1146,6 +1148,13 @@ typedef struct NodeShaderPrincipled {
   char _pad[3];
 } NodeShaderPrincipled;
 
+typedef struct NodeShaderHairMicrofacet {
+  short parametrization;
+  short cross_section;
+  short distribution;
+  char _pad[2];
+} NodeShaderHairMicrofacet;
+
 /** TEX_output. */
 typedef struct TexNodeOutput {
   char name[64];
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 87231edabc1..a47251b9940 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -6224,34 +6224,27 @@ static void def_hair_microfacet(StructRNA *srna)
 {
   PropertyRNA *prop;
 
+  RNA_def_struct_sdna_from(srna, "NodeShaderHairMicrofacet", "storage");
+
   prop = RNA_def_property(srna, "parametrization", PROP_ENUM, PROP_NONE);
-  RNA_def_property_enum_sdna(prop, NULL, "custom0");
+  RNA_def_property_enum_sdna(prop, NULL, "parametrization");
   RNA_def_property_ui_text(
       prop, "Color Parametrization", "Select the shader's color parametrization");
   RNA_def_property_enum_items(prop, node_microfacet_hair_parametrization_items);
-  RNA_def_property_enum_default(prop, SHD_MICROFACET_HAIR_REFLECTANCE);
-  /* Upon editing, update both the node data AND the UI representation */
-  /* (This effectively shows/hides the relevant sockets) */
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_ShaderNode_socket_update");
 
   prop = RNA_def_property(srna, "cross_section_type", PROP_ENUM, PROP_NONE);
-  RNA_def_property_enum_sdna(prop, NULL, "custom1");
+  RNA_def_property_enum_sdna(prop, NULL, "cross_section");
   RNA_def_property_ui_text(
       prop, "Hair Cross Section Shape", "Select the hair's cross section shape");
   RNA_def_property_enum_items(prop, node_microfacet_hair_cross_section_items);
-  RNA_def_property_enum_default(prop, SHD_MICROFACET_HAIR_CIRCULAR);
-  /* Upon editing, update both the node data AND the UI representation */
-  /* (This effectively shows/hides the relevant sockets) */
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_ShaderNode_socket_update");
 
   prop = RNA_def_property(srna, "distribution_type", PROP_ENUM, PROP_NONE);
-  RNA_def_property_enum_sdna(prop, NULL, "custom2");
+  RNA_def_property_enum_sdna(prop, NULL, "distribution");
   RNA_def_property_ui_text(
       prop, "Microfacet Distribution", "Select the microfacet distribution of the hair surface");
   RNA_def_property_enum_items(prop, node_microfacet_hair_distribution_items);
-  RNA_def_property_enum_default(prop, SHD_MICROFACET_HAIR_GGX);
-  /* Upon editing, update both the node data AND the UI representation */
-  /* (This effectively shows/hides the relevant sockets) */
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_ShaderNode_socket_update");
 }
 
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_hair_microfacet.cc b/source/blender/nodes/shader/nodes/node_shader_bsdf_hair_microfacet.cc
index a6f08769d2f..d864dd2cf5c 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_hair_microfacet.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_hair_microfacet.cc
@@ -119,18 +119,22 @@ static void node_shader_buts_microfacet_hair(uiLayout *layout, bContext * /*C*/,
 /* Initialize the custom Parametrization property to Color. */
 static void node_shader_init_hair_microfacet(bNodeTree * /*ntree*/, bNode *node)
 {
-  node->custom0 = SHD_MICROFACET_HAIR_REFLECTANCE;
-  node->custom1 = SHD_MICROFACET_HAIR_CIRCULAR;
-  node->custom2 = SHD_MICROFACET_HAIR_GGX;
+  NodeShaderHairMicrofacet *data = MEM_cnew<NodeShaderHairMicrofacet>(__func__);
+
+  data->parametrization = SHD_MICROFACET_HAIR_REFLECTANCE;
+  data->cross_section = SHD_MICROFACET_HAIR_CIRCULAR;
+  data->distribution = SHD_MICROFACET_HAIR_GGX;
+
+  node->storage = data;
 }
 
 /* Triggers (in)visibility of some sockets when changing Parametrization. */
 static void node_shader_update_hair_microfacet(bNodeTree *ntree, bNode *node)
 {
-  int parametrization = node->custom0;
-  int cross_section_type = node->custom1;
+  NodeShaderHairMicrofacet *data = static_cast<NodeShaderHairMicrofacet *>(node->storage);
 
-  bool elliptical = (cross_section_type == SHD_MICROFACET_HAIR_ELLIPTIC);
+  int parametrization = data->parametrization;
+  bool elliptical = (data->cross_section == SHD_MICROFACET_HAIR_ELLIPTIC);
 
   LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
     if (STREQ(sock->name, "Color")) {
@@ -188,6 +192,8 @@ void register_node_type_sh_bsdf_hair_microfacet()
   ntype.initfunc = file_ns::node_shader_init_hair_microfacet;
   ntype.updatefunc = file_ns::node_shader_update_hair_microfacet;
   ntype.gpu_fn = file_ns::node_shader_gpu_hair_microfacet;
+  node_type_storage(
+      &ntype, "NodeShaderHairMicrofacet", node_free_standard_storage, node_copy_standard_storage);
 
   nodeRegisterType(&ntype);
 }



More information about the Bf-blender-cvs mailing list