Cleanup: Remove unused custom data type

`CD_HAIRLENGTH` is not really a custom data type, it was just used to
specify the hair particle "length" attribute to pass it to EEVEE and
material preview. Because of the "typemap" array in `CustomData`,
it's better not to have this unnecessary type. Instead, use the same
mechanism used to request the active color attribute.

Pull Request: https://projects.blender.org/blender/blender/pulls/109449
This commit is contained in:
Hans Goudey 2023-06-28 17:17:31 +02:00 committed by Hans Goudey
parent 12a10448f9
commit a1cc621e1e
6 changed files with 51 additions and 26 deletions

View File

@ -1946,7 +1946,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
nullptr,
nullptr,
nullptr},
/* 51: CD_HAIRLENGTH */
/* 51: CD_HAIRLENGTH */ /* DEPRECATED */ /* UNUSED */
{sizeof(float), "float", 1, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* 52: CD_PROP_QUATERNION */
{sizeof(float[4]),

View File

@ -155,6 +155,10 @@ GPUNodeLink *GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *n
* The name, type, and domain are unknown and do not depend on the material.
*/
GPUNodeLink *GPU_attribute_default_color(GPUMaterial *mat);
/**
* Add a GPU attribute that refers to the approximate length of curves/hairs.
*/
GPUNodeLink *GPU_attribute_hair_length(GPUMaterial *mat);
GPUNodeLink *GPU_attribute_with_default(GPUMaterial *mat,
eCustomDataType type,
const char *name,
@ -344,6 +348,10 @@ typedef struct GPUMaterialAttribute {
* valid here.
*/
bool is_default_color;
/**
* If true, the attribute is the length of hair particles and curves.
*/
bool is_hair_length;
} GPUMaterialAttribute;
typedef struct GPUMaterialTexture {

View File

@ -364,25 +364,27 @@ void GPUCodegen::generate_attribs()
eGPUType input_type, iface_type;
load_ss << "var_attrs." << var_name;
switch (attr->type) {
case CD_ORCO:
/* Need vec4 to detect usage of default attribute. */
input_type = GPU_VEC4;
iface_type = GPU_VEC3;
load_ss << " = attr_load_orco(" << attr_name << ");\n";
break;
case CD_HAIRLENGTH:
iface_type = input_type = GPU_FLOAT;
load_ss << " = attr_load_" << input_type << "(" << attr_name << ");\n";
break;
case CD_TANGENT:
iface_type = input_type = GPU_VEC4;
load_ss << " = attr_load_tangent(" << attr_name << ");\n";
break;
default:
iface_type = input_type = GPU_VEC4;
load_ss << " = attr_load_" << input_type << "(" << attr_name << ");\n";
break;
if (attr->is_hair_length) {
iface_type = input_type = GPU_FLOAT;
load_ss << " = attr_load_" << input_type << "(" << attr_name << ");\n";
}
else {
switch (attr->type) {
case CD_ORCO:
/* Need vec4 to detect usage of default attribute. */
input_type = GPU_VEC4;
iface_type = GPU_VEC3;
load_ss << " = attr_load_orco(" << attr_name << ");\n";
break;
case CD_TANGENT:
iface_type = input_type = GPU_VEC4;
load_ss << " = attr_load_tangent(" << attr_name << ");\n";
break;
default:
iface_type = input_type = GPU_VEC4;
load_ss << " = attr_load_" << input_type << "(" << attr_name << ");\n";
break;
}
}
info.vertex_in(slot--, to_type(input_type), attr_name);

View File

@ -347,13 +347,14 @@ static char attr_prefix_get(GPUMaterialAttribute *attr)
if (attr->is_default_color) {
return 'c';
}
if (attr->is_hair_length) {
return 'l';
}
switch (attr->type) {
case CD_TANGENT:
return 't';
case CD_AUTO_FROM_NAME:
return 'a';
case CD_HAIRLENGTH:
return 'l';
default:
BLI_assert_msg(0, "GPUVertAttr Prefix type not found : This should not happen!");
return '\0';
@ -555,6 +556,21 @@ GPUNodeLink *GPU_attribute_default_color(GPUMaterial *mat)
return link;
}
GPUNodeLink *GPU_attribute_hair_length(GPUMaterial *mat)
{
GPUNodeGraph *graph = gpu_material_node_graph(mat);
GPUMaterialAttribute *attr = gpu_node_graph_add_attribute(graph, CD_AUTO_FROM_NAME, "", true);
if (attr == nullptr) {
static const float zero_data[GPU_MAX_CONSTANT_DATA] = {0.0f};
return GPU_constant(zero_data);
}
attr->is_hair_length = true;
GPUNodeLink *link = gpu_node_link_create();
link->link_type = GPU_NODE_LINK_ATTR;
link->attr = attr;
return link;
}
GPUNodeLink *GPU_attribute_with_default(GPUMaterial *mat,
const eCustomDataType type,
const char *name,

View File

@ -178,7 +178,8 @@ typedef enum eCustomDataType {
CD_PROP_FLOAT2 = 49,
CD_PROP_BOOL = 50,
CD_HAIRLENGTH = 51,
/* CD_HAIRLENGTH = 51, */ /* UNUSED */
CD_PROP_QUATERNION = 52,
CD_NUMTYPES = 53,
@ -224,8 +225,6 @@ typedef enum eCustomDataType {
#define CD_MASK_PROP_INT32_2D (1ULL << CD_PROP_INT32_2D)
#define CD_MASK_PROP_QUATERNION (1ULL << CD_PROP_QUATERNION)
#define CD_MASK_HAIRLENGTH (1ULL << CD_HAIRLENGTH)
/** Multi-resolution loop data. */
#define CD_MASK_MULTIRES_GRIDS (CD_MASK_MDISPS | CD_GRID_PAINT_MASK)

View File

@ -24,7 +24,7 @@ static int node_shader_gpu_hair_info(GPUMaterial *mat,
{
/* Length: don't request length if not needed. */
static const float zero = 0;
GPUNodeLink *length_link = out[2].hasoutput ? GPU_attribute(mat, CD_HAIRLENGTH, "") :
GPUNodeLink *length_link = out[2].hasoutput ? GPU_attribute_hair_length(mat) :
GPU_constant(&zero);
return GPU_stack_link(mat, node, "node_hair_info", in, out, length_link);
}