9
$\begingroup$

I am working on a material for a candle, but I'm using the geometry input to get the Z value as a fac for a mix shader.

I've already taken into account the objects position using the object info input, but I've realized that if I duplicate the object and scale it up or down, the material no longer works as it should.

Is there a way to get the objects scale in the material node editor to multiply the Z value by?

$\endgroup$
2

3 Answers 3

10
$\begingroup$

You can use the following nodes to extract the scaling information :

get object scale

The key here is the use of the Vector Transform node. The Vector Transform node allows you to transform a vector between different coordinate spaces - World, Object, Camera. When transforming between Object and World coordinates, blender will apply any object Translation, Rotation and Scale and this can be used to extract the scale directly without the use of drivers.

By feeding a known vector into the Vector Transform we can use the output to glean information regarding the object. In this case, the vector [1.0, 0.0, 0.0] is being transformed from Object to World space in 'Vector' mode, meaning that only the Scale and Rotation is applied (the location is ignored). We know that the vector entering the transform has a length of 1.0 and the Dot Product node used this way, followed by a Power of 0.5 (square root) will output the length of the resultant vector and this allows us to ignore the rotation - the change in length is a direct result of the scaling.

The input vector [1.0, 0.0, 0.0] will effectively read the X scale. Passing in [0.0, 1.0, 0.0] will read the Y scale, and passing in [0.0, 0.0, 1.0] the Z scale.

We can therefore use the following material to color the object based on its X, Y, Z scale as R, G, B :

get x,y,z scale as RGB

For your situation you can simply use the output of one of these scales to drive your mix factor.

$\endgroup$
1
$\begingroup$

I found the following solution works in Blender 3.6.* and will - presumably - work in all versions of 3+

Inspired by the other solution posted here, converting a local vector to a world vector and checking it's length effectively gives us the object scale along that axis. For my purposes this was sufficient, as my objects are always scaled uniformly.

I use the following node setup:

Blender shader node setup for

This results in the following behaviour:

Blender shader scaling with object scale

$\endgroup$
1
  • $\begingroup$ Yes - Blender nodes now provide a ‘Distance’ operation to directly measure the length of a vector, instead of having to calculate the length via other means (the Dot Product). $\endgroup$ Dec 17, 2023 at 21:24
0
$\begingroup$

Just tried this method, and the other method linked in the comment by Ray Marilot. The other method didn't work (in version 2.79), and the method described here didn't either, as nothing changed when scaling my objects. But testing some more I ignored the "dot product" and "power" nodes, as my objects werent rotating. I pumped the "vector transform" node into the factor of a color mixer (between pure black and white), and then into a gradient. And lo and behold, it worked! The object was got more black as it shrunk, and more white when it grew. And 50 shades of grey in between a scale of 0 and 1.

$\endgroup$

You must log in to answer this question.

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