// Use the same values in all affected GLSL files for best results. const lowp float a7contrast = 2.0; // modify to adjust contrast (default: 1.0, lower: <1.0, higher: >1.0) const lowp float a7brightness = 1.0; // modify to adjust brightness (default: 0.0, darker: <0.0, brighter: >0.0) const lowp float a7gamma = 2.0; // modify to adjust gamma correction (default: 1.0, darker: <1.0, brighter: >1.0) vec3 a7ContrastFilter( vec3 color ) { if (a7contrast != 1.0) color = ( ( color - 0.5 ) * max( a7contrast, 0.0 ) ) + 0.5; return color; } vec3 a7BrightnessFilter( vec3 color ) { if (a7brightness != 0.0) color += a7brightness; return color; } vec3 a7GammaFilter( vec3 color ) { if (a7gamma != 1.0) color = pow( color, vec3( 1.0 / a7gamma ) ); return color; } vec4 a7ApplyFilters( vec4 color ) { // applying contrast color.rgb = a7ContrastFilter(color.rgb); // applying brightness color.rgb = a7BrightnessFilter(color.rgb); // applying gamma color.rgb = a7GammaFilter(color.rgb); // finalizing pixel data return vec4( color.rgb, color.a ); } uniform lowp sampler2D uTex; uniform highp vec2 uTcScale; uniform highp vec4 uColorTone; varying highp vec2 vTc; varying highp vec2 vRef; varying lowp vec4 vColor; bool isBorderColor(vec4 testColor) { if ((testColor.x == 0.0) && (testColor.y == 0.0) && (testColor.z == 0.0)) { return true; } return false; } void main() { vec2 texCoordUnbiased = vTc / uTcScale; vec2 refCoordUnbiased = vRef / uTcScale; float fu = fract(texCoordUnbiased.x); float fv = fract(texCoordUnbiased.y); vec2 texCoordTileLoc = mod(texCoordUnbiased - refCoordUnbiased, 64.0); int texCoordTileLocIntx = int(floor(texCoordTileLoc.x)); int texCoordTileLocInty = int(floor(texCoordTileLoc.y)); vec4 texColor0 = texture2D(uTex, vTc); vec4 texColor1 = texture2D(uTex, vTc + vec2(uTcScale.x, 0)); vec4 texColor2 = texture2D(uTex, vTc + vec2(0, uTcScale.y)); vec4 texColor3 = texture2D(uTex, vTc + vec2(uTcScale.x, uTcScale.y)); bool border0 = isBorderColor(texColor0); bool border1 = isBorderColor(texColor1); bool border2 = isBorderColor(texColor2); bool border3 = isBorderColor(texColor3); vec4 texColor = vec4(0,0,0,1); if (((texCoordTileLocIntx == 0) || (texCoordTileLocIntx >= 63) || (texCoordTileLocInty == 0) || (texCoordTileLocInty >= 63)) && (border0 || border1 || border2 || border3) ) { texColor = texColor0; } else { vec4 texColorTop = vec4(0,0,0,1); vec4 texColorBottom = vec4(0,0,0,1); if (border1) { texColor1 = texColor0; } if (border2) { texColor2 = texColor0; } if (border3) { texColor3 = texColor0; } texColorTop = mix(texColor0, texColor1, fu); texColorBottom = mix(texColor2, texColor3, fu); texColor = mix(texColorTop, texColorBottom, fv); } texColor = texColor * vColor; float grey = dot(texColor.rgb, vec3(0.299,0.587,0.114)); vec3 tone = grey * uColorTone.rgb; vec4 a7FragColor = vec4(mix(texColor.rgb, tone, uColorTone.a), texColor.a); gl_FragColor = a7ApplyFilters( a7FragColor ); }