Hey,
i am working on a hack n slash and want to highlight units behind walls and trees etc.
I modified a silhouette shader to resemble that effect but i am stuck with the problem of overlapping objects.
In the screenshot you see the dwarf, his hammer (its a separate mesh) and a troll. They all have the silhouette shader so you can see them behind trees or walls.
You can see that where the hammer overlaps the dwarf there are unwanted highlights.
How can i modify the shader or what can i do so that (in this example) the hammer is drawn over the dwarfs highlights?
Thanks! Alex
Find the the shader attached
2247467–150099–SilhouetteOutline.shader (1.81 KB)
Shader "Outlined/Silhouetted Diffuse" {
Properties {
_Color ("Main Color", Color) = (1,1,1,0.5)
_SpecColor ("Spec Color", Color) = (1,1,1,1)
_Emission ("Emmisive Color", Color) = (0,0,0,0)
_Shininess ("Shininess", Range (0.01, 1)) = 0.7
_MainTex ("Base (RGB)", 2D) = "white" { }
_OutlineColor ("Outline Color", Color) = (0,0,0,1)
}
CGINCLUDE
#include "UnityCG.cginc"
struct appdata {
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct v2f {
float4 pos : POSITION;
float4 color : COLOR;
};
//uniform float _Outline;
uniform float4 _OutlineColor;
v2f vert(appdata v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.color = _OutlineColor;
return o;
}
ENDCG
SubShader {
Tags { "Queue" = "Transparent" }
// note that a vertex shader is specified here but its using the one above
Pass {
Name "OUTLINE"
Tags { "LightMode" = "Always" }
Cull Off
ZWrite Off
ZTest Greater
ColorMask RGB // alpha not used
// you can choose what kind of blending mode you want for the outline
//Blend SrcAlpha OneMinusSrcAlpha // Normal
Blend One One // Additive
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
half4 frag(v2f i) :COLOR {
return i.color;
}
ENDCG
}
Pass {
ZWrite On
ZTest LEqual
Blend SrcAlpha OneMinusSrcAlpha
Material {
Diffuse [_Color]
Ambient [_Color]
Shininess [_Shininess]
Specular [_SpecColor]
Emission [_Emission]
}
Lighting On
SeparateSpecular On
SetTexture [_MainTex] {
constantColor [_Color]
Combine texture * primary DOUBLE, texture * constant
}
}
}
Fallback "Diffuse"
}
ok, i got it
Offset -100,-100 added to the Outline Pass did the trick.
Not entirely sure why, but great nonetheless