I want to create a procedural texture that will be based on the geometry of an object. How can I get distance to the nearest edge for the current pixel of an object in Cycles nodes? I hope it is possible. Without any UV mapping and obviously before splitting each face into triangles.
-
$\begingroup$ Short answer is nope. Sorry. Closest you can get is pointiness or a fake AO, or alter the surface geometry to use height/slope as a stand in for edge distance $\endgroup$– 3pointeditJul 17, 2018 at 6:33
-
$\begingroup$ A custom OSL shader might be able to determine the information you are looking for. For example an OSL shader can be created to measure the distance to the nearest face. Can you provide an example of what you want to accomplish? $\endgroup$– Ed TateJul 21, 2018 at 22:18
-
$\begingroup$ im interested in this too!! $\endgroup$– Sam MousaSep 1, 2019 at 21:01
1 Answer
It's not the exact distance as you would say it, but it can be approximated using Bevel node in combination with Normal
output of Texture Coordinate node.
The Bevel shader node can be used for rendering rounded corners. Like bump mapping, this does not modify the actual geometry, only the shading is affected. Slight rounding on edges helps to capture specular highlights that you would also see in the real world.
Bevel essentially gives blurred version of normal vectors depending on geometry, so you just have to measure the difference between them.
Shader node example
Samples
controls smoothnessRadius
means how farther from the edges will the samples taken- Alternatively use Color Ramp or Map Range node to control the falloff
Example results
As I said it is not precise and can be lead to unexpected results such as:
- Edges marked smooth won't affect this
- Edge between two faces with little normal change will have a little effect on this
- You can't get exact value of a distance as it's done by random sampling, thus you can't do proper math with it(everything is either 0 or some fixed values)
- Faces with multiple edges converging will report higher values, due to the nature of the method mentioned above
- Render time will increase by 20% on average, as explained in the official doc.
-
1$\begingroup$ Sounds cool! Though it's not precise, but it is at least something practicable. Thanks
(:
$\endgroup$– AivanF.Jun 13, 2020 at 8:43