|
I'm trying to make an outline shader that only shows outline from the model's silhouette, to be used as indication that the character has been selected. the current problem with this one is the outline doesn't show in the feet, because of the offset, it gets hidden by the ground. I want the outline to be above the terrain, but below the character.
Here is the code:
(comments are locked)
|
|
I'll post this as an answer because it's another possibility, not sure if it's costly when scaled. It's simple but may prove to be unpractical to manage at some point(in case you modify the camera a lot). Using the first shader posted, you duplicate your camera and create one new layer, let's call it 'Outlined'. You select your object that has the mesh with that shader, and change the layer to 'Outlined'. On one camera, you only change the culling mask value, removing the 'Outlined' layer from it. On the other, you have to change three values:
This works properly and may be a valid option.
(comments are locked)
|
|
Won't disabling the depth test with ZTest Always for the outline-mesh do the trick? Also, this will cause the outline to appear "through" other objects - but since you are doing this to indicate selection, this is probably acceptable.
(comments are locked)
|
|
this is not exactly what asked for, but methinks this is a good alternative to do outline with low CPU/GPU load. real outline will take much more improvements to achieve. Shader "Unity Answers/Diffuse Rim"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" { }
_Color ("Main Color", Color) = (.5,.5,.5,1)
_OutlineColor ("Outline Color", Color) = (0,0,0,1)
_OutlineOffset ("Outline offset", Range (0, 1)) = 0.1
_OutlineSize ("Outline size", Range (0, 1)) = 0.1
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
fixed4 _Color;
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;
}
ENDCG
//ouline pass
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
Cull Back
Offset -1, -1
Lighting Off
ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
float _OutlineOffset;
float _OutlineSize;
fixed4 _OutlineColor;
uniform float4x4 _Object2World, _World2Object;
uniform float3 _WorldSpaceCameraPos;
uniform float4 _Time;
struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct v2f
{
float4 pos : SV_POSITION; // project view position
float4 wPos : TEXCOORD0; // world-based position
float4 wNor : TEXCOORD1; // world-based normal
};
v2f vert(appdata v)
{
v2f o;
v.vertex.xyz += _OutlineOffset * v.normal;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.wPos = mul(_Object2World, v.vertex);
o.wNor = mul(_Object2World, float4(v.normal.xyz, 0));
return o;
}
half4 frag(v2f i) : COLOR
{
float3 worldNormal = normalize(i.wNor.xyz);
float3 worldToCameraDirection = normalize(_WorldSpaceCameraPos - i.wPos.xyz);
half4 answer = _OutlineColor;
answer.a *= saturate((_OutlineSize - dot(worldNormal, worldToCameraDirection)) * 100f);
return answer;
}
ENDCG
}
}
}
(comments are locked)
|


Have you solved this yet?
There was one from memory on the UnifyCommunity (wiki) 'site, but of course that is out of action right now. This was the link : http://unifycommunity.com/wiki/index.php?title=ShadowAndOutline
Does anyone have this script ?
Edit : whydoidoit is correct, I was thinking of : http://wiki.unity3d.com/index.php/Silhouette-Outlined_Diffuse
http://webcache.googleusercontent.com/search?q=cache:OwN7XgF6rdkJ:unifycommunity.com/wiki/index.php%3Ftitle%3DShadowAndOutline+&cd=1&hl=ru&ct=clnk≷=ru
Looks like that script is for GUI not for models.
Just to "outline" the issue, the main problem is how the shader uses a mesh copy of your model to outline it, so it is limited in the same way a normal model would be. Considering this, right now I can only think of using multiple cameras, rendering only specific layers, in this order for example: Ground - Shader - Character. I'm sure this can work with some testing put into it. Good luck for now, I'll try to test this so I can post an answer.