Volume density based on inward distance from mesh

I’ve seen several postings about this topic, but none I found were answered. I thought I’d try again.

I would like to be able to calculate a volume density (or just a texture coordinate) proportional to the distance from the mesh, measured inward from the mesh surface to the mesh origin. I’ve got a good idea how the standard gradient texture works, but it is calculated from a single origin point with uniform radial scaling in all directions. In contrast, I want to be able to take into account the shape of the mesh. I’m thinking the density function would run from 0 -> 1 along each radius from the object origin outward until the mesh surface is intersected.

Alternately, if there is a way to access the vertex or face coordinates in Nodes, I think I can build a node tree to calculate the density function from scratch. I can imagine you could do this with Python queries of the vertex or face data, but I suspect that would take a long time to render. Similarly with OSL. But I’d rather than some method rather than no method at all.

I’d greatly appreciate any suggestions you all might have.


you can try using object info node, which has the location of the object, in combination with light path: ray length option. ray length can give you the thickness of the mesh when viewed from the camera, and perhaps with some math operations, you can get the desired result.

also, texture coordinate: object option basically computes the textures from the object origin.

another thing to check, though i may be completely off here, is the upcoming point cloud density node, which is in developement right now.