The shader is actually not the important part - the UVs of the mesh are. In order for this to work, the mesh needs each quad occupying a full 0-1 UV space. That looks like this:
You’ll notice that while the cube has 6 sides, its UV is just a single box. That’s because each quad is overlapping the entire 0-1 space. On our UV, we have the X and Y axis (R&G respectively) going from (0,0) in the top left corner to (1,1) in the bottom right.
Next, let’s alter the coordinates. We don’t really want them from 0-1, that’s just a convenient starting point for us to get where we want.
We actually want them to go from 0 on the edge to 1 in the middle, and then back to 0 on the edge again.
Now we can separate our X&Y/R&G values and use a step or smoothstep operation to choose our edge thickness and softness.
Now we can use this as a mask to drive any effects we want.
A minor optimization would be to use the minimum value between the R&G and just finding that edge instead of finding their edges individually. That looks like this:




