- Home /
Drawing silhouette shader
Hello there, this shader should draw a silhouette before the actual model gets drawn. This is a surface shader so there are not really passes but it should work anyway. However, I need shadows and that's why I decided to use a surface shader.
The Problem is that my silhouette does not get drawn correctly. I think there is something wrong in the Queue, ZWrite or Culling.
All objects in the scene are using the same shader. The silhouette only gets drawn when no object is behind it (only the skybox). I want the silhouette to always be drawn.
Can someone help me out?
Shader "Shadow Silhouette" {
Properties{
_Color("Color", Color) = (1,1,1,1)
_MainTex("Albedo (RGB)", 2D) = "white" {}
_Glossiness("Smoothness", Range(0,1)) = 0.5
_Metallic("Metallic", Range(0,1)) = 0.0
_OutlineWidth("OutlineWidth", Range(0,0.10)) = 0.01
_OutlineColor("OutlineColor", Color) = (1,1,1,1)
}
SubShader{
// Draw a silhouette
Tags{ "Queue" = "Geometry+1" }
LOD 200
ZWrite Off
CGPROGRAM
#pragma surface surf Standard fullforwardshadows vertex:vert
#pragma target 3.0
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
fixed4 _OutlineColor;
float _OutlineWidth;
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_INSTANCING_BUFFER_END(Props)
void vert(inout appdata_full v) {
v.vertex.xyz += float3(v.normal.xyz)*_OutlineWidth;
}
void surf(Input IN, inout SurfaceOutputStandard o) {
o.Albedo = _OutlineColor;
}
ENDCG
// Draw the object
Tags{ "RenderType" = "Opaque" "Queue" = "Geometry+1" }
LOD 200
ZWrite On
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 3.0
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_INSTANCING_BUFFER_END(Props)
void surf(Input IN, inout SurfaceOutputStandard o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Thank you
Your answer
Follow this Question
Related Questions
How to add Emission to my custom shader? 2 Answers
Shader - What is float3.xy? 1 Answer
Shader: Modify XY Position of Texture 0 Answers
Adding a clip() to the default shader? 0 Answers
Surface shader changing z value 0 Answers