6
$\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$
4
$\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$
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$

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.