0
$\begingroup$

I have a material I made that uses some custom properties from the object: a color and a float. The color and float are used in some computations to make the Base Color for the Principled BSDF.

When I look in the right sidebar at the Preview section of the material, it shows the base color as black because it does not know to use any values for the custom properties. Is there any way to adjust the custom property values for the preview objects? I have already tried changing the default values for the properties themselves, to no avail.

Thanks.

$\endgroup$
3
  • $\begingroup$ I guess the problem is, the material preview shows the general appearance of the material, like for example in the dropdown menu where you can choose a material from the list before it is even assigned to the object. Since the custom properties are local attributes, materials however are universal and can be assigned to any object, not just the one you created them on first - so they have no attributes to display in the overview. Don't know if you can define global attributes (never needed that) but if so you had the problem that the preview would show these and not the object's custom ones. $\endgroup$ Commented Jan 12 at 8:37
  • $\begingroup$ @GordonBrinkmann Thanks for the insight! It would be nice to be able to define global attributes, so I might look more into that and edit my post if I happen to find a way. I'm okay with the preview showing the global attributes and not the object's custom ones. $\endgroup$
    – harada
    Commented Jan 13 at 19:35
  • $\begingroup$ For global properties you would not need extra properties, you would simply use Color and Value nodes in the material. So actually you could build some "switch" to show the "global" nodes if the custom properties are 0/not available, but put on an object the material uses the custom values if there are some. I'm not on a computer right now, but I think this could be done. $\endgroup$ Commented Jan 13 at 22:02

1 Answer 1

2
$\begingroup$

Now that I know you're okay with some "general preview" which does not take the custom properties into account I can show you a solution for your problem.

I made a material that uses custom object properties "rgb" for the Base Color of a Principled BSDF and one simply called "float" for the Roughness.

Since the Preview in the Material Properties cannot use these custom properties and would show black, no matter what the values of the custom properties or if the object even had those properties or not.

So to make a preview other than black, you can set default values in the material that will show if the custom properties are 0, either because they are 0 or because they are not available at all.

To do this, you plug the Attribute node's output providing the custom property into a Math Node set to Greater Than, comparing the attribte to 0. The result you can use as the Factor for example in a Mix Color node for the color properties or a general Mix node for the roughness properties.

The actual attribute goes into the bottom socket of a Mix node and will appear on the object if it exists and is > 0, whatever you have in the first input will be the default which the material shows in the preview.

Here is a simple example: I want the preview to show the material in red with a medium roughness of 0.5 as default. The three spheres all have the exact same material, only that the custom properties of the left one are set to "float" = 0.15 to be a bit more glossy than default, and "rgb" is set to (0.1, 0.2, 0.6) to be blue instead of the default red. The sphere in the middle has a higher roughness and the color values set to be greenish. The sphere on the right does not have any custom properties, so it shows the default red medium glossy sphere:

material with custom properties

Well, so far so good... but you might have already guessed that there might be a situation where this material does not work: what happens if you want one object to have a black color? Not very very dark and almost 0, but really 0?

Then you'll get the problem that the Greater Than node will output 0, switching to the default red. Which is not what you want, you also cannot use a Less Than node and simply switch the Mix Color inputs, because then the default preview will not show red, because having no custom property is 0, not less than 0. You could avoid this by simply making the default black, but then you could stick with only plugging the custom property in the Principled BSDF which is not what you want which is the reason for your question after all. So you have to tweak the material a bit to build a workaround.

First of all your custom property has to allow negative values < 0 (or Soft Limits). Since colors do not show anything else then black if you enter negative values in the RGB channels, you could for example use for the color's custom property "rgb" = (-1, -1, -1) or any other negative values. Of course the Greater Than node would now switch to false or 0 and show red, but when you plug a Math node set to Absolute before the Greater Than, the negative values will become > 0 and the Mix Color node will show the second input. But the color will turn every negative value into 0 and thus become black:

black color

Just be aware that although the Absolute and Greater Than nodes convert the three "rgb" values into a single float and always be true if the overall value is different from 0 so that you could even get away with only one of those values being negative for the Greater Than node to give the correct result for switching to the second input, the color will not be black when there are values > 0 present, because (-1, 0.2, 0.3) will become (0, 0.2, 0.3) which is not black, so when you use negative value(s) in there the other(s) have to be 0 to stay black.

$\endgroup$
1
  • 1
    $\begingroup$ Thanks Gordon! This what I ended up using, and it works perfectly. (though in my own practice, I was a bit lazy and ignored the chance that I would ever need pure black lol) Your solution is definitely more robust. Kudos! $\endgroup$
    – harada
    Commented Jan 15 at 3:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .