2

Is there a way to have a shader behave differently near a mesh edge?

For example, if a shader generates a checkered pattern, is it possible to detect the edge and make the squares that intersect the edge transparent?

enter image description here

Some clarifications:

  1. The solution can be for a single face. In other words if the edge can be detected on a signle face.
  2. The solution should work even if the face is not a simple shape like a circle, square, or triangle.
Ed Tate
  • 5,186
  • 1
  • 30
  • 51
  • Sorry if my question is silly, but by "make the squares that intersect the edge transparent" in this case do you literally mean you want only the 9 squares in the middle to be opaque while the other ones that intersect the edge fully transparent? Or do you just want a smooth gradient around the edge that can be made transparent? – uvnoob Aug 23 '20 at 19:34
  • I want only the 9 squares in the center to be opaque. The squares on that intersect the eve should be transparent. – Ed Tate Aug 23 '20 at 20:23
  • 1
    https://blender.stackexchange.com/questions/114079/cycles-nodes-is-it-possible-to-get-distance-to-nearest-edge – Ed Tate Aug 23 '20 at 23:25
  • 2
    "The solution can be for a single face. In other words if the edge can be detected on a signle face" - you mean a solution would be acceptable if the same shader turns the whole face transparent only if the face has a border edge? If that is the case, would the following work: Script that assigns UV coordinates of (0,0) to faces (their vertices) touching borders, otherwise set UV to (1,1). Then you could easily manipulate every face based on generated UV values. – uvnoob Aug 24 '20 at 07:59
  • @uvnoob I agree that this should work. You would need a very dense geometry though – Gorgious Aug 24 '20 at 08:31
  • What you're asking-- use the shader only to detect a mesh edge, for any conceivable geometry and topology-- is not possible. One sample does not know what another sample is doing, so there is no way for one square sample to figure out if that square is cut off, not without rendering the scene to find out. But: with certain constraints, in certain situations, there are potential tricks. If you give your actual situation , rather than a generalized problem, it may be possible. – Nathan Aug 04 '21 at 16:25
  • "The solution can be for a single face. In other words if the edge can be detected on a signle face." - this makes the solution trivial in geonodes, though I don't know if that's what you really mean. Every edge connected to only one face is a boundary edge. Capturing 1 as float on such edges and then recapturing on (interpolating to) faces will give you an attribute that you can read in the shader - if 0, it's a face not connected to a bounary, otherwise it is. – Markus von Broady Apr 18 '23 at 08:40

2 Answers2

1

This might be only an answer that helps to improve the question, but if you subdivide a plane, assign blue material, checker deselect, assign ping material, then create a circle, knife project and remove vertices outside the circle, add a geonodes modifier:

And finally modify the blue material to:

You will get this effect:

Of course this effect could be applied also to pink faces, as well as there could be a single material for both colors, and the color could be captured on faces, or just the shader's checkerboard texture could be aligned with geometry; I did it this way to clearly show it requires the squares to be defined by geometry, as this is how I understand this statement:

The solution can be for a single face. In other words if the edge can be detected on a signle face.

Markus von Broady
  • 36,563
  • 3
  • 30
  • 99
0

I'm not at my pc at the moment, so I can't test it, but I can point you in the right direction, I would use a colorramp-node and mask out the dark squares so they are transparent, then use the geometry-node (docs.blender.org/manual/en/latest/render/shader_nodes/input/…) to create a mask for the position, use another colorramp to set the threshold, and then blend between the original and the transparent texture using a mix-node and the factor comes prom the mask. I hope that helps and I'm sorry that I can just be theoretical at the moment. All the best – Marco Vitale

  • The challenge that this is part of an animation and I only want to have the dark cell on the edge of the mesh transparent. – Ed Tate Feb 27 '21 at 18:50