5

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.

Visual description of desired effect

(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"
}
Ben Hayward
  • 1,444
  • 23
  • 37

1 Answers1

3

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.

Community
  • 1
  • 1
killer_mech
  • 1,568
  • 13
  • 26
  • This is useful - thank you @killer_mech. It's a shame this isn't part of the shader code, as I suspect this could be slower to execute than if it were done on the GPU. Many thanks! – Ben Hayward Jun 08 '16 at 09:04