- Home /
Blueprint Shader
I have a camera that I'm using to generate a top down orthographic view of the world to use as an overview map. What I would like it to look like is just black outlines of all the objects on a white background. I would prefer clean lines as opposed to blured lines found in most outline shaders. I came across this: http://wiki.unity3d.com/index.php?title=Silhouette-Outlined_Diffuse which mostly does what I need, but I wanted to apply the effect "globaly" through the camera and not have to put the shader on each object and I don't know how I would toggle the effect by camera either. Probably somthing along the of this http://www.thecrosshouse.org/Page%208%20-%20Blueprints/Blueprint-First%20Floor.jpg but without the labels and such.
I am using Unity Pro.
Thanks in advance.
Answer by Paulius-Liekis · Aug 22, 2013 at 07:17 PM
Note that some outlines shaders work on geometry (like your one) which means it has to be applied to every object, others work on screen-space, which means they are automatically applied on every object. So you might want to look for screen-space effect.
Otherwise you can look into replacement shaders (camera property) which allows to replace shader on all objects.
Answer by HJ05 · Aug 22, 2013 at 10:33 PM
While not a perfect solution it produces an effect close enough to what I was looking for. Using the edge detect effect on the map camera and a modified shader from here: http://answers.unity3d.com/questions/301904/edge-highlighting-shader-with-custom-highlight-col.html I came up with this:
Shader "Custom/Edge Highlight" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Treshold ("Treshold", Float) = 0.2
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
Fog { Mode off }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform float4 _MainTex_TexelSize;
uniform float _Treshold;
struct v2f {
float4 pos : POSITION;
float2 uv[3] : TEXCOORD0;
};
v2f vert( appdata_img v )
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
float2 uv = MultiplyUV( UNITY_MATRIX_TEXTURE0, v.texcoord );
o.uv[0] = uv;
o.uv[1] = uv + float2(-_MainTex_TexelSize.x, -_MainTex_TexelSize.y);
o.uv[2] = uv + float2(+_MainTex_TexelSize.x, -_MainTex_TexelSize.y);
return o;
}
half4 frag (v2f i) : COLOR
{
half4 original = tex2D(_MainTex, i.uv[0]);
// a very simple cross gradient filter
half3 p1 = original.rgb;
half3 p2 = tex2D( _MainTex, i.uv[1] ).rgb;
half3 p3 = tex2D( _MainTex, i.uv[2] ).rgb;
half3 diff = p1 * 2 - p2 - p3;
half len = dot(diff,diff);
if( len >= _Treshold )
original.xyzw = half4(0f,0f,0f,1.0f);
else
original = half4(1f,1f,1f,1.0f);
return original;
}
ENDCG
}
}
Fallback off
}
The background is either white, or if it is above the threshold then the pixel is black.