Created
July 27, 2014 20:48
-
-
Save bazhenovc/8b3b69b1a39f3d758c1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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