diff --git a/crt/shaders/slotmask.slang b/crt/shaders/slotmask.slang index c8a743b..df66402 100644 --- a/crt/shaders/slotmask.slang +++ b/crt/shaders/slotmask.slang @@ -16,7 +16,7 @@ layout(push_constant) uniform Push // Parameter lines go here: -#pragma parameter msk_scale "Mask Scale, to be equal to OSSC LINES" 4.0 4.0 5.0 1.0 +#pragma parameter msk_scale "Mask Scale, to be equal to OSSC LINES" 4.0 3.0 5.0 1.0 #define msk_scale params.msk_scale #pragma parameter MASK_INTENSITY "Mask Brightness" 0.2 0.0 1.0 0.05 @@ -65,6 +65,23 @@ vec3 mask(vec2 pos, vec3 col) float x,y; vec2 p = pos*global.OutputSize.xy; p = (p/size); + +if (msk_scale == 3.0) +{ + x = fract(p.x/6.0); + y = fract(p.y/3.0); + if (x < 0.5){ + if (x<1.0/6.0 && y > 1.0/3.0) msk.b = 1.0; + else if (x<2.0/6.0 && x>1.0/6.0 && y > 1.0/3.0 ) msk.g = 1.0; + else if (x<3.0/6.0 && x>2.0/6.0 && y > 1.0/3.0 ) msk.r = 1.0; + } + + else if (x > 0.4999){ + if (x<4.0/6.0 && y < 2.0/3.0 || x<4.0/6.0 && y >= 3.0/3.0 ) msk.b = 1.0; + else if (x<5.0/6.0 && x>4.0/6.0 && y < 2.0/3.0 || x<5.0/6.0 && x>4.0/6.0 && y >= 3.0/3.0) msk.g = 1.0; + else if (x<6.0/6.0 && x>5.0/6.0 && y < 2.0/3.0 || x<6.0/6.0 && x>5.0/6.0 && y >= 3.0/3.0) msk.r = 1.0; + } +} if (msk_scale == 4.0) @@ -72,15 +89,15 @@ if (msk_scale == 4.0) x = fract(p.x/6.0); y = fract(p.y/4.0); if (x < 0.5){ - if (x<1.0/6.0 && y > 1.0/4.0) msk.b = 1.0; - else if (x<2.0/6.0 && x>1.0/6.0 && y < 3.0/4.0 ) msk.g = 1.0; + if (x<1.0/6.0 && y > 1.0/4.0) msk.b = 1.0; + else if (x<2.0/6.0 && x>1.0/6.0 && y > 1.0/4.0 ) msk.g = 1.0; else if (x<3.0/6.0 && x>2.0/6.0 && y > 1.0/4.0 ) msk.r = 1.0; } else if (x > 0.4999){ - if (x<4.0/6.0 && y < 3.0/4.0) msk.b = 1.0; - else if (x<5.0/6.0 && x>4.0/6.0 && y > 1.0/4.0 ) msk.g = 1.0; - else if (x<6.0/6.0 && x>5.0/6.0 && y < 3.0/4.0 ) msk.r = 1.0; + if (x<4.0/6.0 && y < 2.0/4.0 || x<4.0/6.0 && y >= 3.0/4.0 ) msk.b = 1.0; + else if (x<5.0/6.0 && x>4.0/6.0 && y < 2.0/4.0 || x<5.0/6.0 && x>4.0/6.0 && y >= 3.0/4.0) msk.g = 1.0; + else if (x<6.0/6.0 && x>5.0/6.0 && y < 2.0/4.0 || x<6.0/6.0 && x>5.0/6.0 && y >= 3.0/4.0) msk.r = 1.0; } } @@ -89,14 +106,14 @@ if (msk_scale == 5.0) x = fract(p.x/6.0); y = fract(p.y/5.0); if (x < 0.5){ - if (x<1.0/6.0 && y > 1.0/5.0) msk.b = 1.0; - else if (x<2.0/6.0 && x>1.0/6.0 && y < 4.0/5.0 ) msk.g = 1.0; + if (x<1.0/6.0 && y > 1.0/5.0) msk.b = 1.0; + else if (x<2.0/6.0 && x>1.0/6.0 && y > 1.0/5.0 ) msk.g = 1.0; else if (x<3.0/6.0 && x>2.0/6.0 && y > 1.0/5.0 ) msk.r = 1.0; } else if (x > 0.4999){ - if (x<4.0/6.0 && y < 2.0/5.0 || x<4.0/6.0 && y >= 3.0/5.0) msk.b = 1.0; - else if (x<5.0/6.0 && x>4.0/6.0 && y < 3.0/5.0 || x<5.0/6.0 && x>4.0/6.0 && y >= 4.0/5.0 ) msk.g = 1.0; + if (x<4.0/6.0 && y < 2.0/5.0 || x<4.0/6.0 && y >= 3.0/5.0) msk.b = 1.0; + else if (x<5.0/6.0 && x>4.0/6.0 && y < 2.0/5.0 || x<5.0/6.0 && x>4.0/6.0 && y >= 3.0/5.0 ) msk.g = 1.0; else if (x<6.0/6.0 && x>5.0/6.0 && y < 2.0/5.0 || x<6.0/6.0 && x>5.0/6.0 && y >= 3.0/5.0 ) msk.r = 1.0; } } @@ -107,13 +124,8 @@ if (msk_scale == 5.0) } void main() -{ - vec2 OGL2Pos = vTexCoord*SourceSize.xy; - float cent = floor(OGL2Pos.y)+0.5; - float ycoord = cent*SourceSize.w; - ycoord = mix(vTexCoord.y, ycoord,0.7); - - vec3 col = texture(Source,vec2(vTexCoord.x,ycoord)).rgb; +{ + vec3 col = texture(Source,vTexCoord).rgb; float l = dot(col,vec3(0.22,0.70,0.08)); col = col*col; diff --git a/misc/shaders/simple_color_controls.slang b/misc/shaders/simple_color_controls.slang new file mode 100644 index 0000000..b5d06e9 --- /dev/null +++ b/misc/shaders/simple_color_controls.slang @@ -0,0 +1,153 @@ +#version 450 + + +layout(push_constant) uniform Push +{ + vec4 OutputSize; + vec4 OriginalSize; + vec4 SourceSize; + uint FrameCount; + float SAT,BLACK,TEMP,SEGA,BRIGHTNESS,postbr,contrast, + gamma_out_red,gamma_out_green,gamma_out_blue, + gamma_in, mono, R,G,B; +} params; + +#pragma parameter TEMP "Color Temperature in Kelvins" 9311.0 1031.0 12047.0 72.0 +#define TEMP params.TEMP +#pragma parameter SAT "Saturation" 1.0 0.0 2.0 0.01 +#define SAT params.SAT +#pragma parameter BRIGHTNESS "Brightness" 1.0 0.0 2.0 0.01 +#define BRIGHTNESS params.BRIGHTNESS +#pragma parameter contrast "Contrast" 1.0 0.00 2.00 0.01 +#define contrast params.contrast +#pragma parameter BLACK "Black Level" 0.0 -0.20 0.20 0.01 +#define BLACK params.BLACK +#pragma parameter SEGA "SEGA Lum Fix" 0.0 0.0 1.0 1.0 +#define SEGA params.SEGA +#pragma parameter postbr "Post Brightness" 1.0 0.0 2.5 0.01 +#define postbr params.postbr +#pragma parameter gamma_in "Gamma In" 2.4 1.0 4.0 0.05 +#define gamma_in params.gamma_in +#pragma parameter gamma_out_red "Gamma out Red" 2.2 1.0 4.0 0.05 +#define gamma_out_red params.gamma_out_red +#pragma parameter gamma_out_green "Gamma out Green" 2.2 1.0 4.0 0.05 +#define gamma_out_green params.gamma_out_green +#pragma parameter gamma_out_blue "Gamma out Blue" 2.2 1.0 4.0 0.05 +#define gamma_out_blue params.gamma_out_blue +#pragma parameter mono "Mono Display On/Off" 0.0 0.0 1.0 1.0 +#define mono params.mono +#pragma parameter R "Mono Red/Channel" 1.0 0.0 2.0 0.01 +#define R params.R +#pragma parameter G "Mono Green/Channel" 1.0 0.0 2.0 0.01 +#define G params.G +#pragma parameter B "Mono Blue/Channel" 1.0 0.0 2.0 0.01 +#define B params.B + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; +} global; + +#pragma stage vertex +layout(location = 0) in vec4 Position; +layout(location = 1) in vec2 TexCoord; +layout(location = 0) out vec2 vTexCoord; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + +float saturate(float v) + { + return clamp(v, 0.0, 1.0); + } + +vec3 ColorTemp(float temperatureInKelvins) +{ + vec3 retColor; + temperatureInKelvins = clamp(temperatureInKelvins, 1000.0, 40000.0) / 100.0; + + if (temperatureInKelvins <= 66.0) + { + retColor.r = 1.0; + retColor.g = saturate(0.39008157876901960784 * log(temperatureInKelvins) - 0.63184144378862745098); + } + else + { + float t = temperatureInKelvins - 60.0; + retColor.r = saturate(1.29293618606274509804 * pow(t, -0.1332047592)); + retColor.g = saturate(1.12989086089529411765 * pow(t, -0.0755148492)); + } + + if (temperatureInKelvins >= 66.0) + retColor.b = 1.0; + else if(temperatureInKelvins <= 19.0) + retColor.b = 0.0; + else + retColor.b = saturate(0.54320678911019607843 * log(temperatureInKelvins - 10.0) - 1.19625408914); + + return retColor; +} + +mat4 contrastMatrix(float contr) +{ + float t = (1.0 - contr) / 2.0; + + return mat4(contr, 0, 0, 0, + 0, contr, 0, 0, + 0, 0, contr, 0, + t, t, t, 1); +} + + +vec3 toGrayscale(vec3 color) +{ + float average = (color.r + color.g + color.b) / 3.0; + return vec3(average); +} + +vec3 colorize(vec3 grayscale, vec3 color) +{ + return (grayscale * color); +} + + + +void main() +{ + vec3 col = texture(Source,vTexCoord).rgb; + col *= BRIGHTNESS; + col = (contrastMatrix(contrast) * vec4(col,1.0)).rgb; +//color temperature + col *= ColorTemp(TEMP); + +//saturation + float l = dot(col, vec3(0.3,0.6,0.1)); + col = mix(vec3(l), col, SAT); + col = pow(col, vec3(gamma_in)); +//black level + + if (SEGA == 1.0) col *= 1.0625; + col *= mix(1.0,postbr,l); + col = pow(col, vec3(1.0/gamma_out_red,1.0,1.0)); + col = pow(col, vec3(1.0,1.0/gamma_out_green,1.0)); + col = pow(col, vec3(1.0,1.0,1.0/gamma_out_blue)); + col -= vec3(BLACK); + col*= vec3(1.0)/vec3(1.0-BLACK); + + if (mono == 1.0) + { + vec3 col1 = toGrayscale (col); + vec3 c = vec3(R, G, B); + col = colorize (col1, c); + } + + FragColor = vec4(col,1.0); +} \ No newline at end of file diff --git a/misc/simple_color_controls.slangp b/misc/simple_color_controls.slangp new file mode 100644 index 0000000..93907d5 --- /dev/null +++ b/misc/simple_color_controls.slangp @@ -0,0 +1,4 @@ +shaders = 1 + +shader0 = shaders/simple_color_controls.slang +scale_type0 = source diff --git a/scanlines/ossc_slot.slangp b/scanlines/ossc_slot.slangp index 612661f..9aa8788 100644 --- a/scanlines/ossc_slot.slangp +++ b/scanlines/ossc_slot.slangp @@ -1,23 +1,53 @@ -shaders = "3" +shaders = "5" feedback_pass = "0" -shader0 = "../misc/shaders/image-adjustment.slang" -filter_linear2 = "false" +shader0 = "../misc/shaders/simple_color_controls.slang" +wrap_mode0 = "clamp_to_border" +mipmap_input0 = "false" +alias0 = "" +float_framebuffer0 = "false" +srgb_framebuffer0 = "false" scale_type_x0 = "source" scale_x0 = "1.000000" scale_type_y0 = "source" scale_y0 = "1.000000" -shader1 = "../scanlines/shaders/ossc.slang" -filter_linear2 = "false" +shader1 = "../windowed/shaders/lanczos3-x.slang" +filter_linear1 = "false" +wrap_mode1 = "clamp_to_edge" +mipmap_input1 = "false" +alias1 = "" +float_framebuffer1 = "false" +srgb_framebuffer1 = "false" scale_type_x1 = "viewport" scale_x1 = "1.000000" -scale_type_y1 = "viewport" +scale_type_y1 = "source" scale_y1 = "1.000000" -shader2 = "../crt/shaders/slotmask.slang" -filter_linear2 = "true" -ia_saturation = "1.300000" -ia_black_level = "0.060000" -ia_bright_boost = "0.100000" -L1 = "0.500000" -L4 = "0.500000" -L5 = "0.600000" -HYBRID = "0.250000" +shader2 = "../windowed/shaders/lanczos3-y.slang" +filter_linear2 = "false" +wrap_mode2 = "clamp_to_edge" +mipmap_input2 = "false" +alias2 = "" +float_framebuffer2 = "false" +srgb_framebuffer2 = "false" +shader3 = "../scanlines/shaders/ossc.slang" +wrap_mode3 = "clamp_to_border" +mipmap_input3 = "false" +alias3 = "" +float_framebuffer3 = "false" +srgb_framebuffer3 = "false" +scale_type_x3 = "viewport" +scale_x3 = "1.000000" +scale_type_y3 = "viewport" +scale_y3 = "1.000000" +shader4 = "../crt/shaders/slotmask.slang" +wrap_mode4 = "clamp_to_border" +mipmap_input4 = "false" +alias4 = "" +float_framebuffer4 = "false" +srgb_framebuffer4 = "false" +SAT = "1.10000" +BRIGHTNESS = "1.050000" +contrast = "1.040000" +BLACK = "0.010000" +postbr = "1.150000" +gamma_out_red = "2.400000" +gamma_out_blue = "2.500000"