Reputation: 419
I'm trying to discard a fragment, but I also want to be able to compare color on the texture to other parts of the texture. It seems like if fragments get discarded, I can't check those areas of the texture anymore. How would I be able to either check the color, or check if it is discarded so that it won't check, and thus have no errors.
Here's some code to illustrate the issue.
bool diagonal = (sS==0.0&&nS==0.0&&((cornerSign.x*cornerSign.y==1.0&&cC.rgb==cNW.rgb&&cNW.rgb==cSE.rgb&&((cNE.rgb!=cC.rgb&&cornerSign.x>0.0&&cN.rgb==cE.rgb)||(cSW.rgb!=cC.rgb&&cornerSign.x<0.0&&cS.rgb==cW.rgb)) )||(cornerSign.x*cornerSign.y==-1.0&&cC.rgb==cNE.rgb&&cNE.rgb==cSW.rgb&&((cNW.rgb!=cC.rgb&&cornerSign.x<0.0&&cN.rgb==cW.rgb)||(cSE.rgb!=cC.rgb&&cornerSign.x>0.0&&cS.rgb==cE.rgb)) )));
vec4 mixedColor = ((diagonal?vec4(0.0):step(1.0,tColor.a)*tColor)+(step(1.0,tColor2.a)*tColor2)+(step(1.0,tColor3.a)*tColor3)+(diagonal?vec4(0.0):(step(1.0,tColor4.a)*tColor4)))/(diagonal?step(1.0,tColor2.a)+step(1.0,tColor3.a):step(1.0,tColor.a)+step(1.0,tColor2.a)+step(1.0,tColor3.a)+step(1.0,tColor4.a));
mixedColor.a = min(1.0,step(1.0,tColor2.a)+step(1.0,tColor3.a)+step(1.0,tColor4.a));
vec4 newColor = (sS==0.0&&nS>=2.0)||(sS==0.0&&oS==2.0)||(sS==0.0&&tS==2.0&&fColor.rgb!=tColor.rgb)||diagonal?mixedColor:tColor;
vec4 middlePart = (min(1.0,(1.0-step(subRadius,subDistance))+(1.0-step(1.0,subSign.x*cornerSign.x))+(1.0-step(1.0,subSign.y*cornerSign.y)))*(wedged?wedgeColor:tColor));
vec4 outerPart = (clamp((step(subRadius,subDistance))-((1.0-step(1.0,subSign.x*cornerSign.x))+(1.0-step(1.0,subSign.y*cornerSign.y))),0.0,1.0)*(wedged?wedgeColor:newColor));
//diagonals
vec4 middlePartDiagonal = (min(1.0,(1.0-step(subRadius,abs(vUv.x-subPoint.x)+abs(vUv.y-subPoint.y)))+(1.0-step(1.0,subSign.x*cornerSign.x))+(1.0-step(1.0,subSign.y*cornerSign.y)))*tColor);
vec4 outerPartDiagonal = (clamp((step(subRadius,abs(vUv.x-subPoint.x)+abs(vUv.y-subPoint.y)))-((1.0-step(1.0,subSign.x*cornerSign.x))+(1.0-step(1.0,subSign.y*cornerSign.y))),0.0,1.0)*newColor);
gl_FragColor = (diagonal?middlePartDiagonal+outerPartDiagonal:middlePart+outerPart);
vec4 tColor = texture2D(texture, vUv);
vec4 colorTest = texture2D(texture, vUv+vec2(-1.0/textureWidth,1.0/textureHeight));
gl_FragColor = tColor;
if(gl_FragColor.a < 0.5 ) discard;
else gl_FragColor = colorTest;
the errors I get:
warning X4121: gradient-based operations must be moved out of flow control to prevent divergence. Performance may improve by using a non-gradient operation
(802,1): error X4505: maximum temp register index exceeded
(805,1): error X4505: maximum temp register index exceeded
(808,1): error X4505: maximum temp register index exceeded....continued..
--
edit: here is some other lines, not sure if this is affecting anything:
//the colors for a 3by3 pixel area
vec4 cNW = texture2D(texture, vUv+vec2(-1.0/textureWidth,1.0/textureHeight));
vec4 cN = texture2D(texture, vUv+vec2(0.0,1.0/textureHeight));
vec4 cNE = texture2D(texture, vUv+vec2(1.0/textureWidth,1.0/textureHeight));
vec4 cW = texture2D(texture, vUv+vec2(-1.0/textureWidth,0.0));
vec4 cC = texture2D(texture, vUv);
vec4 cE = texture2D(texture, vUv+vec2(1.0/textureWidth,0.0));
vec4 cSW = texture2D(texture, vUv+vec2(-1.0/textureWidth,-1.0/textureHeight));
vec4 cS = texture2D(texture, vUv+vec2(0.0,-1.0/textureHeight));
vec4 cSE = texture2D(texture, vUv+vec2(1.0/textureWidth,-1.0/textureHeight));
//more colors for 5x5 area
vec4 cNWNW = texture2D(texture, vUv+vec2(-2.0/textureWidth,2.0/textureHeight));
vec4 cNWN = texture2D(texture, vUv+vec2(-1.0/textureWidth,2.0/textureHeight));
vec4 cNWW = texture2D(texture, vUv+vec2(-2.0/textureWidth,1.0/textureHeight));
vec4 cNN = texture2D(texture, vUv+vec2(0.0/textureWidth,2.0/textureHeight));
vec4 cWW = texture2D(texture, vUv+vec2(-2.0/textureWidth,0.0/textureHeight));
vec4 cNENE = texture2D(texture, vUv+vec2(2.0/textureWidth,2.0/textureHeight));
vec4 cNEN = texture2D(texture, vUv+vec2(1.0/textureWidth,2.0/textureHeight));
vec4 cNEE = texture2D(texture, vUv+vec2(2.0/textureWidth,1.0/textureHeight));
vec4 cEE = texture2D(texture, vUv+vec2(2.0/textureWidth,0.0/textureHeight));
vec4 cSESE = texture2D(texture, vUv+vec2(2.0/textureWidth,-2.0/textureHeight));
vec4 cSES = texture2D(texture, vUv+vec2(1.0/textureWidth,-2.0/textureHeight));
vec4 cSEE = texture2D(texture, vUv+vec2(2.0/textureWidth,-1.0/textureHeight));
vec4 cSS = texture2D(texture, vUv+vec2(0.0/textureWidth,-2.0/textureHeight));
vec4 cSWSW = texture2D(texture, vUv+vec2(-2.0/textureWidth,-2.0/textureHeight));
vec4 cSWS = texture2D(texture, vUv+vec2(-1.0/textureWidth,-2.0/textureHeight));
vec4 cSWW = texture2D(texture, vUv+vec2(-2.0/textureWidth,-1.0/textureHeight));
//count sub sections that are the same as subpixel
/* clockwise order
12
43
03,04,02,03
02,01,01,04
04,01,01,02
03,02,04,03
*/
mat4 subC = mat4(0.0);
//first section (topleft corner)
vec3 checking = vec3(1.0)-ceil(abs(cC.rgb-cN.rgb));
subC[0][0] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cC.rgb-cW.rgb));
subC[0][0] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cW.rgb-cNW.rgb));
subC[0][1] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cW.rgb-cC.rgb));
subC[0][1] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cNW.rgb-cN.rgb));
subC[0][2] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cNW.rgb-cW.rgb));
subC[0][2] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cN.rgb-cNW.rgb));
subC[0][3] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cN.rgb-cC.rgb));
subC[0][3] += (checking.x*checking.y*checking.z);
//(topright corner)
checking = vec3(1.0)-ceil(abs(cC.rgb-cN.rgb));
subC[1][0] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cC.rgb-cE.rgb));
subC[1][0] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cN.rgb-cNE.rgb));
subC[1][1] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cN.rgb-cC.rgb));
subC[1][1] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cNE.rgb-cN.rgb));
subC[1][2] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cNE.rgb-cE.rgb));
subC[1][2] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cE.rgb-cNE.rgb));
subC[1][3] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cE.rgb-cC.rgb));
subC[1][3] += (checking.x*checking.y*checking.z);
//(bottomright corner)
checking = vec3(1.0)-ceil(abs(cC.rgb-cE.rgb));
subC[2][0] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cC.rgb-cS.rgb));
subC[2][0] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cE.rgb-cC.rgb));
subC[2][1] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cE.rgb-cSE.rgb));
subC[2][1] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cSE.rgb-cE.rgb));
subC[2][2] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cSE.rgb-cS.rgb));
subC[2][2] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cS.rgb-cC.rgb));
subC[2][3] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cS.rgb-cSE.rgb));
subC[2][3] += (checking.x*checking.y*checking.z);
//(bottomleft corner)
checking = vec3(1.0)-ceil(abs(cC.rgb-cW.rgb));
subC[3][0] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cC.rgb-cS.rgb));
subC[3][0] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cS.rgb-cC.rgb));
subC[3][1] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cS.rgb-cSW.rgb));
subC[3][1] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cSW.rgb-cW.rgb));
subC[3][2] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cSW.rgb-cS.rgb));
subC[3][2] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cW.rgb-cC.rgb));
subC[3][3] += (checking.x*checking.y*checking.z);
checking = vec3(1.0)-ceil(abs(cW.rgb-cSW.rgb));
subC[3][3] += (checking.x*checking.y*checking.z);
Upvotes: 1
Views: 322
Reputation: 419
I solved this by rewriting my shader without using if/else conditionals and without arrays and without loops. I only have one if statement, and no errors or warnings.
Upvotes: 1
Reputation: 473407
maximum temp register index exceeded
This error means exactly that: the compiler couldn't compile your shader because the number of temporary registers you needed was too great. This could be, in part, due to stupidity on the compiler's part, not reclaiming variables that won't be referenced again. Or it could be a problem with your shader.
I already see a fairly large one:
vec4 tColor = texture2D(texture, vUv);
All of the code before this line is entirely irrelevant. Why? Because not one of those variables is actually used to generate gl_FragColor
. And only the data used to generate that matters to the output. You basically spend a lot of time computing a value, only to then overwrite it with something very simple: tColor
or testColor
. Neither of which depend on the previous computation.
Take out all of the unneeded computations.
Also:
gradient-based operations must be moved out of flow control to prevent divergence. Performance may improve by using a non-gradient operation
This is also suggestive that you aren't showing everything. This warning would only appear if you were calling a texture
function in non-uniform control flow (ie: a conditional statement). I see no such non-uniform control flow in your code, yet there is the warning. That suggests that there is something more going on in your shader.
Upvotes: 0