9
$\begingroup$

I'm looking to use a mesh's local vertex data (absolute distance from 0 or origin) for the FAC on a color ramp thus allowing me to grade the color based on distance from the Origin. Is there a way to get this data from a node in cycles?

This is to make a coal with an Emissive Color ramp that will have a Dark black\red for the tips of the coal and a brighter warmer orange/red for the bits closer to the heat.

enter image description here

$\endgroup$
15
$\begingroup$

You can easily use use the Object texture coordinates from the Texture Coordinates node to achieve this.

The socket will output XYZ values in object space, than can be used as RGB values or mapped with a Color Ramp node.

All you have to do is use a Separate XYZ node to get the Z component of the coordinates, and optionally a Math node set to Absolute so you can easily have symmetry along Z, if that is what you wish to achieve.

Object Texture Coordinates

Taking this a step further, you can calculate the distance as sqrt(x^2 + y^2 + z^2) (and remove the Absolute node) as follows :

Distance in three dimensions

Feed this into a 'Multiply' Math node to allow you to scale it as necessary and link this into the Color Ramp.

Distance shading

$\endgroup$
  • $\begingroup$ Thanks, this is really helpful, and a step in the right direction, but not quite finished. I'm trying to radiate from the origin out, so I think I will have to combine the XYZ values or something similar to get the desired affect. $\endgroup$ – Deadly_Cicada Oct 25 '16 at 4:07
  • $\begingroup$ Well I used the Color Ramp as a Diffuse Color influence, but you can easily replace it by a black and white mask color ramp driving a Mix Shader between emission and diffuse instead $\endgroup$ – Duarte Farrajota Ramos Oct 25 '16 at 5:54
  • 4
    $\begingroup$ Multiply each of the X, Y, Z coordinates by itself, add them all together, and raise to the power of 0.5 (ie, square root of (x squared + y squared + z squared)) to get the distance from the origin. $\endgroup$ – Rich Sedman Oct 25 '16 at 10:06
  • 4
    $\begingroup$ One point to note is that using the Object coordinates will mean that different sized coals will be coloured differently as the scale will affect your calculation. To avoid that use the Generated coordintes instead of Object. The Generated coords vary from 0 to 1 regardless of scale. However, you'd then have to subtract 0.5 from each before using thenin your calculation to move the origin to the centre of the object. $\endgroup$ – Rich Sedman Oct 25 '16 at 10:10
  • 2
    $\begingroup$ @DuarteFarrajotaRamos I've edited your answer to include the nodes required for distance from origin - hope this is OK (if not, feel free to revert it). Having played around with the Generated coordinates, I realise that it is better to use the Object coordinates instead of Generated as this keeps the scaling in each of the 3 dimensions consistent - with Generated a long narrow object would have different scales along each of the dimensions which would mess with the distance calculation. $\endgroup$ – Rich Sedman Oct 25 '16 at 22:20

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.