Simple color correction shader

edited February 2020 in General discussions

I dug in my old computer and found an old project I had. I had made a basic color correction shader that worked well. I wanted to share it years ago I had already given up on the game project and I couldn't find the latest source code. It not's the latest version I made.

So here's the shader code, it may or may not work as is in a game but it can be useful anyways. Basically it's like the color balance filter in Photoshop, Krita, the Gimp... You put more or less red, green, blue on the dark or light parts of the image. In image editing software the brightness is divided in 3, dark, mid and light, while in my shader I divided it in 2.

A basic setting that works well with this kind of shader is to put more blue in the dark parts and more orange in the light parts. You have to change correcdark and correclight parameters for that, they represent colors.

The final shader had a transition between 2 color corrections but I couldn't find the source code on my computer. The goal was for the color correction to change when the player moved to different parts of the level.

It works by putting the shader on all objects. The energy vector is to even the brightness or each color.
Some things are commented out, I don't remember why but if the shader doesn't work as is try to uncomment things.

In the scene
[Character@ColorGrading]

at the end of the scene
[ColorGrading]
ShaderList = ColorGradingShader

[ColorGradingShader]
Code = "
#define energy vec3(0.7, 0.41, 0.89)
#define correcdark vec3(0.0, 0.0, 1.0)
#define correclight vec3(1.0, 0.0, 0.0)

void main()
{
    gl_FragColor = texture2D(Texture,gl_TexCoord[0]);
    gl_FragColor.rgb += mix( correcdark * energy, correclight * energy,  dot(vec3(0.3, 0.59, 0.11), texture2D(Texture,gl_TexCoord[0]).rgb));
}
"
ParamList = Texture ; # correcdark # correclight
;correcdark = (0.0, 0.0, 1.0)
;correclight = (1.0, 0.0, 0.0)

Comments

Sign In or Register to comment.