Cycles: new Microfacet-based Hair BSDF with elliptical cross-section support #105600

Merged
Weizhen Huang merged 114 commits from weizhen/blender:microfacet_hair into main 2023-08-18 12:46:20 +02:00
2 changed files with 29 additions and 27 deletions
Showing only changes of commit e888002668 - Show all commits

View File

@ -586,18 +586,18 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
float alpha = stack_load_float_default(stack, offset_ofs, data_node.z);
float ior = stack_load_float_default(stack, ior_ofs, data_node.w);
uint shared_ofs1, melanin_ofs, melanin_redness_ofs, absorption_coefficient_ofs;
uint tint_ofs, melanin_ofs, melanin_redness_ofs, absorption_coefficient_ofs;
svm_unpack_node_uchar4(data_node2.x,
&shared_ofs1,
&tint_ofs,
&melanin_ofs,
&melanin_redness_ofs,
&absorption_coefficient_ofs);
uint tint_ofs, random_ofs, random_color_ofs, shared_ofs2;
uint shared_ofs1, random_ofs, random_color_ofs, shared_ofs2;
svm_unpack_node_uchar4(
data_node3.x, &tint_ofs, &random_ofs, &random_color_ofs, &shared_ofs2);
data_node3.x, &shared_ofs1, &random_ofs, &random_color_ofs, &shared_ofs2);
const AttributeDescriptor attr_descr_random = find_attribute(kg, sd, data_node3.w);
const AttributeDescriptor attr_descr_random = find_attribute(kg, sd, data_node2.y);
float random = 0.0f;
if (attr_descr_random.offset != ATTR_STD_NOT_FOUND) {
random = primitive_surface_attribute_float(kg, sd, attr_descr_random, NULL, NULL);
@ -676,10 +676,9 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
}
/* Remap Coat value to [0, 100]% of Roughness. */
float coat = stack_load_float_default(stack, shared_ofs1, data_node2.y);
float coat = stack_load_float_default(stack, shared_ofs1, data_node3.w);
float m0_roughness = 1.0f - clamp(coat, 0.0f, 1.0f);
bsdf->N = maybe_ensure_valid_specular_reflection(sd, N);
bsdf->v = roughness;
bsdf->s = radial_roughness;
bsdf->m0_roughness = m0_roughness;
@ -703,8 +702,8 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
break;
}
uint R_ofs, TT_ofs, TRT_ofs, temp;
svm_unpack_node_uchar4(data_node4.x, &R_ofs, &TT_ofs, &TRT_ofs, &temp);
uint R_ofs, TT_ofs, TRT_ofs, unused;
svm_unpack_node_uchar4(data_node4.x, &R_ofs, &TT_ofs, &TRT_ofs, &unused);
float R = stack_load_float_default(stack, R_ofs, data_node4.y);
float TT = stack_load_float_default(stack, TT_ofs, data_node4.z);
float TRT = stack_load_float_default(stack, TRT_ofs, data_node4.w);
@ -714,7 +713,7 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
bsdf->extra->TT = fmaxf(0.0f, TT);
bsdf->extra->TRT = fmaxf(0.0f, TRT);
bsdf->aspect_ratio = stack_load_float_default(stack, shared_ofs1, data_node2.y);
bsdf->aspect_ratio = stack_load_float_default(stack, shared_ofs1, data_node3.w);
if (bsdf->aspect_ratio != 1.0f) {
/* Align ellipse major axis with the curve normal direction. */
const AttributeDescriptor attr_descr_normal = find_attribute(kg, sd, shared_ofs2);

View File

@ -3513,32 +3513,35 @@ void PrincipledHairBsdfNode::compile(SVMCompiler &compiler)
__float_as_uint(random_roughness));
/* data node */
compiler.add_node(model,
compiler.add_node(SVM_STACK_INVALID,
compiler.encode_uchar4(offset_ofs, ior_ofs, color_ofs, parametrization),
__float_as_uint(offset),
__float_as_uint(ior));
/* data node 2 */
compiler.add_node(compiler.encode_uchar4(model == NODE_PRINCIPLED_HAIR_HUANG ?
compiler.stack_assign_if_linked(aspect_ratio_in) :
coat_ofs,
melanin_ofs,
melanin_redness_ofs,
absorption_coefficient_ofs),
__float_as_uint(model == NODE_PRINCIPLED_HAIR_HUANG ? aspect_ratio : coat),
compiler.add_node(compiler.encode_uchar4(
tint_ofs, melanin_ofs, melanin_redness_ofs, absorption_coefficient_ofs),
attr_random,
__float_as_uint(melanin),
__float_as_uint(melanin_redness));
/* data node 3 */
compiler.add_node(compiler.encode_uchar4(tint_ofs,
random_in_ofs,
random_color_ofs,
model == NODE_PRINCIPLED_HAIR_HUANG ?
compiler.attribute(ATTR_STD_VERTEX_NORMAL) :
radial_roughness_ofs),
__float_as_uint(random),
__float_as_uint(random_color),
attr_random);
if (model == NODE_PRINCIPLED_HAIR_HUANG) {
compiler.add_node(compiler.encode_uchar4(compiler.stack_assign_if_linked(aspect_ratio_in),
random_in_ofs,
random_color_ofs,
compiler.attribute(ATTR_STD_VERTEX_NORMAL)),
__float_as_uint(random),
__float_as_uint(random_color),
__float_as_uint(aspect_ratio));
}
else {
compiler.add_node(
compiler.encode_uchar4(coat_ofs, random_in_ofs, random_color_ofs, radial_roughness_ofs),
__float_as_uint(random),
__float_as_uint(random_color),
__float_as_uint(coat));
}
/* data node 4 */
compiler.add_node(compiler.encode_uchar4(compiler.stack_assign_if_linked(R_in),