Replace legacy custom fields with node storage struct

This commit is contained in:
Weizhen Huang 2023-01-12 17:55:01 +01:00
parent 9b99cc216b
commit 0da0f29c17
3 changed files with 27 additions and 19 deletions

View File

@ -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];

View File

@ -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");
}

View File

@ -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);
}