I have the following scenario in cycles:

enter image description here

I would like to know if it is possible to create a gradient on a plane like the one on the image above where the colours depend on the distance to an object (sphere in this case). In this case, the surface right below the ball would be the nearest one and hence would be of one colour. As we move away from the plane's center the colour should change accordingly to the distance to the sphere. I would like to automatize the process so that blender takes the coordinates of the sphere and automatically draws a colour gradient on the plane's surface. I have managed to create the gradient but I cannot make it dependant of the distance to an object.

Thanks in advance

  • $\begingroup$ Related blender.stackexchange.com/questions/79851/… $\endgroup$ Commented Jan 26, 2018 at 11:59
  • $\begingroup$ With cycles / surface nodes you could make a setup that measures distance to a single point that happens in shader pipeline. You can write image data via python script so you can sample the areas and calculate the distance and "bake" the data but it is relatively slow since python is run on CPU. Are you looking to use this real-time, in rendering or export some custom data format? $\endgroup$
    – kheetor
    Commented Jan 26, 2018 at 12:44
  • $\begingroup$ I want this to create a pixel map density and no need to be in real-time, only need the rendered final image. $\endgroup$
    – Miguel
    Commented Jan 26, 2018 at 12:57

4 Answers 4


Here is a simple node setup for Cycles. Note that this will use the sphere object origin, not its surfaces. This material will not consider the shape of your object.

Use the Mapping node to tweak the effect of the gradient and the ColorRamp node to change the gradient colors.

Results can be viewed in render mode.

Gradient with distance node set up


You can do something like this with dynamic paint. This solution does calculate proximity from the mesh, not just the center point.

The plane should be your dynamic paint canvas, the sphere (or whatever object(s)) the brush. I suggest painting to vertices as that's easy to use in the material node setup. On the brush object, set your paint source to "Proximity" and set a Paint Distance that gives you the gradient values you're looking for.

dynamic paint setup

Then set up your material to translate the gradient into a color gradient input to a shader. Here I've used the wetmap.

material setup

  • 2
    $\begingroup$ What would this look like in the new EVEE viewport in 2.8? $\endgroup$
    – patmo141
    Commented Dec 12, 2018 at 21:00

Another way of doing this:

enter image description here

Add a Value node to your shader, then...

  1. Right click on the number field and choose edit driver.
  2. Under Driver Settings, set Type to "Sum Values".
  3. In the Object field, select your sphere.
  4. For Type set "X Location".
  5. For Space, set World Space.

enter image description here

Repeat with Y and Z, then wire the results into a Combine XYZ node. Now you're passing your sphere's position to the shader.

To get the distance from the sphere to your surface:

  1. Add a Geometry Node
  2. Add Vector Math Node, set it to Subtract
  3. Subtract the Combine XYZ node from the Geometry Position node.
  4. Add another Vector Math node. Set it to Dot Product
  5. Wire the output of the Vector Subtract node into both vectors of the Dot Product node.

Now you've got distance going from 0 to a big number. Scale it down, clamp it, and feed it to a color ramp.

  • $\begingroup$ So this is just distance to the center of the object, not distance to the surface of the object, right? $\endgroup$
    – endolith
    Commented May 14, 2021 at 1:38
  • 1
    $\begingroup$ Yep, that's correct $\endgroup$ Commented May 15, 2021 at 20:06

You can use "Point Dencity" texture with "Object Vertices" enter image description here


You must log in to answer this question.

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