diff --git a/crt/common.inc b/crt/common.inc index cdb99d2..6417dbf 100644 --- a/crt/common.inc +++ b/crt/common.inc @@ -2,5 +2,7 @@ layout(std140, set = 0, binding = 1) uniform UBO { mat4 MVP; vec4 SourceSize; + float OUT_GAMMA; + float BOOST; } global; diff --git a/crt/linearize.slang b/crt/linearize.slang index 763412c..c1fb2a3 100644 --- a/crt/linearize.slang +++ b/crt/linearize.slang @@ -1,8 +1,10 @@ #version 450 +#include "parameters.inc" layout(std140, set = 0, binding = 0) uniform UBO { mat4 MVP; + float GAMMA; } global; #pragma stage vertex @@ -23,7 +25,7 @@ layout(set = 0, binding = 2) uniform sampler2D Source; vec3 gamma(vec3 v) { - return pow(v, vec3(2.2)); + return pow(v, vec3(global.GAMMA)); } void main() diff --git a/crt/parameters.inc b/crt/parameters.inc new file mode 100644 index 0000000..e55bbb0 --- /dev/null +++ b/crt/parameters.inc @@ -0,0 +1,3 @@ +#pragma parameter OUT_GAMMA "Monitor Output Gamma" 2.2 1.8 2.4 +#pragma parameter BOOST "Color Boost" 1.0 0.2 2.0 0.02 +#pragma parameter GAMMA "CRT gamma" 2.5 2.0 3.0 0.02 diff --git a/crt/scanline.slang b/crt/scanline.slang index 9427ea8..b0ac8f4 100644 --- a/crt/scanline.slang +++ b/crt/scanline.slang @@ -1,6 +1,7 @@ #version 450 #include "common.inc" +#include "parameters.inc" #pragma stage vertex layout(location = 0) in vec4 Position; @@ -20,7 +21,7 @@ layout(set = 0, binding = 2) uniform sampler2D Source; vec3 invgamma(vec3 v) { - return pow(v, vec3(1.0 / 2.2)); + return pow(clamp(v, vec3(0.0), vec3(1.0)), vec3(1.0 / global.OUT_GAMMA)); } float luma(vec3 col) @@ -49,5 +50,5 @@ void main() dist.y * l1 + dist.z * l2; - FragColor = vec4(invgamma(color), 1.0); + FragColor = vec4(invgamma(global.BOOST * color), 1.0); }