From 380204890cd62fb5144ce45c32ec4847991a86d7 Mon Sep 17 00:00:00 2001 From: hunterk Date: Tue, 30 Aug 2022 22:21:39 -0500 Subject: [PATCH] make LUT shaders automatically set color depth --- reshade/shaders/LUT/LUT.slang | 12 +++++------ reshade/shaders/LUT/multiLUT.slang | 32 +++++++++++------------------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/reshade/shaders/LUT/LUT.slang b/reshade/shaders/LUT/LUT.slang index 708224a..38b0403 100755 --- a/reshade/shaders/LUT/LUT.slang +++ b/reshade/shaders/LUT/LUT.slang @@ -6,11 +6,8 @@ layout(push_constant) uniform Push vec4 OriginalSize; vec4 OutputSize; uint FrameCount; - float LUT_Size; } params; -#pragma parameter LUT_Size "LUT Size" 16.0 1.0 64.0 1.0 - layout(std140, set = 0, binding = 0) uniform UBO { mat4 MVP; @@ -43,11 +40,12 @@ vec4 mixfix(vec4 a, vec4 b, float c) void main() { + vec2 LUT_Size = textureSize(SamplerLUT, 0); vec4 imgColor = texture(Source, vTexCoord.xy); - float red = ( imgColor.r * (params.LUT_Size - 1.0) + 0.4999 ) / (params.LUT_Size * params.LUT_Size); - float green = ( imgColor.g * (params.LUT_Size - 1.0) + 0.4999 ) / params.LUT_Size; - float blue1 = (floor( imgColor.b * (params.LUT_Size - 1.0) ) / params.LUT_Size) + red; - float blue2 = (ceil( imgColor.b * (params.LUT_Size - 1.0) ) / params.LUT_Size) + red; + float red = ( imgColor.r * (LUT_Size.y - 1.0) + 0.4999 ) / (LUT_Size.y * LUT_Size.y); + float green = ( imgColor.g * (LUT_Size.y - 1.0) + 0.4999 ) / LUT_Size.y; + float blue1 = (floor( imgColor.b * (LUT_Size.y - 1.0) ) / LUT_Size.y) + red; + float blue2 = (ceil( imgColor.b * (LUT_Size.y - 1.0) ) / LUT_Size.y) + red; float mixer = clamp(max((imgColor.b - blue1) / (blue2 - blue1), 0.0), 0.0, 32.0); vec4 color1 = texture( SamplerLUT, vec2( blue1, green )); vec4 color2 = texture( SamplerLUT, vec2( blue2, green )); diff --git a/reshade/shaders/LUT/multiLUT.slang b/reshade/shaders/LUT/multiLUT.slang index 44ef9de..462f64f 100755 --- a/reshade/shaders/LUT/multiLUT.slang +++ b/reshade/shaders/LUT/multiLUT.slang @@ -1,7 +1,6 @@ #version 450 // A version of the LUT shader that loads 2 LUTs. -// For use with Kurozumi's 64-bit colorspace LUTs. layout(push_constant) uniform Push { @@ -12,12 +11,7 @@ layout(push_constant) uniform Push float LUT_selector_param; } params; -#pragma parameter LUT_selector_param "Color Temp (1=D65, 2=D93)" 1.0 1.0 2.0 1.0 -//#pragma parameter LUT_Size1 "LUT Size 1" 16.0 1.0 64.0 1.0 -//#pragma parameter LUT_Size2 "LUT Size 2" 16.0 1.0 64.0 1.0 -const float LUT_Size1 = 64.0; -const float LUT_Size2 = 64.0; // hardcode these for Kurozumi's LUTs - +#pragma parameter LUT_selector_param "LUT Selector" 1.0 1.0 2.0 1.0 int LUT_selector = int(params.LUT_selector_param); layout(std140, set = 0, binding = 0) uniform UBO @@ -53,26 +47,24 @@ vec4 mixfix(vec4 a, vec4 b, float c) void main() { + float LUT_Size = mix(textureSize(SamplerLUT1, 0).y, textureSize(SamplerLUT2, 0).y, params.LUT_selector_param - 1.0); vec4 imgColor = texture(Source, vTexCoord.xy); vec4 color1, color2 = vec4(0.,0.,0.,0.); float red, green, blue1, blue2, mixer = 0.0; + + red = ( imgColor.r * (LUT_Size - 1.0) + 0.4999 ) / (LUT_Size * LUT_Size); + green = ( imgColor.g * (LUT_Size - 1.0) + 0.4999 ) / LUT_Size; + blue1 = (floor( imgColor.b * (LUT_Size - 1.0) ) / LUT_Size) + red; + blue2 = (ceil( imgColor.b * (LUT_Size - 1.0) ) / LUT_Size) + red; + mixer = clamp(max((imgColor.b - blue1) / (blue2 - blue1), 0.0), 0.0, 32.0); + if(LUT_selector == 1) { - red = ( imgColor.r * (LUT_Size1 - 1.0) + 0.4999 ) / (LUT_Size1 * LUT_Size1); - green = ( imgColor.g * (LUT_Size1 - 1.0) + 0.4999 ) / LUT_Size1; - blue1 = (floor( imgColor.b * (LUT_Size1 - 1.0) ) / LUT_Size1) + red; - blue2 = (ceil( imgColor.b * (LUT_Size1 - 1.0) ) / LUT_Size1) + red; - mixer = clamp(max((imgColor.b - blue1) / (blue2 - blue1), 0.0), 0.0, 32.0); - color1 = texture( SamplerLUT1, vec2( blue1, green )); - color2 = texture( SamplerLUT1, vec2( blue2, green )); + color1 = texture( SamplerLUT1, vec2( blue1, green )); + color2 = texture( SamplerLUT1, vec2( blue2, green )); } - if(LUT_selector == 2) + else { - red = ( imgColor.r * (LUT_Size2 - 1.0) + 0.4999 ) / (LUT_Size2 * LUT_Size2); - green = ( imgColor.g * (LUT_Size2 - 1.0) + 0.4999 ) / LUT_Size2; - blue1 = (floor( imgColor.b * (LUT_Size2 - 1.0) ) / LUT_Size2) + red; - blue2 = (ceil( imgColor.b * (LUT_Size2 - 1.0) ) / LUT_Size2) + red; - mixer = clamp(max((imgColor.b - blue1) / (blue2 - blue1), 0.0), 0.0, 32.0); color1 = texture( SamplerLUT2, vec2( blue1, green )); color2 = texture( SamplerLUT2, vec2( blue2, green )); }