Shaders: Constant register limit exceeded - what does it mean?


I already used Google, tried the search function and also scanned the documents provided by Nvidia, but this keeps me puzzled:

I’m working on a shader that, besides some other stuff, has a secondary texture used for detailing. The texture slot is used for a perlin noise sample, which is called three times with different texture coordinates, then summed up to create a basic fBm. It looks like this:

float subtex = (tex2D(_SubTex, i.tex.xy * _SubTex_ST.xy + ).x - .5 )*SUB_TEX_WEIGHT;
float subtex2 = (tex2D(_SubTex, i.tex.xy * _SubTex_ST.xy * 2 + * 2 ).x - .5)*SUB_TEX_WEIGHT;
float subtex3 = (tex2D(_SubTex, i.tex.xy * _SubTex_ST.xy * 4 + * 4 ).x - .5 )*SUB_TEX_WEIGHT;

but, when I sum up like this:

subtex += subtex2*.5 + subtex3*.25;

I get an error: Constant register limit exceeded; more than 32 constant registers needed to compiled program at line 38

same is for

subtex2 += subtex3*.5;
subtex += subtex2*.5;

or any other variation of this kind. But when I create a new float like this:

float subtexSum = subtex + subtex2*.5 + subtex3*.25;

there is no problem.

I don’t get it. What is the problem with the first and second variant, and why is it working in the final version? Or, what operations are utilizing constant registers and what don’t? Any clarification on this topic would be welcome. Thank you!

Try using #pragma glsl

Adding the above pragma in my case fixed the error.

To see how registers are being used, you can view the compiled shader file that Unity creates.

To fix the problem, try adding #pragma target 3.0