Yeah, for samplers you have to follow some special rules, the reason being that âtexturesâ and âsamplersâ arenât separated in Unity. Iâll add this to the docs, but the rules for compute shaders are:
Either use same as texture name, with âsamplerâ in front (e.g. Texture2D MyTex; SamplerState samplerMyTex). In this case, sampler will be initialized to that textureâs filter/wrap/aniso settings.
Or use one of âpredefinedâ samplers; name has to have âLinearâ or âPointâ (for filter mode) and âClampâ or âRepeatâ (for wrap mode). Example, âMyLinearClampSamplerâ - this will have linear filter and clamp wrap mode.
In case youâre still having trouble sampling in compute shaders (and for future travellers of this thread): make sure you specify which mipmap level should be used (LOD). (So in compute shaders youâll want to use SampleLevel, in stead of Sample.)
Fragment program 'frag': Unrecognized sampler 'sampler_repeatedtexture' - does not match any texture and is not a recognized inline name (should contain filter and wrap modes).
Is the shader compiler doing âmagicâ in the background and removing samplers in the actual compiled code? From the generated code it looks alrightâŚ
The error shows it written in all lowercase though. Maybe thatâs just an error quirk but maybe you had it written like that at first and it hasnât recompiled?
This should be working fine, this is exactly how itâs used in their shaders too. Have you restarted Unity and reimported the shader as a test? And if so the error repeats itself on reimport?
Yep, that error stays around. My first instinct was also to rename the property to lowercase (_repeatedtexture) instead, but the error persists, also after restarts and library clear.
It seems that the actual reason for this failing is that the shader compiler strips out the texture when itâs not accessed, and when doing so also strips out the sampler, thus resulting in âtotally ok code but the compilation result is still brokenâ. Not sure if thatâs a bug or âby designâ; accessing the sampler but not the texture is surely an edge case.
Iâm not sure how youâre both accessing the texture to get the error, but also supposedly it isnât being accessed when the shader compiler looks at the code⌠Are you saying you have the sampling of it inside of keyword/shader_feature block, and youâre only turning that keyword on at runtime in build? Because that would make sense as unused variants are stripped, which is what multi_compile avoids.
If you are not using the _RepeatedTexture texture, then yes it will be removed as part of compilation. So effectively youâre left with a sampler that has no idea which texture it should get the sampling settings from, since the texture is gone.
I got this in 2023, playing with #pragma multi_compile
As Aras said, looks like the sampler canât find its texture, because the texture gets optimized-away.
Luckily for me, I didnât need to have it belong to any texture, just had to have it as Bilinear+Repeat
So I used SamplerState my_sampler_RepeatPoint; as described at the bottom of