Gradient inbound

Hey, blender people. I’m looking for a way to make the gradient start from the center if an object and end close to it’s surface. No problem to make it with a sphere, but how is it possible to apply for other shapes of distinctive faces like cube or just random blob mesh? Guess there should be some math nodes using object normals, but my knowledge is not enough here, so asking for your help kindly. Cheers.

@thorn this looks like a task for the NPR branch maybe?

If the gradient ends at the surface of the object… then you’ll only see the last stop of the gradient, because all you can really render is the surface itself.
:thinking:

hm…maybe…? i have an idea, but will have to see what happens…

As you can see from my simple node set-up, gradient is rather being a factor input, where the first color just fills the inside and the second one being a small “skin” on the surface.

So it looks when you have a sphere… But you’re using a distance from the center, and not a distance from the surface, and this small difference is enough to break the logic when you’re rendering a Cube (or any other non-spherical object).

Calculating the distance from the surface, is far more complex, because you need to do it for all faces that compound the surface… The sphere is easy, because the whole surface is at the same distance to the center, but it’s not true for any other surfaces.

Yep, that’s what I’m trying to figure out, how to limit gradient by bounds of a custom vectors, pretty much like a single voronoi cell in 3d space.

A ‘single voronoi cell’ is just a point. It has no bounds… :confused:

If the ‘cell’ is in the vicinity of other ‘cell’, then you’re able to define one bound, which would be a plane where all points of its surface have some distance to both ‘cells’; for example if the plane is right in between both ‘cells’, the distance from each point in the plane to the two ‘cells’ will be the same.
If you have three or more ‘cells’, then you need to repeat the same logic to all ‘cells’, and it will result in multiple bound planes intersecting with each other. And this get’s exponentially more complicated as you add more and more ‘cells’.

In the case of your example, with a cube, there are 6 planes forming the surface of the cube, so it’s probably better to use the faces.
and forget the ‘voronoi’ analogy (which is also not very practical in terms of shading)

Here, I’m taking advantage of some facts about a cube, like its faces are parallel to its axis… Other surfaces require other solutions, thought it’s very difficult to generalize this inside a shader.

Probably you could get it done using GNs and storing values at each vertex… :thinking:

1 Like