I worked a little bit on my fragment shader to allow both texture rendering as well as color rendering. After I made the changes, all my textures were very pixelated (like an old 8-bit game) and I had to ramp up the precision for the texture coordinates to medium. This also gave me a performance hit. I just don’t understand why I suddenly had to change the precision in the first place.
Here is the “original” shader:
varying lowp vec2 TexCoordOut;
uniform sampler2D Texture;
uniform lowp float opacity;
void main(void) {
gl_FragColor = opacity * texture2D(Texture, TexCoordOut);
}
This is how the shader looks after the changes:
varying mediump vec2 TexCoordOut;
uniform sampler2D Texture;
uniform lowp vec4 color;
uniform lowp float opacity;
uniform int colorRender;
void main(void) {
if (colorRender == 1)
{
gl_FragColor = color;
} else {
gl_FragColor = opacity * texture2D(Texture, TexCoordOut);
}
}
You blame the performance loss on switching to mediump, but you’ve also added branching to the shader. Given that every fragment for a single draw call will always take the same path, you should just have two different shaders, each without branching.