make LUT shaders automatically set color depth

This commit is contained in:
hunterk 2022-08-30 22:21:39 -05:00
parent 768d42e71c
commit 380204890c
2 changed files with 17 additions and 27 deletions

View file

@ -6,11 +6,8 @@ layout(push_constant) uniform Push
vec4 OriginalSize; vec4 OriginalSize;
vec4 OutputSize; vec4 OutputSize;
uint FrameCount; uint FrameCount;
float LUT_Size;
} params; } params;
#pragma parameter LUT_Size "LUT Size" 16.0 1.0 64.0 1.0
layout(std140, set = 0, binding = 0) uniform UBO layout(std140, set = 0, binding = 0) uniform UBO
{ {
mat4 MVP; mat4 MVP;
@ -43,11 +40,12 @@ vec4 mixfix(vec4 a, vec4 b, float c)
void main() void main()
{ {
vec2 LUT_Size = textureSize(SamplerLUT, 0);
vec4 imgColor = texture(Source, vTexCoord.xy); vec4 imgColor = texture(Source, vTexCoord.xy);
float red = ( imgColor.r * (params.LUT_Size - 1.0) + 0.4999 ) / (params.LUT_Size * params.LUT_Size); float red = ( imgColor.r * (LUT_Size.y - 1.0) + 0.4999 ) / (LUT_Size.y * LUT_Size.y);
float green = ( imgColor.g * (params.LUT_Size - 1.0) + 0.4999 ) / params.LUT_Size; float green = ( imgColor.g * (LUT_Size.y - 1.0) + 0.4999 ) / LUT_Size.y;
float blue1 = (floor( imgColor.b * (params.LUT_Size - 1.0) ) / params.LUT_Size) + red; float blue1 = (floor( imgColor.b * (LUT_Size.y - 1.0) ) / LUT_Size.y) + red;
float blue2 = (ceil( imgColor.b * (params.LUT_Size - 1.0) ) / params.LUT_Size) + 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); float mixer = clamp(max((imgColor.b - blue1) / (blue2 - blue1), 0.0), 0.0, 32.0);
vec4 color1 = texture( SamplerLUT, vec2( blue1, green )); vec4 color1 = texture( SamplerLUT, vec2( blue1, green ));
vec4 color2 = texture( SamplerLUT, vec2( blue2, green )); vec4 color2 = texture( SamplerLUT, vec2( blue2, green ));

View file

@ -1,7 +1,6 @@
#version 450 #version 450
// A version of the LUT shader that loads 2 LUTs. // A version of the LUT shader that loads 2 LUTs.
// For use with Kurozumi's 64-bit colorspace LUTs.
layout(push_constant) uniform Push layout(push_constant) uniform Push
{ {
@ -12,12 +11,7 @@ layout(push_constant) uniform Push
float LUT_selector_param; float LUT_selector_param;
} params; } params;
#pragma parameter LUT_selector_param "Color Temp (1=D65, 2=D93)" 1.0 1.0 2.0 1.0 #pragma parameter LUT_selector_param "LUT Selector" 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
int LUT_selector = int(params.LUT_selector_param); int LUT_selector = int(params.LUT_selector_param);
layout(std140, set = 0, binding = 0) uniform UBO layout(std140, set = 0, binding = 0) uniform UBO
@ -53,26 +47,24 @@ vec4 mixfix(vec4 a, vec4 b, float c)
void main() 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 imgColor = texture(Source, vTexCoord.xy);
vec4 color1, color2 = vec4(0.,0.,0.,0.); vec4 color1, color2 = vec4(0.,0.,0.,0.);
float red, green, blue1, blue2, mixer = 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) 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 )); color1 = texture( SamplerLUT1, vec2( blue1, green ));
color2 = texture( SamplerLUT1, vec2( blue2, 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 )); color1 = texture( SamplerLUT2, vec2( blue1, green ));
color2 = texture( SamplerLUT2, vec2( blue2, green )); color2 = texture( SamplerLUT2, vec2( blue2, green ));
} }