I have a very simple Cutout Shader for displaying Icons in 3D space (see below).
I want to 'programatically' add an outline/stroke which follows the alpha contours, with a user defined thickness and colour.
(Left): What I currently have - an alpha cutout shader (Right): What I want - An outline to go around the cutout Please Note: These are not sprites, they are 3D planes
How can I go about doing this, please?
Shader "Custom/Transparent/CutoutEmissive" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
_EmissiveAmount ("Emissive Amount", Range(0,1)) = 0.5
_Outline ("Outline Thickness", Range(0,10)) = 0.0
}
SubShader {
Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
LOD 200
CGPROGRAM
#pragma surface surf Lambert alphatest:_Cutoff
sampler2D _MainTex;
fixed4 _Color;
float _EmissiveAmount;
float _Outline;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
o.Emission = c.rgb*_EmissiveAmount;
}
ENDCG
}
Fallback "Legacy Shaders/Transparent/Cutout/VertexLit"
}
I know its very late but here it is anyways. I came across this solution where the script applies outline near the cutoff. It is hosted on git hub by José Guerreiro and it did solve my problem with cutoff meshes. The only thing I had to do is add the cutoff meshes to the list and set the color of the line. It has its thickness, intensity and cutoff. The usage is written on page itself. Downside is you will have to have the game in play mode to test this but otherwise it is really nice
Note: This outline works only with cutoff on 3d meshes and sprites; normal meshes it does not work.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With