I was able to figure it out ^^
Due to the 3 image limit on the forum, I’m also posting this on imgur with more screenshots, if it helps make it clearer - https://imgur.com/a/Kg55w?
So there’s no way (as far as I can find) to make a blender node that lets you specify a gradient direction like “away from the object’s inner rim” or “away from the object’s edge” or anything like that.
But what you CAN do is specify a direction determined by a face’s position the UV/Image Editor. Then you can position the faces in the editor to make the gradient move in the direction you want.
It sounds like a lot of manual work but it’s not actually, here’s what I did.
Originally my number 5 was a text object, so first I converted it to a mesh. I cleaned it up by using “remove doubles” to get rid of a lot of unnecessary points. You could probably also use decimate or something. I got the mesh looking tidy, basically, and made everything into quads. Like so: https://i.imgur.com/u9elJIn.jpg
I wanted something like an inset, but outside the original 5’s boundaries. So I guess like an outset, but when I tried using the inset modifier with the outset option, it didn’t work as I wanted. So I found a workaround. I extrude the 5 downward along the Z axis. Then I selected all those edges I just extruded, but not the 5’s front or back face. Then I separated those edges with P to make them into their own object, so I had this 5 shaped “cookie cutter”, an outline of the 5 with zero thickness in the X or Y direction. I then gave it thickness by using the solidify modifier, and applied the modifer. That gave me the shape below (and I’m hiding the original “5” to just show the rim). If you don’t want your gradient to expand outside the original object’s boundaries, you could just use the inset modifier to make a rim.
Note that when viewed from above, the entire rim is made of nicely angled quads, sort of like a winding sidewalk path, the curves and corners all seem to move along a direction, which is important to make the rest of this work.
- Once I had my rim, I set up the nodes like this. The busy-looking principled shaders make it look overly complex, but it’s not really. I am going from a shiny black solid surface, to a shiny white transparent surface. The first node on the left is the white. The second one is the black. These plug into a mix shader.
Then to specify exactly how smooth the transition is from one shader to the other, I use the color ramp node. By dragging the black and white arrow thingies inward a bit, I made a sharper transition from black to white.
I plug the color output of this ramp into the factor of the mix shader.
So we have color A, color B, and a ramp to control the transition from one to the other. Now I just need the tricky part, a vector that tells blender where to position the texture so that color A and color B appear where I want. So that’s a “texture coordinate” input. And we’re using the UV output of the texture coordinates (because basically it’s the only way I could find to specify this). Then we add a mapping node to control the coordinates, because the UV node by itself doesn’t position them the way I want by default.
The only part of this setup that might be a little confusing here is the seemingly arbitrary -10" on the mapping node, under the Y location… and the 45 degree rotation on the Z axis, under the rotation column.
The Y tweak is there because, for some reason, Once I got the gradient working and visible, it was off-center a bit, so that there was more black than white even though they’re supposed to be exactly the same amount. When I played with the Y location to move it -10", it seemed to center perfectly.
The rotation tweak is there because the blender UV map editor works in 2D space, with X being left & right, and Y being up + down. The coordinates of this space are 0,0 (bottom left) to 1,1 (upper right). If I just plug the texture coordinates as “UV” it’s not specific enough, I’m not giving exact X or Y directions, just “UV coordinates”.
So blender assumes equal X and Y directions. That puts black in our gradient at 0,0, and white is at 1,1. This makes the gradient move diagonally from the bottom left corner of the UV editor, to the top right corner. I don’t want that, I want the gradient to move vertically. Not on the object itself, just within the UV editor. So I rotate the gradient 45 degrees with that mapping node.
Finally, I just need to unwrap this 5’s rim so that for every individual face, when I’m looking at the UV Editor, the inner edge of the 5 is at the bottom, and the outer edge is at the top.
It would be super handy and easy if I could just have each face scaled to fit the entire UV editor plane, as a perfect square, and just make sure all the squares are rotated correctly.
To achieve that, all you have to do is click one random face of the rim, as in the pic below, press U, and do “smart UV project”. You don’t need to specify any seams or change any of the settings shown below. Just click OK. This does exactly what I wanted… makes a zillion perfect squares in the UV editor, all of them filling up the entire UV plane, and all of them overlapping. Once that’s done, you should immediately see the gradient on every face in the 3D view. But by default it was just rotating the wrong way, like so: https://i.imgur.com/nYS274c.jpg
So all I had to do is go into the UV editor, A to select all, R, X, -90 to rotate them all 90 degrees counterclockwise, putting the black edges along the inner rim and the white edges along the outer rim.
This got me 95% of the way there, You may end up with a few weird faces that end up backwards or whatever, like this one shown below. To fix that easily, I first enabled the option to synchronize the selection between my mesh and my UV mapping. In the imgur screenshot above, that’s the little button at the bottom that looks like an arrow clicking on a cube. Then when I clicked on the misbehaving face, it highlighted that same face in the UV editor. Then I just hovered my mouse over the UV editor (so I don’t accidentally rotate the mesh instead of the UV) and did R, X, 180 to flip it around 180 degrees.
Final result of the rim can be seen here. So now my object’s edges are semi transparent, sort of like subsurface scattering but controlled the way I want (and possibly less resource-intensive). https://i.imgur.com/h2ZBtKu.jpg