BGE Color Correction

Well, the last thread I found on this was closed over a year ago without any real answer to the question:

Is there a way to create color correction in GLSL?

I made this small “framework”://code by flemming stäbler, 2013
//use if you like, but don’t distribute this as your own!
//no warranty, tested in blender 2.65 on an amd r6570.

uniform sampler2D bgl_RenderedTexture;
void main(void)
{
vec4 texcolor = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st);

float red = texcolor.r;
float green = texcolor.g;
float blue = texcolor.b;

float redl = red * max((-2 * red) +1, 0); //low band
float greenl = green * max((-2 * green) +1, 0);
float bluel = blue * max ((-2 * blue) +1 , 0);

float redm = red * min(2 * red, (-2 * red) + 2); //mid band
float greenm = green * min(2 * green, (-2 * green) + 2);
float bluem = blue * min(2 * blue, (-2 * blue) + 2);

float redh = red * max((2 * red) - 1, 0); //hi band
float greenh = green * max((2 * green) - 1, 0);
float blueh = blue * max((2 * blue) - 1, 0);

redl = redl * 0.44;
redm = redm * 0.80;
redh = redh * 1.40;

greenl = greenl * 0.48;
greenm = greenm * 0.55;
greenh = greenh * 1.64;

bluel = bluel * 0.65;
bluem = bluem * 0.50;
blueh = blueh * 1.22;

float redf = redl + redm + redh; //summing it up
float greenf = greenl + greenm + greenh;
float bluef = bluel + bluem + blueh;

gl_FragColor = vec4(redf, bluef, greenf, texcolor.a);
}

The code brings down the framerate by around 5-10% for me.

EDIT:



This is really useful, thanks man :slight_smile: