Hi guys,
I am experiencing an annoying issue when trying to create a Unlit shader supporting GPU Instancing.
It works fine if I don’t put any lights, or if all my objects are affected by the same lights. In this example, my two red sphere use my custom unlit shader and are properly GPU instanced :

But if I put a light (like a spotlight) which only affects one of my sphere, it will break the instancing.
Here is the setup in the editor scene view :

And the broken instancing result:
Here is the test shader I am using :
Shader "Unlit/CustomUnlit"
{
Properties { }
SubShader
{
LOD 100
Pass
{
ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#pragma multi_compile_instancing
#include "UnityCG.cginc"
struct v2f
{
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
v2f vert (appdata_base v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_TRANSFER_INSTANCE_ID(v, o);
o.vertex = UnityObjectToClipPos(v.vertex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(i);
fixed4 col = float4(1,0,0,1);
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
I am using a deferred camera. But you can see in the Frame Debugger that after the “RenderDeferred” pass, it draws an additional “RenderForwardOpaque” pass which seems to be the issue. Because if I use a standard build-in shader, it works and the “RenderForwardOpaque” doesn’t appear in the Frame Debugger:
Note that I don’t care about lighting on my Unlit shader. I don’t want it to cast or receive shadows/lights.
What am I missing?
Thanks

