Cannot compile shader because of Error [SM5] warning: Line number "32768

Hello,

I have a shader that is made up of several material functions. I modified one of them and since then I have the following error that prevent me to compile the shader:

Error [SM5] warning: Line number “32768” got beyond range
MaterialFloat Local31559 = floor(Local31558);
from …/…/…/Engine/Shaders/BasePassPixelShader.usf: 10: #include “Material.usf”

One of the function nodes is repeated several times and if I put the Output node in the middle of the tree the shader compiles and if I put it at the end it doesn’t, very likely because of a generated shader file that exceeds the maximum number of lines.

The thing is: Am I really generating a 32768 lines shader???

How can I fix the issue?

I can post an archive with the shader code if required.

Thanks a lot for any help!!!

Did you every find a workaround for this? Currently I have the same problem in my post processing material. I would find it very odd if there really is a hard limit of 32768 lines in the compiled shader that can be hit quite easily with a complex material. Would be nice if someone of Epic can also weight in here.

You should never be able to hit the limit under normal conditions. This is most likely a sign, that something is off in your material.

I know this is an old post, but I just stumbled upon this. I’ll post my workaround in case anyone else runs into it.

a) When doing a lot of editing Unreal doesn’t properly clean up stale data. To fix this delete all the nodes in your shader, re-compile (and fix any errors), then re-paste them back in. Alternatively, you can close Unreal and reopen it.

b) There are cases where a material goes legitimately over the line limit. Unreal adds a lot of lines to your material and the preprocessor bloats it even more (MCPP in ThirdParty). Especially if you have a lot of static switches (and/or static parameter switches). I hit this case. The preprocessor is complaining there are “#line” directives in lines over 32768 and because mcpp was written a long time ago and you may be dealing with a compiler/processor that only handles 16-bit addressing, it issues a warning.
Seeing as any compiler/processor we deal with is most probably going to handle above-16 bit addressing, the error can be filtered out. Note that it’s not the number of lines in the material necessarily, but what’s the largest line number used in a preprocessor directive. My material now has 88445 lines when fully expanded (I use a ton of static switches), but shuffling nodes around I was able to sometimes get rid of the error because the last directive can end up before the threshold depending on how you structure your code.

MCPP is called from Engine\Source\Developer\ShaderPreprocessor\Private\ShaderPreprocessor.cpp in “PreprocessShader”. You could filter that error out there, then recompile the “ShaderCompilerWorker” program (in Visual Studio under "Programs). ShaderCompilerWorker is the external program that compiles shaders in the background.

There is already a function for filtering out MCPP errors you don’t care about. It’s in Engine\Source\Developer\ShaderPreprocessor\Private\PreprocessorPrivate.h, in “FilterMcppError”. Add “32768” in that line, compile “ShaderCompileWorker”, then run the editor again.

c) You can also break the material down to smaller, more specialized materials, but that approach has its own pluses and minuses.

Just stumbled upon this. Great catch! We’ll add an internal ticket to look into this; we haven’t generated files with that many lines, so we’ll have to figure out if we replace mcpp with another preprocessor or try to fix it. I’m afraid we don’t have a quick solution right now, except follow what rantrod menioned.