2
$\begingroup$

I am looking for documentation on the titled item. Of course, I first went to the Blender 2.79 API documentation to find out about the node inputs and their acceptable values, but couldn't sort out how to determine default values for a given input from that page. I've searched on here for the titled item and got 16 answers, none of which addressed my problem. Please allow me to illustrate using a code snippet from a class that creates a shader in a material zone of a figure.

  def buildShaderset(self, image):
    if self.selSdr == "PrinSSS":
      self.matOut = self.treeNodes.nodes.new("ShaderNodeOutputMaterial")
      self.matOut.location = (100, 450)
      self.nodes["Output"] = self.matOut

      if (self.Region[0:4] == 'Skin' or self.Region == 'Mouth'):
        self.shPrin = self.treeNodes.nodes.new("ShaderNodeBsdfPrincipled")
        self.shPrin.location = (100, 250)
        self.nodes["Principled"] = self.shPrin
        self.treeNodes.links.new(self.shPrin.outputs[0], self.matOut.inputs[0])
        # Specular values
        self.shPrin.inputs[5].default_value = .015
        self.shPrin.inputs[11].default_value = .2
        self.shPrin.inputs[14].default_value = 1.8

    # Skin and Eyes mat slot names have _suffixes
    if self.Region[0:4] == 'Skin':
      self.makeSkin()

...etc

I sort-of guessed the input[] locations for spec values, which appear to reflect on the created node. I was wondering if there was documentation on those inputs for Python developers (of which I am least).

Thank you for considering my little conundrum.

$\endgroup$
3
$\begingroup$

From 2.79 source code, there is this definition. I guess the inputs are in the order you want here:

static bNodeSocketTemplate sh_node_bsdf_principled_in[] = {
    {   SOCK_RGBA, 1, N_("Base Color"),             0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
    {   SOCK_FLOAT, 1, N_("Subsurface"),            0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
    {   SOCK_VECTOR, 1, N_("Subsurface Radius"),    1.0f, 0.2f, 0.1f, 0.0f, 0.0f, 100.0f},
    {   SOCK_RGBA, 1, N_("Subsurface Color"),       0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
    {   SOCK_FLOAT, 1, N_("Metallic"),              0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
    {   SOCK_FLOAT, 1, N_("Specular"),              0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
    {   SOCK_FLOAT, 1, N_("Specular Tint"),         0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
    {   SOCK_FLOAT, 1, N_("Roughness"),             0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
    {   SOCK_FLOAT, 1, N_("Anisotropic"),           0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
    {   SOCK_FLOAT, 1, N_("Anisotropic Rotation"),  0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
    {   SOCK_FLOAT, 1, N_("Sheen"),                 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
    {   SOCK_FLOAT, 1, N_("Sheen Tint"),            0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
    {   SOCK_FLOAT, 1, N_("Clearcoat"),             0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
    {   SOCK_FLOAT, 1, N_("Clearcoat Roughness"),   0.03f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
    {   SOCK_FLOAT, 1, N_("IOR"),                   1.45f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f},
    {   SOCK_FLOAT, 1, N_("Transmission"),          0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
    {   SOCK_FLOAT, 1, N_("Transmission Roughness"),0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
    {   SOCK_VECTOR, 1, N_("Normal"),               0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
    {   SOCK_VECTOR, 1, N_("Clearcoat Normal"),     0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
    {   SOCK_VECTOR, 1, N_("Tangent"),              0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
    {   -1, 0, ""   }
};
$\endgroup$
  • $\begingroup$ That answered more than one question: about this specific shader node, and about nodes in general. Sock_Vector takes a tuple. And counting of inputs starts at 0? $\endgroup$ – RobinsSea Apr 2 '18 at 7:46
  • $\begingroup$ afaik, yes 0 based. I don't know the code in details, but that'd be counter intuitive the inputs in C and Python be in a different order. $\endgroup$ – lemon Apr 2 '18 at 7:51
  • $\begingroup$ @lemon Please could you include a link to that code? I'm having trouble finding it. $\endgroup$ – Robin Betts Apr 2 '18 at 11:04
  • 1
    $\begingroup$ @RobinBetts it is in "blender\source\blender\nodes\shader\nodes\node_shader_bsdf_principled.c" line 32 from the 2.79.4 (current) version $\endgroup$ – lemon Apr 2 '18 at 13:36
3
$\begingroup$

Just ignore the input list index values. Treat the input list as a dictionary.

shPrin.inputs['Specular'].default_value = 0.015
shPrin.inputs['Sheen Tint'].default_value = 0.2
shPrin.inputs['IOR'].default_value = 1.8

If you know an index and want to know the name -

>>> shPrin.inputs[11].name
'Sheen Tint'

And to list all the available names -

for i in shPrin.inputs:
    print(i.name)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.