How to make this shader effectable in defered render path?

Shader “Selected Effect — Outline/Extrude Vertex/Standard” {
Properties {
_MainTex (“Main”, 2D) = “white” {}
_BumpMap (“Bump”, 2D) = “bump” {}
_Glossiness (“Smoothness”, Range(0, 1)) = 0.5
_Metallic (“Metallic”, Range(0, 1)) = 0
_OutlineWidth (“Outline Width”, Float) = 0.1
_OutlineColor (“Outline Color”, Color) = (0, 1, 0, 1)
_OutlineFactor (“Outline Factor”, Range(0, 1)) = 1
_Overlay (“Overlay”, Float) = 0
_OverlayColor (“Overlay Color”, Color) = (1, 1, 0, 1)
[MaterialToggle] _OutlineWriteZ (“Outline Z Write”, Float) = 1.0
[MaterialToggle] _OutlineBasedVertexColorR (“Outline Based Vertex Color R”, Float) = 0.0
}
SubShader {
Tags { “RenderType” = “Opaque” “Queue” = “Geometry+1” }
Pass {
Cull Front
ZTest Less
ZWrite [_OutlineWriteZ]

CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include “Outline.cginc”
ENDCG
}

CGPROGRAM
#pragma surface surf Standard
sampler2D _MainTex, _BumpMap;
float4 _OverlayColor;
float _Overlay, _Glossiness, _Metallic;
struct Input
{
float2 uv_MainTex;
float2 uv_BumpMap;
};
void surf (Input IN, inout SurfaceOutputStandard o)
{
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = lerp(c.rgb, _OverlayColor.rgb, _Overlay);
o.Alpha = c.a;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
}
ENDCG
}
FallBack “Diffuse”
}

This is a outline shader ,in my test it is effectable in forward render path,but invalid for defered render path… What is the issue of this shader?

The outline pass will default to be a forward pass. If you’re using a deferred rendering path and a shader has a deferred pass (which the surface shader is generating in this case) all forward passes will be ignored. You’d have to write an outline pass that works with deferred.

https://discussions.unity.com/t/615369

Also be weary that disabling the ZWrite for a deferred pass can have some weird artifacts.

The alternative is to use two separate materials, one that renders the object using deferred and one that renders the outline as a separate forward pass. But in that scenario the outline will always be rendered after the deferred pass so disabling the ZWrite will not result in it being a silhouette only outline like it would when rendering using the forward rendering path.

1 Like

Thanks for your impatient answer very much:smile: My knowledge about renderer or shader within Unity is kinda scrappy and incoherent. I want to get a solid knowledge about them. Is there some good book or systematic articles for learning?:slight_smile:

1 Like