Created
March 19, 2019 09:21
-
-
Save markknol/141244cd5d29aedd8a657f49f392f80b to your computer and use it in GitHub Desktop.
LUT shader (uses 512x512 textures)
This file contains 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
class LutShader extends h3d.shader.ScreenShader { | |
static var SRC = { | |
@param var texture : Sampler2D; | |
@param var lookup1 : Sampler2D; | |
@param var lookup2 : Sampler2D; | |
@param var mixAmount : Float = 0.0; | |
@param var totalMixAmount : Float = 1.0; | |
function calcLookup(color:Vec4, lookupTexture:Sampler2D):Vec4 { | |
var blueColor = color.b * 63.0; | |
var quad1 = vec2(0,0); | |
quad1.y = floor(floor(blueColor) / 8.0); | |
quad1.x = floor(blueColor) - (quad1.y * 8.0); | |
var quad2 = vec2(0,0); | |
quad2.y = floor(ceil(blueColor) / 8.0); | |
quad2.x = ceil(blueColor) - (quad2.y * 8.0); | |
var texPos1 = vec2( | |
(quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.r), | |
(quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.g) | |
); | |
var texPos2 = vec2( | |
(quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.r), | |
(quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.g) | |
); | |
var newColor1 = lookupTexture.get(texPos1); | |
var newColor2 = lookupTexture.get(texPos2); | |
return mix(newColor1, newColor2, fract(blueColor)); | |
} | |
function fragment() { | |
var currentColor = texture.get(calculatedUV); | |
var color1 = calcLookup(currentColor, lookup1); | |
var color2 = calcLookup(currentColor, lookup2); | |
var lutColor = mix(color1, color2, mixAmount); | |
output.color = mix(currentColor, lutColor, totalMixAmount); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment