← All ideas
  • Published 22 Jul 2024

Distance Shader in Cycles (like Arnold/Redshift)

Cycles could really use a distance shader. The shader computes distance to the nearest vertex of a target object. It works like AO, just limited to one object. Image from Arnold's docs.

distance_shader_arnold.png

100%

Development Status: Open

Upvote 6 Downvote 0
michla
22 Jul 2024

8 Comments

Lauloque

It doesn't take much to get distance effects in shaders. If you want only the object location's distance, all it takes is this:

object distance

And for the actual object's shape, the AO node does a great job usually:

AO distance

And I bet we can do a lot more with Geo Nodes, but I am no expert in these.

What would a dedicated Distance node would bring to the table?

Perhaps being able to target specific objects or collections, and more controls on the distance and gradient ?

2
michla Author

Well, I know and use all those tricks. What it does is - you can shade a plane that’s only 4 verts (so the GN way won’t work) using distance to vertices of one chosen object from many possible nearby objects (AO will sample distance to all objects). There is no reason to NOT have a distance node, if only as a mode for AO or whatever. It’d be immensely usable for motion graphics.

I'd provide a visual example but I've no idea how to attach an image in a comment.

Lauloque

I didn't say there shouldn't be a distance node ;)

This site supports a bit of markdown, so to put pictures anywhere you need to upload it somewhere (i use imgur), copy the url of the picture, and insert it using the markdown code ![description](https://picture.url)

1
Hatrutsu

Out of curiosity: what's the add-on with the icons in the viewport?

michla Author

Okay, so here is a visual example vs a screenshot of a recent demo from Redshift... so it turns out I can't event reproduce the fine stepped texture using the AO node - let alone having it only target a single object - the white torus. The only way would be to have a fairly dense geo and use GN. This is, however, a brute force solution.

seanr

This distance shader shouldn't just be distance from some other named object (though that's useful too), I also want distance from the edge of the material itself - so think inner glow on a shape in Photoshop. Blender obviously already knows the edges of the material's applied area - it should be able to calculate the distance from that quite easily, one would think. 😉

DGruwier

Specific examples of ways I've used the distance node in Vray:

  • Water ripples
  • Water surface tension
  • Procedural dirt/grime/snow/buildup
  • Procedural displacement around objects, sand piling up against rocks, etc.
  • Controlling complex gradients with geometry
  • Advanced material blending between objects
  • Forcefield effects like passing through a barrier
  • Procedural clouds and fog that is shaped by geometry but is 100% shader based
  • Volumetric aura around objects
  • Controlling foliage wind effects by distance to uneven ground

All from a simple render-time solution that is 100% solid across any kind of geometry you throw at it, including displacement. There's a lot of possibilities here. I consider this a pretty basic tool in a shading toolkit. And no, current solutions are not good enough:

  • Geometry nodes is not good alternative, because you're limited by the resolution of the mesh.
  • Ambient Occlusion is not a good alternative, it's unpredictable and uneven, and only works at very close distances.
  • Object position is not a good alternative, because it's not related to the geometry surface at all.