The code below is run over the whole screen a la shadertoy.com, and explains itself in the comments:

Code: Select all

```
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec3 green = vec3(0., 1., 0.);
vec3 red = vec3(1., 0., 0.);
// a = 1.0, b = 2.0
float a = 1.;
float b = a + a;
// split the screen into 4 parts.
if (fragCoord.x < 1920./4.) {
// shows green, so b == 2.
if (b == 2.) {
fragColor.rgb = green;
} else {
fragColor.rgb = red;
}
} else if (fragCoord.x < 2.*1920./4.) {
// shows green, so mod(2., 2.) == 0
if (mod(2., 2.) == 0.) {
fragColor.rgb = green;
} else {
fragColor.rgb = red;
}
} else if (fragCoord.x < 3.*1920./4.) {
// shows red, so mod(b, 2.) != 0, even though b == 2.
if (mod(b, 2.) == 0.) {
fragColor.rgb = green;
} else {
fragColor.rgb = red;
}
} else {
// shows green, so mod(b, 2.) == 2
if (mod(b, 2.) == 2.) {
fragColor.rgb = green;
} else {
fragColor.rgb = red;
}
// so maybe this has to do with == being more about closeness
// than exact equality? I don't know.
}
}
```

It works as expected on shadertoy.com too. What's going on?