URP_ShaderGraphCustomLighting
URP_ShaderGraphCustomLighting copied to clipboard
Invalid subscript 'ShadowCoord' compilation error for unlit graph in 2020 LTS/URP 10.8.1
Hi,
I get this error on shader compilation when using a 2020 LTS with custom lighting.
It looks like a relevant fix for this was made on the URP repo. It consists of :
https://github.com/Unity-Technologies/Graphics/pull/3551/files
where the fix was to add a check for defined(VARYINGS_NEED_SHADOW_COORD)
in Varyings.hlsl:
#if defined(VARYINGS_NEED_SHADOW_COORD) && defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
However, the URP version used on 2020 LTS still uses the old test:
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
so it requires a different workaround.
This repo has a test starting on line 38:
#ifndef SHADERGRAPH_PREVIEW
#if VERSION_GREATER_EQUAL(9, 0)
#include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
#if (SHADERPASS != SHADERPASS_FORWARD)
#undef REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR
#endif
#else
#ifndef SHADERPASS_FORWARD
#undef REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR
#endif
#endif
#endif
which undefines the statement so that Varyings.hlsl does not try to reference shadowCoord.
In my case, this still resulted in errors in the console. The reason was because the custom lighting nodes (and related includes) were only included on shadergraph paths that calculated color. The shadowcaster pass does not calculate color, so it doesn't make the custom lighting include, does not make the undef and so still throws the errors. The fix for me was to wire a custom function to the alpha node so that it makes the include and then also correctly undefs the shadowcaster pass.
(Issue can be closed, I hope the info is useful to others)