Hi, I’m developing a replacement shader. Usually it’s using a tag to branch subshaders in the replacement shader, Usually a RenderType tag is used for branching. However, the problem: looks like it’s limited to only one pass or I dunno, which causing problems with shadows. For example I have a subshader for “opaque” tag that is fully rendering colors and so, but if I have multiple objects with this tag in the scene they are not casting shadow on themselves. I was trying to add a shadow caster pass inside a subshader just like ordinary shaders do but it’s failled to compile every time.
For example:
SubShader
{
Tags{ "RenderType" = "Opaque" }
Pass
{
Tags {"LightMode" = "ShadowCaster"}
Offset 1, 1
Cull Off
ZWrite On
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_shadowcaster
#include "UnityCG.cginc"
struct v2f {
V2F_SHADOW_CASTER;
};
v2f vert(appdata_base v)
{
v2f o;
TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
return o;
}
float4 frag(v2f i) : SV_Target
{
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}
}
This subshader working correctly but ofc not drawing nothing but shadows.
and this subshader is just draws colors but cannot draw shadows from the objects that has been using this subshader. how to make a subshader with 2 passes that would be working with the replacement?:
SubShader
{
Tags{ "RenderType" = "Opaque" "Queue" = "AlphaTest-41" }
Cull Back
CGPROGRAM
#include "UnityPBSLighting.cginc"
#include "UnityCG.cginc"
#include "UnityStandardUtils.cginc"
#include "UnityShaderVariables.cginc"
#include "Tessellation.cginc"
#pragma target 5.0
#pragma only_renderers d3d9 d3d11_9x d3d11
#pragma surface surf StandardCustomLighting keepalpha addshadow fullforwardshadows vertex:vertexDataFunc tessellate:tessFunction tessphong:_TessPhongStrength
struct Input
{
float2 uv_texcoord;
float3 worldPos;
float3 worldNormal;
INTERNAL_DATA
float2 uv2_texcoord2;
float4 vertexColor : COLOR;
};
struct SurfaceOutputCustomLightingCustom
{
half3 Albedo;
half3 Normal;
half3 Emission;
half Metallic;
half Smoothness;
half Occlusion;
half Alpha;
Input SurfInput;
UnityGIInput GIData;
};
inline float3 ASESafeNormalize(float3 inVec)
{
float dp3 = max(0.001f , dot(inVec , inVec));
return inVec * rsqrt(dp3);
}
float4 tessFunction(appdata_full v0, appdata_full v1, appdata_full v2)
{
return UnityDistanceBasedTess(v0.vertex, v1.vertex, v2.vertex, _TessMin, _TessMax, _TessValue);
}
void vertexDataFunc(inout appdata_full v)
{
}
inline half4 LightingStandardCustomLighting(inout SurfaceOutputCustomLightingCustom s, half3 viewDir, UnityGI gi)
{
UnityGIInput data = s.GIData;
Input i = s.SurfInput;
half4 c = 0;
c.rgb = 1.0;
c.a = 1;
clip1.0 - _Cutoff);
return c;
}
inline void LightingStandardCustomLighting_GI(inout SurfaceOutputCustomLightingCustom s, UnityGIInput data, inout UnityGI gi)
{
s.GIData = data;
}
void surf(Input i , inout SurfaceOutputCustomLightingCustom o)
{
o.SurfInput = i;
o.Normal = float3(0,0,1);
}
ENDCG
}