5
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Related blender.stackexchange.com/questions/79851/… $\endgroup$ – Duarte Farrajota Ramos Jan 26 '18 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 Jan 26 '18 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 Jan 26 '18 at 12:57
6
$\begingroup$

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

$\endgroup$
8
$\begingroup$

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

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

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.