shader error in 'universal render pipeline/lit': maximum ps_4_0 sampler register index (16) exceeded

Hi, will the unity team ever fix this issue that stops me from building? This error shouldnt happen in the Lit shader ever. I’ve noticed that it may happen in shadergraphs that use many textures after a lot of google searches. But the Lit shader doesnt use that many textures. I’ve had a bug report on this for more than 6 months. When will it get fixed? I somehow managed to build until now by reimporting the URP assets every time i tried to build but that doesnt work anymore. I just tested in 2021.2.3,4,5,6,7,8,9,10 and 14, and in 2022.1.0b11. I am stuck because of this and it doesnt seem like it will be fixed soon. I’ve been promised in my bug report that it will get fixed after the christmas vacantions, but it’s 12 march and this stuff is still going on. It’s somewhat outrageous if you ask me.

7958607--1019922--upload_2022-3-12_12-22-29.png

I made this thread a while ago too: Shader error in 'Universal Render Pipeline/Lit' URP 12

Nobody seems to care about this problem. It may not happen for everybody because usually people dont have big projects but im definitely not the only person with a big project here. I think the cause is many lit materials and not everybody has this many lit shader materials in the project.

2 Likes

Well my assumption seems correct. So i added 3 more maps in my game and all of those environment assets had urp/lit shader. Before adding those maps i could bypass the error by reimporting the urp asset and forward renderer before building. After adding those maps i couldnt. I made all those materials simple lit and now i can build again.

There are weird issues going on with the lit shader since urp 12. Hope they will be fixed soon. Simple lit doesnt look the way i want, i need the lit shader.

just contacted unity about this as well, pretty much a won’t fix

so much for a production ready LTS release, huh?
can’t even use the shipped shaders since they’ll break with no explanation or workaround

4 Likes

Further questioning:

Hi there, I must’ve missed this reply, this is a game-breaking bug but it wont be fixed anytime soon? I just upgraded to 2021.3 and i cannot build again. Wow.

Was this helpful for you? Can you give me more details please?

Just popping this in here as well in case anyone else needs this info (swontonb and I had a little chat via dms)

how do you even modify the lit shader? It comes back to default code after compiling, since its in packages folder.

You just copy the URP package from Library/PackageCache/com.unity.render-pipelines.universal@12.1.6 to the Packages folder (so you end up with Packages/com.unity.render-pipelines.universal@12.1.6) and that makes unity use the local folder instead of re-downloading it

As for what features to remove… if you dont use light cookies for example you should be able to just edit the Lit shader and comment out all the “#pragma multi_compile _ _LIGHT_COOKIES”
If you don’t use Decals you can comment out the “#pragma multi_compile _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3” etc
(there’s gonna be multiple of that in the shader)

For me taking out light cookies solved the sampler issues, but your project may have different needs

If you use the shadergraph you’ll also have to modify the keywords shadergraph adds (which was easier than expected, code is quite tidy), you want to look at the URP/Editor/ShaderGraph/Targets/UniversalTarget.cs there
For light cookies, thats on line 1783 in 12.1.6, you can now look at the uses via your IDE of choice or, if you’re just using lit targets the exact spot where its referenced is in UniversalLitSubTarget.cs line 814 onwards - just remove it from there and shader graph shaders wont reference it either anymore
For example:

As a side effect, removing multicompile keywords will also reduce your shader build time, which is also a huge issue with 2021 lts :slight_smile:

7 Likes

Dang man you saved my life! Allthough i was using light cookies i choose the ability to build. All i did was saying #define light cookies instead of #pragma multi_compile, as you mentioned in the 2nd post, in the urp lit shader code and the variants went from 1500M to 250M. Unity URP team messed up the light cookies, that was the cause of the sampler limit. I did that because i read your other post here:

Btw if you want to use decals it’s safe to do it, light cookies seem to be the main problem. I use decals for bullet marks and blood splatters.

Regarding huge build times… i kinda got used to it, the first build takes ages, the second is faster. Without cookies its a lot of times faster (from 1500M variants to 250M).

Thanks a lot man! If it wasnt for you to have this issue and be able to report it I’d be stuck forever. My project is 90 gb, kinda hard to send a bug report with it.

2 Likes

OMG! Thank you so much! After I commented out the cookies, the installation package was reduced from 1GB to 700MB, the build time was reduced from 5 hours to 2 hours, and the RAM usage was also reduced…

3 Likes

Your sir, have saved my life.

Linux 2021.3.16f1 building to Android (Quest 2).

com.unity.render-pipelines.universal@12.1.8

All I had to do was comment out lit.shader lines 125 and 435 which are the //#pragma multi_compile_fragment _ _LIGHT_COOKIES

Now, nothing is ever easy so I suspect this will come back to haunt me one day.

But in the meantime, thank you very much!

P.S issue only occurred in the scene after i used lightmapping.

In my non-lightmapped scene there is no problem.

Don’t worry, this is still the case even in latest beta… to which i decided to switch just to see if i will be able to build… but guess what… i can’t… latest 2022.x fails to build with some errors that can not be even traced… and latest 2023.beta just gives me the same error as original post… so guess how much you can rely on URP

Getting this on 2022.3.0. I use light cookies, but disabling the feature in the URP pipeline asset files didn’t prevent the error anyway. Suddenly unable to build my project… what gives!?

Update: After digging through my recent commit history, it seems that this error is being caused by enabling LOD Cross Fade on my URP pipeline asset. The build actually still goes ahead but this error is logged in the background:

Shader error in 'Universal Render Pipeline/Lit': maximum ps_4_0 sampler register index (16) exceeded at /Users/Joe/Documents/Workspace/Hobble/Library/PackageCache/com.unity.render-pipelines.universal@14.0.7/ShaderLibrary/LightCookie/LightCookieInput.hlsl(12) (on d3d11)

Compiling Subshader: 0, Pass: ForwardLit, Fragment program with LIGHTMAP_ON LOD_FADE_CROSSFADE _ADDITIONAL_LIGHTS _ADDITIONAL_LIGHT_SHADOWS _DETAIL_MULX2 _EMISSION _LIGHT_COOKIES _MAIN_LIGHT_SHADOWS _METALLICSPECGLOSSMAP _NORMALMAP _OCCLUSIONMAP _REFLECTION_PROBE_BLENDING _REFLECTION_PROBE_BOX_PROJECTION _SCREEN_SPACE_OCCLUSION _SPECULAR_SETUP
Platform defines: SHADER_API_DESKTOP UNITY_ENABLE_DETAIL_NORMALMAP UNITY_ENABLE_REFLECTION_BUFFERS UNITY_LIGHTMAP_FULL_HDR UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BLENDING UNITY_SPECCUBE_BOX_PROJECTION UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS
Disabled keywords: DEBUG_DISPLAY DIRLIGHTMAP_COMBINED DOTS_INSTANCING_ON DYNAMICLIGHTMAP_ON EVALUATE_SH_MIXED EVALUATE_SH_VERTEX FOG_EXP FOG_EXP2 FOG_LINEAR INSTANCING_ON LIGHTMAP_SHADOW_MIXING SHADER_API_GLES30 SHADOWS_SHADOWMASK UNITY_ASTC_NORMALMAP_ENCODING UNITY_COLORSPACE_GAMMA UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_HARDWARE_TIER3 UNITY_LIGHTMAP_DLDR_ENCODING UNITY_LIGHTMAP_RGBM_ENCODING UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_NO_DXT5nm UNITY_NO_FULL_STANDARD_SHADER UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 UNITY_PBS_USE_BRDF3 UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_UNIFIED_SHADER_PRECISION_MODEL UNITY_VIRTUAL_TEXTURING _ADDITIONAL_LIGHTS_VERTEX _ALPHAMODULATE_ON _ALPHAPREMULTIPLY_ON _ALPHATEST_ON _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3 _DETAIL_SCALED _ENVIRONMENTREFLECTIONS_OFF _FORWARD_PLUS _LIGHT_LAYERS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN _PARALLAXMAP _RECEIVE_SHADOWS_OFF _SHADOWS_SOFT _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A _SPECULARHIGHLIGHTS_OFF _SURFACE_TYPE_TRANSPARENT _WRITE_RENDERING_LAYERS

same fix as above, take the URP package from library>package cache, paste it in packages folder, right near the manifest. This way you can edit the lit shader and comment light cookies. That’s the only way to get rid of maximum sampler error

For me 2022.3 brought whole new bunch of errors, like 10-15 errors in all URP shaders. The merging shaders into one was a big fail and i basically cannot send a bug report. It only happens when the project is big and has a lot of materials I believe, just like the maximum sampler error. It cant be reproduced in a small project, you must have thousands of materials.

Your tweak means we cannot use Light Cookies right?

yes but, well, its either use cookies or build your project. Which one would you choose? hehe

1 Like

Neither. :smile: I’ll try sending a repro bug to Unity.

Really sorry to inform you but this will probably never get fixed

https://issuetracker.unity3d.com/issues/sampler-limit-16-exceeded-in-urp-lit-shader

It’s a too deep issue and requires rewriting the pipeline or something.

1 Like

The option to disable the quite frankly rarely-used Light Cookies in the pipeline settings would be a start.

well that won’t work, I tested it before finding the solution that actually worked (commenting cookies in the shader directly)

Right. To why can’t Unity supply a proper fix rather than us relying on this hack?