Fix T45058: Cycles hair shader reflects incorrectly for meshes

The issue was caused by non-continuous tangent space calculated for triangles.

This commit adds a Tangent input to Hair BSDF node which can be used to hook up
Tangent calculated form UV as an input to the node in order to make sure the
tangent space is continuous.

Doing this as an input instead of using default tangent layer from UV because of
several reasons:

- This way it's really easy to preserve compatibility with existing setups.

- Default UV map is not necessarily giving continuous space, one might want to
  use other tangent space sources or distort the space for some artistic
  decision.

Reviewers: juicyfruit, dingto

Reviewed By: dingto

Differential Revision: https://developer.blender.org/D1428
This commit is contained in:
Sergey Sharybin 2015-10-11 19:43:30 +05:00
parent 34e7285b0a
commit 3f4c0612fe
Notes: blender-bot 2023-10-12 12:49:04 +02:00
Referenced by issue #45058, Cycles hair shader reflects incorrectly for meshes
3 changed files with 8 additions and 2 deletions

View File

@ -411,7 +411,10 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
sc->data1 = param2;
sc->data2 = -stack_load_float(stack, data_node.z);
if(!(ccl_fetch(sd, type) & PRIMITIVE_ALL_CURVE)) {
if(stack_valid(data_node.y)) {
sc->T = normalize(stack_load_float3(stack, data_node.y));
}
else if(!(ccl_fetch(sd, type) & PRIMITIVE_ALL_CURVE)) {
sc->T = normalize(ccl_fetch(sd, dPdv));
sc->data2 = 0.0f;
}

View File

@ -2358,6 +2358,7 @@ HairBsdfNode::HairBsdfNode()
add_input("Offset", SHADER_SOCKET_FLOAT);
add_input("RoughnessU", SHADER_SOCKET_FLOAT);
add_input("RoughnessV", SHADER_SOCKET_FLOAT);
add_input("Tangent", SHADER_SOCKET_VECTOR);
}
void HairBsdfNode::compile(SVMCompiler& compiler)

View File

@ -33,7 +33,9 @@ static bNodeSocketTemplate sh_node_bsdf_hair_in[] = {
{ SOCK_RGBA, 1, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
{ SOCK_FLOAT, 1, N_("Offset"), 0.0f, 0.0f, 0.0f, 0.0f, -M_PI_2, M_PI_2, PROP_ANGLE},
{ SOCK_FLOAT, 1, N_("RoughnessU"), 0.1f, 0.1f, 0.1f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
{ SOCK_FLOAT, 1, N_("RoughnessV"), 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, { -1, 0, "" }
{ SOCK_FLOAT, 1, N_("RoughnessV"), 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
{ SOCK_VECTOR, 1, N_("Tangent"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
{ -1, 0, "" },
};
static bNodeSocketTemplate sh_node_bsdf_hair_out[] = {