We're working on a new project, and I'd like to create a shader and material for rendering an outline for a Skeleton in Unity, but instead of a solid color, I'd like to use a gradient to simulate rim-lighting on the skeletons.
I'm very new to shader programming, so please bear with me here.
So far I have something working, but not in a way that I want it to. My current fragOutline pass in my .cginc looks like this:
float4 fragOutline(VertexOutput i) : SV_Target {
// Normalize the vertex Y value within the min-max range
float gradientCoord = (i.vertexY - _MinVertexY) / (_MaxVertexY - _MinVertexY);
// Sample the gradient texture
float4 gradientColor = tex2D(_OutlineGradient, float2(0.5, gradientCoord));
float4 outlineColor = _OutlineColor * gradientColor;
float4 texColor = computeOutlinePixel(_MainTex, _MainTex_TexelSize.xy, i.uv, i.vertexColorAlpha,
_OutlineWidth, _OutlineReferenceTexWidth, _OutlineMipLevel,
_OutlineSmoothness, _ThresholdEnd, _OutlineOpaqueAlpha, outlineColor);
#ifdef SKELETON_GRAPHIC
texColor *= UnityGet2DClipping(i.worldPosition.xy, _ClipRect);
#endif
return texColor;
}
And this renders the outline as a gradient, so long as I provide an appropriate _MinVertexY and _MaxVertexY value (I'd rather not have to do that however).
The other issue is that because it's an outline it renders to the left and right edges of the Skeleton as well, but I'd rather the outline only be above the Skeleton, like a rim-light effect caused by an overhead light.
Any help, suggestions, code snippets, solutions, etc. would be greatly appreciated here.
Here is the effect I currently have working in Unity:
Here is the effect that I'd like to achieve (made in Photoshop):
I can almost fake this effect by using a gradient that is 100% transparent in the center, fading out to the top and bottom colors respectively, but the outline still appears under the bottom edge of the Skeleton, as well as to the left and right of the edges on the sides of the Skeleton.
What would be the best way to avoid having to do that, and ensure the outline only appears over the top edge of the Skeleton, like in my example effect?