Shaders: rename Specular to Specular IOR Level in Principled BSDF

To clarify that this is no longer the primary control, but rather
and adjustment on IOR.

Ref #99447
Ref #112552
This commit is contained in:
Brecht Van Lommel
2023-09-25 12:52:13 +02:00
parent 239edb27ad
commit 1d265eed5d
15 changed files with 34 additions and 33 deletions

View File

@@ -14,7 +14,7 @@ shader node_principled_bsdf(string distribution = "multi_ggx",
float SubsurfaceIOR = 1.4, float SubsurfaceIOR = 1.4,
float SubsurfaceAnisotropy = 0.0, float SubsurfaceAnisotropy = 0.0,
float Metallic = 0.0, float Metallic = 0.0,
float Specular = 0.5, float SpecularIORLevel = 0.5,
color SpecularTint = color(1.0), color SpecularTint = color(1.0),
float Roughness = 0.5, float Roughness = 0.5,
float Anisotropic = 0.0, float Anisotropic = 0.0,
@@ -56,8 +56,8 @@ shader node_principled_bsdf(string distribution = "multi_ggx",
if (Metallic < 1.0 && Transmission < 1.0) { if (Metallic < 1.0 && Transmission < 1.0) {
float eta = IOR; float eta = IOR;
float f0 = F0_from_ior(eta); float f0 = F0_from_ior(eta);
if (Specular != 0.5) { if (SpecularIORLevel != 0.5) {
f0 *= 2.0 * max(Specular, 0.0); f0 *= 2.0 * max(SpecularIORLevel, 0.0);
eta = ior_from_F0(f0); eta = ior_from_F0(f0);
if (IOR < 1.0) { if (IOR < 1.0) {
eta = 1.0 / eta; eta = 1.0 / eta;

View File

@@ -74,7 +74,7 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
switch (type) { switch (type) {
case CLOSURE_BSDF_PRINCIPLED_ID: { case CLOSURE_BSDF_PRINCIPLED_ID: {
uint specular_offset, roughness_offset, specular_tint_offset, anisotropic_offset, uint specular_ior_level_offset, roughness_offset, specular_tint_offset, anisotropic_offset,
sheen_offset, sheen_tint_offset, sheen_roughness_offset, coat_offset, sheen_offset, sheen_tint_offset, sheen_roughness_offset, coat_offset,
coat_roughness_offset, coat_ior_offset, eta_offset, transmission_offset, coat_roughness_offset, coat_ior_offset, eta_offset, transmission_offset,
anisotropic_rotation_offset, coat_tint_offset, coat_normal_offset, dummy, alpha_offset, anisotropic_rotation_offset, coat_tint_offset, coat_normal_offset, dummy, alpha_offset,
@@ -83,7 +83,7 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
float3 T = stack_load_float3(stack, data_node.y); float3 T = stack_load_float3(stack, data_node.y);
svm_unpack_node_uchar4(data_node.z, svm_unpack_node_uchar4(data_node.z,
&specular_offset, &specular_ior_level_offset,
&roughness_offset, &roughness_offset,
&specular_tint_offset, &specular_tint_offset,
&anisotropic_offset); &anisotropic_offset);
@@ -327,8 +327,8 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
/* Apply IOR adjustment */ /* Apply IOR adjustment */
float eta = ior; float eta = ior;
float f0 = F0_from_ior(eta); float f0 = F0_from_ior(eta);
if (specular != 0.5f) { if (specular_ior_level != 0.5f) {
f0 *= 2.0f * specular; f0 *= 2.0f * specular_ior_level;
eta = ior_from_F0(f0); eta = ior_from_F0(f0);
if (ior < 1.0f) { if (ior < 1.0f) {
eta = 1.0f / eta; eta = 1.0f / eta;

View File

@@ -2704,7 +2704,7 @@ NODE_DEFINE(PrincipledBsdfNode)
SOCKET_IN_VECTOR(subsurface_radius, "Subsurface Radius", make_float3(0.1f, 0.1f, 0.1f)); SOCKET_IN_VECTOR(subsurface_radius, "Subsurface Radius", make_float3(0.1f, 0.1f, 0.1f));
SOCKET_IN_FLOAT(subsurface_ior, "Subsurface IOR", 1.4f); SOCKET_IN_FLOAT(subsurface_ior, "Subsurface IOR", 1.4f);
SOCKET_IN_FLOAT(subsurface_anisotropy, "Subsurface Anisotropy", 0.0f); SOCKET_IN_FLOAT(subsurface_anisotropy, "Subsurface Anisotropy", 0.0f);
SOCKET_IN_FLOAT(specular, "Specular", 0.0f); SOCKET_IN_FLOAT(specular_ior_level, "Specular IOR Level", 0.0f);
SOCKET_IN_FLOAT(roughness, "Roughness", 0.5f); SOCKET_IN_FLOAT(roughness, "Roughness", 0.5f);
SOCKET_IN_COLOR(specular_tint, "Specular Tint", one_float3()); SOCKET_IN_COLOR(specular_tint, "Specular Tint", one_float3());
SOCKET_IN_FLOAT(anisotropic, "Anisotropic", 0.0f); SOCKET_IN_FLOAT(anisotropic, "Anisotropic", 0.0f);
@@ -2802,7 +2802,7 @@ void PrincipledBsdfNode::compile(SVMCompiler &compiler)
int normal_offset = compiler.stack_assign_if_linked(input("Normal")); int normal_offset = compiler.stack_assign_if_linked(input("Normal"));
int coat_normal_offset = compiler.stack_assign_if_linked(input("Coat Normal")); int coat_normal_offset = compiler.stack_assign_if_linked(input("Coat Normal"));
int tangent_offset = compiler.stack_assign_if_linked(input("Tangent")); int tangent_offset = compiler.stack_assign_if_linked(input("Tangent"));
int specular_offset = compiler.stack_assign(input("Specular")); int specular_ior_level_offset = compiler.stack_assign(input("Specular IOR Level"));
int roughness_offset = compiler.stack_assign(input("Roughness")); int roughness_offset = compiler.stack_assign(input("Roughness"));
int specular_tint_offset = compiler.stack_assign(input("Specular Tint")); int specular_tint_offset = compiler.stack_assign(input("Specular Tint"));
int anisotropic_offset = compiler.stack_assign(input("Anisotropic")); int anisotropic_offset = compiler.stack_assign(input("Anisotropic"));
@@ -2836,7 +2836,7 @@ void PrincipledBsdfNode::compile(SVMCompiler &compiler)
normal_offset, normal_offset,
tangent_offset, tangent_offset,
compiler.encode_uchar4( compiler.encode_uchar4(
specular_offset, roughness_offset, specular_tint_offset, anisotropic_offset), specular_ior_level_offset, roughness_offset, specular_tint_offset, anisotropic_offset),
compiler.encode_uchar4(sheen_offset, sheen_tint_offset, sheen_roughness_offset)); compiler.encode_uchar4(sheen_offset, sheen_tint_offset, sheen_roughness_offset));
compiler.add_node( compiler.add_node(

View File

@@ -525,7 +525,7 @@ class PrincipledBsdfNode : public BsdfBaseNode {
NODE_SOCKET_API(float, subsurface_anisotropy) NODE_SOCKET_API(float, subsurface_anisotropy)
NODE_SOCKET_API(float, metallic) NODE_SOCKET_API(float, metallic)
NODE_SOCKET_API(float, subsurface) NODE_SOCKET_API(float, subsurface)
NODE_SOCKET_API(float, specular) NODE_SOCKET_API(float, specular_ior_level)
NODE_SOCKET_API(float, roughness) NODE_SOCKET_API(float, roughness)
NODE_SOCKET_API(float3, specular_tint) NODE_SOCKET_API(float3, specular_tint)
NODE_SOCKET_API(float, anisotropic) NODE_SOCKET_API(float, anisotropic)

View File

@@ -281,14 +281,14 @@ class PrincipledBSDFWrapper(ShaderWrapper):
def specular_get(self): def specular_get(self):
if not self.use_nodes or self.node_principled_bsdf is None: if not self.use_nodes or self.node_principled_bsdf is None:
return self.material.specular_intensity return self.material.specular_intensity
return self.node_principled_bsdf.inputs["Specular"].default_value return self.node_principled_bsdf.inputs["Specular IOR Level"].default_value
@_set_check @_set_check
def specular_set(self, value): def specular_set(self, value):
value = values_clamp(value, 0.0, 1.0) value = values_clamp(value, 0.0, 1.0)
self.material.specular_intensity = value self.material.specular_intensity = value
if self.use_nodes and self.node_principled_bsdf is not None: if self.use_nodes and self.node_principled_bsdf is not None:
self.node_principled_bsdf.inputs["Specular"].default_value = value self.node_principled_bsdf.inputs["Specular IOR Level"].default_value = value
specular = property(specular_get, specular_set) specular = property(specular_get, specular_set)
@@ -313,7 +313,7 @@ class PrincipledBSDFWrapper(ShaderWrapper):
return None return None
return ShaderImageTextureWrapper( return ShaderImageTextureWrapper(
self, self.node_principled_bsdf, self, self.node_principled_bsdf,
self.node_principled_bsdf.inputs["Specular"], self.node_principled_bsdf.inputs["Specular IOR Level"],
grid_row_diff=0, grid_row_diff=0,
colorspace_name='Non-Color', colorspace_name='Non-Color',
) )

View File

@@ -692,10 +692,11 @@ static void version_principled_bsdf_emission(bNodeTree *ntree)
} }
} }
/* Rename Principled BSDF emission to emission color. */ /* Rename various Principled BSDF sockets. */
static void version_principled_bsdf_emission_color(bNodeTree *ntree) static void version_principled_bsdf_rename_sockets(bNodeTree *ntree)
{ {
version_node_input_socket_name(ntree, SH_NODE_BSDF_PRINCIPLED, "Emission", "Emission Color"); version_node_input_socket_name(ntree, SH_NODE_BSDF_PRINCIPLED, "Emission", "Emission Color");
version_node_input_socket_name(ntree, SH_NODE_BSDF_PRINCIPLED, "Specular", "Specular IOR Level");
} }
/* Replace old Principled Hair BSDF as a variant in the new Principled Hair BSDF. */ /* Replace old Principled Hair BSDF as a variant in the new Principled Hair BSDF. */
@@ -1429,8 +1430,8 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
if (ntree->type == NTREE_SHADER) { if (ntree->type == NTREE_SHADER) {
/* Convert specular tint on the Principled BSDF. */ /* Convert specular tint on the Principled BSDF. */
version_principled_bsdf_specular_tint(ntree); version_principled_bsdf_specular_tint(ntree);
/* Rename emission to emission color. */ /* Rename some sockets. */
version_principled_bsdf_emission_color(ntree); version_principled_bsdf_rename_sockets(ntree);
} }
} }
FOREACH_NODETREE_END; FOREACH_NODETREE_END;

View File

@@ -1138,7 +1138,7 @@ bNodeTree *EEVEE_shader_default_surface_nodetree(Material *ma)
e_data.surface.roughness_socket = static_cast<bNodeSocketValueFloat *>( e_data.surface.roughness_socket = static_cast<bNodeSocketValueFloat *>(
nodeFindSocket(bsdf, SOCK_IN, "Roughness")->default_value); nodeFindSocket(bsdf, SOCK_IN, "Roughness")->default_value);
e_data.surface.specular_socket = static_cast<bNodeSocketValueFloat *>( e_data.surface.specular_socket = static_cast<bNodeSocketValueFloat *>(
nodeFindSocket(bsdf, SOCK_IN, "Specular")->default_value); nodeFindSocket(bsdf, SOCK_IN, "Specular IOR Level")->default_value);
e_data.surface.ntree = ntree; e_data.surface.ntree = ntree;
} }
/* Update */ /* Update */

View File

@@ -41,7 +41,7 @@ DefaultSurfaceNodeTree::DefaultSurfaceNodeTree()
roughness_socket_ = roughness_socket_ =
(bNodeSocketValueFloat *)nodeFindSocket(bsdf, SOCK_IN, "Roughness")->default_value; (bNodeSocketValueFloat *)nodeFindSocket(bsdf, SOCK_IN, "Roughness")->default_value;
specular_socket_ = specular_socket_ =
(bNodeSocketValueFloat *)nodeFindSocket(bsdf, SOCK_IN, "Specular")->default_value; (bNodeSocketValueFloat *)nodeFindSocket(bsdf, SOCK_IN, "Specular IOR Level")->default_value;
ntree_ = ntree; ntree_ = ntree;
} }

View File

@@ -37,7 +37,7 @@ void node_bsdf_principled(vec4 base_color,
float subsurface_scale, float subsurface_scale,
float subsurface_ior, float subsurface_ior,
float subsurface_anisotropy, float subsurface_anisotropy,
float specular, float specular_ior_level,
vec4 specular_tint, vec4 specular_tint,
float anisotropic, float anisotropic,
float anisotropic_rotation, float anisotropic_rotation,
@@ -65,7 +65,7 @@ void node_bsdf_principled(vec4 base_color,
ior = max(ior, 1e-5); ior = max(ior, 1e-5);
transmission = clamp(transmission, 0.0, 1.0); transmission = clamp(transmission, 0.0, 1.0);
subsurface = clamp(subsurface, 0.0, 1.0); subsurface = clamp(subsurface, 0.0, 1.0);
specular = max(specular, 0.0); specular_ior_level = max(specular_ior_level, 0.0);
specular_tint = max(specular_tint, vec4(0.0)); specular_tint = max(specular_tint, vec4(0.0));
/* Not used by EEVEE */ /* Not used by EEVEE */
/* anisotropic = clamp(anisotropic, 0.0, 1.0) */ /* anisotropic = clamp(anisotropic, 0.0, 1.0) */
@@ -181,8 +181,8 @@ void node_bsdf_principled(vec4 base_color,
if (true) { if (true) {
float eta = ior; float eta = ior;
float f0 = F0_from_ior(eta); float f0 = F0_from_ior(eta);
if (specular != 0.5) { if (specular_ior_level != 0.5) {
f0 *= 2.0 * specular; f0 *= 2.0 * specular_ior_level;
eta = ior_from_F0(f0); eta = ior_from_F0(f0);
if (ior < 1.0) { if (ior < 1.0) {
eta = 1.0 / eta; eta = 1.0 / eta;

View File

@@ -388,13 +388,13 @@ void MaterialNode::set_specular(COLLADAFW::ColorOrTexture &cot)
has_specularity = false; has_specularity = false;
} }
else { else {
bNode *node = add_node(SH_NODE_RGB, -300, locy, "Specular"); bNode *node = add_node(SH_NODE_RGB, -300, locy, "Specular IOR Level");
set_color(node, col); set_color(node, col);
/* TODO: Connect node */ /* TODO: Connect node */
} }
} }
else if (cot.isTexture()) { else if (cot.isTexture()) {
add_texture_node(cot, -300, locy, "Specular"); add_texture_node(cot, -300, locy, "Specular IOR Level");
/* TODO: Connect node */ /* TODO: Connect node */
} }
else { else {
@@ -407,7 +407,7 @@ void MaterialNode::set_specular(COLLADAFW::ColorOrTexture &cot)
* TODO: This is a solution only for a corner case. We must find a better * TODO: This is a solution only for a corner case. We must find a better
* way to handle specularity in general. Also note that currently we * way to handle specularity in general. Also note that currently we
* do not export specularity values, see EffectExporter::operator() */ * do not export specularity values, see EffectExporter::operator() */
bNodeSocket *socket = nodeFindSocket(shader_node, SOCK_IN, "Specular"); bNodeSocket *socket = nodeFindSocket(shader_node, SOCK_IN, "Specular IOR Level");
((bNodeSocketValueFloat *)socket->default_value)->value = 0.0f; ((bNodeSocketValueFloat *)socket->default_value)->value = 0.0f;
} }
} }

View File

@@ -469,7 +469,7 @@ void USDMaterialReader::set_principled_node_inputs(bNode *principled,
} }
if (pxr::UsdShadeInput specular_input = usd_shader.GetInput(usdtokens::specularColor)) { if (pxr::UsdShadeInput specular_input = usd_shader.GetInput(usdtokens::specularColor)) {
set_node_input(specular_input, principled, "Specular", ntree, column, &context); set_node_input(specular_input, principled, "Specular Tint", ntree, column, &context);
} }
if (pxr::UsdShadeInput metallic_input = usd_shader.GetInput(usdtokens::metallic)) { if (pxr::UsdShadeInput metallic_input = usd_shader.GetInput(usdtokens::metallic)) {

View File

@@ -296,7 +296,7 @@ static InputSpecMap &preview_surface_input_map()
{"Color", {usdtokens::diffuse_color, pxr::SdfValueTypeNames->Float3, true}}, {"Color", {usdtokens::diffuse_color, pxr::SdfValueTypeNames->Float3, true}},
{"Roughness", {usdtokens::roughness, pxr::SdfValueTypeNames->Float, true}}, {"Roughness", {usdtokens::roughness, pxr::SdfValueTypeNames->Float, true}},
{"Metallic", {usdtokens::metallic, pxr::SdfValueTypeNames->Float, true}}, {"Metallic", {usdtokens::metallic, pxr::SdfValueTypeNames->Float, true}},
{"Specular", {usdtokens::specular, pxr::SdfValueTypeNames->Float, true}}, {"Specular IOR Level", {usdtokens::specular, pxr::SdfValueTypeNames->Float, true}},
{"Alpha", {usdtokens::opacity, pxr::SdfValueTypeNames->Float, true}}, {"Alpha", {usdtokens::opacity, pxr::SdfValueTypeNames->Float, true}},
{"IOR", {usdtokens::ior, pxr::SdfValueTypeNames->Float, true}}, {"IOR", {usdtokens::ior, pxr::SdfValueTypeNames->Float, true}},
/* Note that for the Normal input set_default_value is false. */ /* Note that for the Normal input set_default_value is false. */

View File

@@ -27,7 +27,7 @@ namespace blender::io::obj {
const char *tex_map_type_to_socket_id[] = { const char *tex_map_type_to_socket_id[] = {
"Base Color", "Base Color",
"Metallic", "Metallic",
"Specular", "Specular IOR Level",
"Roughness", /* Map specular exponent to roughness. */ "Roughness", /* Map specular exponent to roughness. */
"Roughness", "Roughness",
"Sheen", "Sheen",
@@ -204,7 +204,7 @@ static void store_bsdf_properties(const bNode *bsdf_node,
float specular = material->spec; float specular = material->spec;
if (bsdf_node) { if (bsdf_node) {
copy_property_from_node(SOCK_FLOAT, bsdf_node, "Specular", {&specular, 1}); copy_property_from_node(SOCK_FLOAT, bsdf_node, "Specular IOR Level", {&specular, 1});
} }
float metallic = material->metallic; float metallic = material->metallic;

View File

@@ -307,7 +307,7 @@ static void set_bsdf_socket_values(bNode *bsdf, Material *mat, const MTLMaterial
if (mtl_mat.tex_map_of_type(MTLTexMapType::Emission).is_valid()) { if (mtl_mat.tex_map_of_type(MTLTexMapType::Emission).is_valid()) {
set_property_of_socket(SOCK_FLOAT, "Emission Strength", {1.0f}, bsdf); set_property_of_socket(SOCK_FLOAT, "Emission Strength", {1.0f}, bsdf);
} }
set_property_of_socket(SOCK_FLOAT, "Specular", {specular}, bsdf); set_property_of_socket(SOCK_FLOAT, "Specular IOR Level", {specular}, bsdf);
set_property_of_socket(SOCK_FLOAT, "Roughness", {roughness}, bsdf); set_property_of_socket(SOCK_FLOAT, "Roughness", {roughness}, bsdf);
mat->roughness = roughness; mat->roughness = roughness;
set_property_of_socket(SOCK_FLOAT, "Metallic", {metallic}, bsdf); set_property_of_socket(SOCK_FLOAT, "Metallic", {metallic}, bsdf);

View File

@@ -104,7 +104,7 @@ static void node_declare(NodeDeclarationBuilder &b)
.draw_buttons([](uiLayout *layout, bContext * /*C*/, PointerRNA *ptr) { .draw_buttons([](uiLayout *layout, bContext * /*C*/, PointerRNA *ptr) {
uiItemR(layout, ptr, "distribution", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE); uiItemR(layout, ptr, "distribution", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}); });
spec.add_input<decl::Float>("Specular") spec.add_input<decl::Float>("Specular IOR Level")
.default_value(0.5f) .default_value(0.5f)
.min(0.0f) .min(0.0f)
.max(1.0f) .max(1.0f)