Oh the lag! (Need help with fragment shader)

I’ve been working on this project (can’t spoil anything yet, sorry) and I’ve been having this pretty annoying problem. While editing the shader, the fragment tab always stays red like there is an error. The debug stuff doesn’t tell me anything and I did a few sweeps of the code and found nothing wrong. I think maybe an outside eye might find it or at least tell me why codea is doing this. The shader still works but causes an unplayable amount of frame variance (drops from 55 to 30 randomly). The red tab also makes it so that I can’t use the bindings tab.

Here is the fragment shader:


The vertex shader is left default

After you copy it over, the red tab might not show up right away. If you put a space
anywhere, it should show up

@1980geeksquad - The red may be because you define texSize but don’t use it

You have one small bug I can see, at line 71 you set alpha to 255 instead of 1. OpenGL does cap all colour values at 1 so maybe this doesn’t matter, and it wouldn’t affect speed.

I would calculate the constant values such as 100/255, and the vec3 in line 79, outside main, and set them to variables, to avoid the need for them to be continually recalculated.

If the shader works but is unpredictably choppy, this suggests that one part of it is very slow, and I would usually isolate it by simplifying each part one by one and seeing what makes a difference.

Actually, the red is because of the error I pointed out above. I found it by deleting parts of the shader until the red disappeared. The same approach may isolate the speed problem.

Replacing those calculations helps a lot. As for isolating code, it looks like from lines 72 to 78 was causing the problem.

if (col.rgb == vec3(num3,1,0))
col = vec4(0,0,1,1);

I’m off to investigate. :-B I have a feeling that it has something to do with the else (it might be checking it way too often or something)

Thank you @Ignatz :-bd