Skip to content

Instantly share code, notes, and snippets.

@bazhenovc
Created July 27, 2014 20:48
Show Gist options
  • Save bazhenovc/8b3b69b1a39f3d758c1d to your computer and use it in GitHub Desktop.
Save bazhenovc/8b3b69b1a39f3d758c1d to your computer and use it in GitHub Desktop.
vec4 ApplyColorGrading(vec4 color, in sampler2D ramp)
{
// 3d texture unwrapped to 256x16
vec2 offset = vec2(0.5f / 256.0f, 0.5f / 16.0f);
float scale = 15.0f / 16.0f;
// even and fractional parts of blue component
float blueInt = floor(color.b * 15.0) / 16.0f;
float blueFract = color.b * 15.0f - blueInt * 16.0f;
// UV
vec2 uv = vec2(
blueInt + color.r * scale / 16.0f,
color.g * scale
);
// uv offsets
vec2 duv0 = vec2(0, 0);
vec2 duv1 = vec2(1.0 / 16.0, 0.0);
// LUT samples
vec4 lut0 = texture(ramp, offset + uv + duv0);
vec4 lut1 = texture(ramp, offset + uv + duv1);
return mix(lut0, lut1, blueFract);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment