- Home /
Shaders: Constant register limit exceeded - what does it mean?
Hello,
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 + _SubTex_ST.zw ).x - .5 )*SUB_TEX_WEIGHT;
float subtex2 = (tex2D(_SubTex, i.tex.xy * _SubTex_ST.xy * 2 + _SubTex_ST.zw * 2 ).x - .5)*SUB_TEX_WEIGHT;
float subtex3 = (tex2D(_SubTex, i.tex.xy * _SubTex_ST.xy * 4 + _SubTex_ST.zw * 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!
Answer by ilya_ca · Jul 26, 2014 at 10:13 AM
Try using #pragma glsl
Adding the above pragma in my case fixed the error.
I'm still not sure why it behaves that way, but this at least fixed it. Thank you.
Answer by tanoshimi · Jul 26, 2014 at 12:01 PM
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
Your answer
![](https://koobas.hobune.stream/wayback/20220613145952im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Additional blending when using properties rather than hard-coded values for colors 0 Answers
How to render a Cube using Shaders? 0 Answers
Multipass Surface Shader (or equivalent)? 2 Answers
How to force the compilation of a shader in Unity? 5 Answers
Parse error: Syntax Error in compiled shader, Unity 4.3.1 [free] 1 Answer