I am using Unity 2021.3.21f1 and URP 12.1.10
I slightly modified the standard URP Lit shader. I managed to fix many compilation errors, but I can not fix one error for several days. Moreover, this error does not occur during normal compilation in the Uity editor - IT OCCURRS ONLY WHEN BUILDING THE WHOLE PROJECT.
The error is like this:
Shader error in ‘GK/URP_Lit’: Fragment program ‘DepthNormalsFragment’: Unrecognized sampler ‘sampler_basemap’ - does not match any texture and is not a recognized inline name (should contain filter and wrap modes). at line 266 (on d3d11)
As you can see, the error is in the ‘GK/URP_Lit’ shader and is related to the ‘DepthNormals’ pass, specifically in the fragment program ‘DepthNormalsFragment’, which is located in the GK_URP_LitDepthNormalsPass.hlsl file at the very bottom.
This is all clear. But there are questions.
- There is no ‘sampler_basemap’ sampler in this shader, there is only such ‘sampler_BaseMap’.
- If line 93 :
float3 normalTS = SampleNormal( uv, TEXTURE2D_ARGS(_NormalMap, sampler_BaseMap), _NormalMul );
replace with this
float3 normalTS = float3(0.0, 0.0, 1.0);
then the ERROR DOES NOT occur, and a little higher in the DepthNormalsFragment() function there is line 77
Alpha( SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a, _BaseColor, _Cutoff );
it also uses sampler_BaseMap and there are no errors! - Another ‘ForwardLit’ pass also uses the sampler_BaseMap sampler for _BaseMap, _NormalMap, _MetallicMap, _RoughnessMap textures and everything is fine - no errors.
You can, of course, create your own sampler for _NormalMap and use it, but I want to figure out why sampler_BaseMap works for _NormalMap for one pass, but does not work for another pass.
Also noticed one not clear moment.
For the ForwardLit pass in the Varyings structure (file GK_URP_LitForwardPass.hlsl) for uv, TEXCOORD0 is used:
float2 uv : TEXCOORD0;
And for the DepthNormals pass in the Varyings structure (GK_URP_LitDepthNormalsPass.hlsl file) for uv, TEXCOORD1 is used:
float2 uv : TEXCOORD1;
Why?