Outline Shader working in editor but not in-game
Hello everybody! I Have a bit of an issue. So, this shader i have works in the editor, and shows just the way I want it to, but when I go in-game I can't see it at all. Here is the code:
Shader "Custom/Outline"
{
Properties
{
_Color("Main Color", Color) = (0.5,0.5,0.5,1)
_MainTex ("Texture", 2D) = "white" {}
_OutlineColor("Outline Color", Color) = (0,0,0,1)
_OutlineWidth("Outline Width", Range(1.0,5.0)) = 1.01
}
CGINCLUDE
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct v2f
{
float4 pos : POSITION;
float3 normal : NORMAL;
};
float _OutlineWidth;
float4 _OutlineColor;
v2f vert(appdata v)
{
v.vertex.xyz *= _OutlineWidth;
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
return o;
}
ENDCG
SubShader
{
Pass // Render the Outline
{
ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
half4 frag(v2f i) : COLOR
{
return _OutlineColor;
}
ENDCG
}
Pass // Normal Render
{
ZWrite On
Material
{
Diffuse[_Color]
Ambient[_Color]
}
Lighting On
SetTexture[_MainTex]
{
ConstantColor[_Color]
}
SetTexture[_MainTex]
{
Combine previous * primary DOUBLE
}
}
}
}
Please tell me if you need anymore information. Thanks!
Are you using Forward or Deferred rendering. If you are using Deferred, the shader will work in the scene view, but you'll probably need to mark it as transparent in order for it to work in game view; otherwise Unity will think there is nothing there and simply draw over the top of it. For the first pass (i.e. the outline pass), rather than have ZWrite Off and draw over the top of it with the second pass, what you could do ins$$anonymous$$d is replace it with;
ZWrite On
Cull Front
That way the outline will be drawn behind the object, but it won't be straight up ignored by the rendering pass.
Your answer
Follow this Question
Related Questions
Highlighting Multiple Objects with an Outline Shader 0 Answers
Problem with fresnel materials 0 Answers
Standard Shader Emissive Warning? 2 Answers
How to change a child's shader to another shader? 1 Answer
Similar looking base and globe model 0 Answers