Refactor: Cycles: Replace fixed Tangent input with custom input
This replaces the fixed Tangent input in BsdfNode::compile with a custom input. This is done because very few nodes actually use the tangent input and it would be better to have this slot available for other inputs on different nodes in the future. Pull Request: https://projects.blender.org/blender/blender/pulls/119042
This commit is contained in:
committed by
Brecht Van Lommel
parent
62151ffaeb
commit
03cb588529
@@ -477,17 +477,17 @@ ccl_device
|
||||
|
||||
/* compute roughness */
|
||||
float anisotropy = clamp(param2, -0.99f, 0.99f);
|
||||
if (data_node.y == SVM_STACK_INVALID || fabsf(anisotropy) <= 1e-4f) {
|
||||
if (data_node.w == SVM_STACK_INVALID || fabsf(anisotropy) <= 1e-4f) {
|
||||
/* Isotropic case. */
|
||||
bsdf->T = zero_float3();
|
||||
bsdf->alpha_x = roughness;
|
||||
bsdf->alpha_y = roughness;
|
||||
}
|
||||
else {
|
||||
bsdf->T = stack_load_float3(stack, data_node.y);
|
||||
bsdf->T = stack_load_float3(stack, data_node.w);
|
||||
|
||||
/* rotate tangent */
|
||||
float rotation = stack_load_float(stack, data_node.z);
|
||||
float rotation = stack_load_float(stack, data_node.y);
|
||||
if (rotation != 0.0f) {
|
||||
bsdf->T = rotate_around_axis(bsdf->T, bsdf->N, rotation * M_2PI_F);
|
||||
}
|
||||
@@ -512,8 +512,8 @@ ccl_device
|
||||
else {
|
||||
sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
|
||||
if (type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID) {
|
||||
kernel_assert(stack_valid(data_node.w));
|
||||
const Spectrum color = rgb_to_spectrum(stack_load_float3(stack, data_node.w));
|
||||
kernel_assert(stack_valid(data_node.z));
|
||||
const Spectrum color = rgb_to_spectrum(stack_load_float3(stack, data_node.z));
|
||||
bsdf_microfacet_setup_fresnel_constant(kg, bsdf, sd, color);
|
||||
}
|
||||
}
|
||||
@@ -585,7 +585,7 @@ ccl_device
|
||||
fresnel->f0 = make_float3(F0_from_ior(ior));
|
||||
fresnel->f90 = one_spectrum();
|
||||
fresnel->exponent = -ior;
|
||||
const float3 color = stack_load_float3(stack, data_node.z);
|
||||
const float3 color = stack_load_float3(stack, data_node.y);
|
||||
fresnel->reflection_tint = reflective_caustics ? rgb_to_spectrum(color) : zero_spectrum();
|
||||
fresnel->transmission_tint = refractive_caustics ? rgb_to_spectrum(color) :
|
||||
zero_spectrum();
|
||||
@@ -834,10 +834,10 @@ ccl_device
|
||||
bsdf->N = maybe_ensure_valid_specular_reflection(sd, N);
|
||||
bsdf->roughness1 = param1;
|
||||
bsdf->roughness2 = param2;
|
||||
bsdf->offset = -stack_load_float(stack, data_node.z);
|
||||
bsdf->offset = -stack_load_float(stack, data_node.y);
|
||||
|
||||
if (stack_valid(data_node.y)) {
|
||||
bsdf->T = normalize(stack_load_float3(stack, data_node.y));
|
||||
if (stack_valid(data_node.w)) {
|
||||
bsdf->T = normalize(stack_load_float3(stack, data_node.w));
|
||||
}
|
||||
else if (!(sd->type & PRIMITIVE_CURVE)) {
|
||||
bsdf->T = normalize(sd->dPdv);
|
||||
@@ -866,12 +866,12 @@ ccl_device
|
||||
ccl_private Bssrdf *bssrdf = bssrdf_alloc(sd, weight);
|
||||
|
||||
if (bssrdf) {
|
||||
bssrdf->radius = rgb_to_spectrum(stack_load_float3(stack, data_node.z) * param1);
|
||||
bssrdf->radius = rgb_to_spectrum(stack_load_float3(stack, data_node.y) * param1);
|
||||
bssrdf->albedo = closure_weight;
|
||||
bssrdf->N = maybe_ensure_valid_specular_reflection(sd, N);
|
||||
bssrdf->ior = param2;
|
||||
bssrdf->alpha = 1.0f;
|
||||
bssrdf->anisotropy = stack_load_float(stack, data_node.w);
|
||||
bssrdf->anisotropy = stack_load_float(stack, data_node.z);
|
||||
|
||||
sd->flag |= bssrdf_setup(sd, bssrdf, path_flag, (ClosureType)type);
|
||||
}
|
||||
|
||||
@@ -2283,14 +2283,14 @@ bool BsdfBaseNode::has_bump()
|
||||
BsdfNode::BsdfNode(const NodeType *node_type) : BsdfBaseNode(node_type) {}
|
||||
|
||||
void BsdfNode::compile(SVMCompiler &compiler,
|
||||
ShaderInput *param1,
|
||||
ShaderInput *param2,
|
||||
ShaderInput *param3,
|
||||
ShaderInput *param4)
|
||||
ShaderInput *bsdf_y,
|
||||
ShaderInput *bsdf_z,
|
||||
ShaderInput *data_y,
|
||||
ShaderInput *data_z,
|
||||
ShaderInput *data_w)
|
||||
{
|
||||
ShaderInput *color_in = input("Color");
|
||||
ShaderInput *normal_in = input("Normal");
|
||||
ShaderInput *tangent_in = input("Tangent");
|
||||
|
||||
if (color_in->link) {
|
||||
compiler.add_node(NODE_CLOSURE_WEIGHT, compiler.stack_assign(color_in));
|
||||
@@ -2300,21 +2300,20 @@ void BsdfNode::compile(SVMCompiler &compiler,
|
||||
}
|
||||
|
||||
int normal_offset = (normal_in) ? compiler.stack_assign_if_linked(normal_in) : SVM_STACK_INVALID;
|
||||
int tangent_offset = (tangent_in) ? compiler.stack_assign_if_linked(tangent_in) :
|
||||
SVM_STACK_INVALID;
|
||||
int param3_offset = (param3) ? compiler.stack_assign(param3) : SVM_STACK_INVALID;
|
||||
int param4_offset = (param4) ? compiler.stack_assign(param4) : SVM_STACK_INVALID;
|
||||
int data_y_offset = (data_y) ? compiler.stack_assign(data_y) : SVM_STACK_INVALID;
|
||||
int data_z_offset = (data_z) ? compiler.stack_assign(data_z) : SVM_STACK_INVALID;
|
||||
int data_w_offset = (data_w) ? compiler.stack_assign(data_w) : SVM_STACK_INVALID;
|
||||
|
||||
compiler.add_node(
|
||||
NODE_CLOSURE_BSDF,
|
||||
compiler.encode_uchar4(closure,
|
||||
(param1) ? compiler.stack_assign(param1) : SVM_STACK_INVALID,
|
||||
(param2) ? compiler.stack_assign(param2) : SVM_STACK_INVALID,
|
||||
(bsdf_y) ? compiler.stack_assign(bsdf_y) : SVM_STACK_INVALID,
|
||||
(bsdf_z) ? compiler.stack_assign(bsdf_z) : SVM_STACK_INVALID,
|
||||
compiler.closure_mix_weight_offset()),
|
||||
__float_as_int((param1) ? get_float(param1->socket_type) : 0.0f),
|
||||
__float_as_int((param2) ? get_float(param2->socket_type) : 0.0f));
|
||||
__float_as_int((bsdf_y) ? get_float(bsdf_y->socket_type) : 0.0f),
|
||||
__float_as_int((bsdf_z) ? get_float(bsdf_z->socket_type) : 0.0f));
|
||||
|
||||
compiler.add_node(normal_offset, tangent_offset, param3_offset, param4_offset);
|
||||
compiler.add_node(normal_offset, data_y_offset, data_z_offset, data_w_offset);
|
||||
}
|
||||
|
||||
void BsdfNode::compile(SVMCompiler &compiler)
|
||||
@@ -2392,13 +2391,21 @@ void GlossyBsdfNode::compile(SVMCompiler &compiler)
|
||||
{
|
||||
closure = distribution;
|
||||
|
||||
ShaderInput *tangent = input("Tangent");
|
||||
tangent = compiler.is_linked(tangent) ? tangent : nullptr;
|
||||
|
||||
/* TODO: Just use weight for legacy MultiGGX? Would also simplify OSL. */
|
||||
if (closure == CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID) {
|
||||
BsdfNode::compile(
|
||||
compiler, input("Roughness"), input("Anisotropy"), input("Rotation"), input("Color"));
|
||||
BsdfNode::compile(compiler,
|
||||
input("Roughness"),
|
||||
input("Anisotropy"),
|
||||
input("Rotation"),
|
||||
input("Color"),
|
||||
tangent);
|
||||
}
|
||||
else {
|
||||
BsdfNode::compile(compiler, input("Roughness"), input("Anisotropy"), input("Rotation"));
|
||||
BsdfNode::compile(
|
||||
compiler, input("Roughness"), input("Anisotropy"), input("Rotation"), nullptr, tangent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3535,7 +3542,11 @@ void HairBsdfNode::compile(SVMCompiler &compiler)
|
||||
{
|
||||
closure = component;
|
||||
|
||||
BsdfNode::compile(compiler, input("RoughnessU"), input("RoughnessV"), input("Offset"));
|
||||
ShaderInput *tangent = input("Tangent");
|
||||
tangent = compiler.is_linked(tangent) ? tangent : nullptr;
|
||||
|
||||
BsdfNode::compile(
|
||||
compiler, input("RoughnessU"), input("RoughnessV"), input("Offset"), nullptr, tangent);
|
||||
}
|
||||
|
||||
void HairBsdfNode::compile(OSLCompiler &compiler)
|
||||
|
||||
@@ -479,10 +479,11 @@ class BsdfNode : public BsdfBaseNode {
|
||||
SHADER_NODE_BASE_CLASS(BsdfNode)
|
||||
|
||||
void compile(SVMCompiler &compiler,
|
||||
ShaderInput *param1,
|
||||
ShaderInput *param2,
|
||||
ShaderInput *param3 = NULL,
|
||||
ShaderInput *param4 = NULL);
|
||||
ShaderInput *bsdf_y,
|
||||
ShaderInput *bsdf_z,
|
||||
ShaderInput *data_y = nullptr,
|
||||
ShaderInput *data_z = nullptr,
|
||||
ShaderInput *data_w = nullptr);
|
||||
|
||||
NODE_SOCKET_API(float3, color)
|
||||
NODE_SOCKET_API(float3, normal)
|
||||
|
||||
@@ -294,9 +294,14 @@ int SVMCompiler::stack_assign(ShaderOutput *output)
|
||||
return output->stack_offset;
|
||||
}
|
||||
|
||||
bool SVMCompiler::is_linked(ShaderInput *input)
|
||||
{
|
||||
return (input->link || input->constant_folded_in);
|
||||
}
|
||||
|
||||
int SVMCompiler::stack_assign_if_linked(ShaderInput *input)
|
||||
{
|
||||
if (input->link || input->constant_folded_in) {
|
||||
if (is_linked(input)) {
|
||||
return stack_assign(input);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ class SVMCompiler {
|
||||
|
||||
int stack_assign(ShaderOutput *output);
|
||||
int stack_assign(ShaderInput *input);
|
||||
bool is_linked(ShaderInput *input);
|
||||
int stack_assign_if_linked(ShaderInput *input);
|
||||
int stack_assign_if_linked(ShaderOutput *output);
|
||||
int stack_find_offset(int size);
|
||||
|
||||
Reference in New Issue
Block a user