diff --git a/misc/clamphack.inc b/misc/clamphack.inc new file mode 100644 index 0000000..a20c1a3 --- /dev/null +++ b/misc/clamphack.inc @@ -0,0 +1,7 @@ +//hacky clamp fix +vec2 bordertest = (vTexCoord); +vec3 res = texture(Source, vTexCoord).rgb; +if ( bordertest.x > 0.0001 && bordertest.x < 0.9999 && bordertest.y > 0.0001 && bordertest.y < 0.9999) +res.rgb = res.rgb; +else +res.rgb = vec3(0.0); \ No newline at end of file diff --git a/misc/image-adjustment.slang b/misc/image-adjustment.slang new file mode 100644 index 0000000..33f481e --- /dev/null +++ b/misc/image-adjustment.slang @@ -0,0 +1,79 @@ +#version 450 + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; + vec4 OutputSize; + vec4 OriginalSize; + vec4 SourceSize; +} global; + +#define overscan_percent_x 0.0 // crop width of image by X%; default is 0.0 +#define overscan_percent_y 0.0 // crop height of image by X%; default is 0.0 +#define saturation 1.0 // color saturation; default 1.0 +#define monitor_gamma 2.2 // gamma setting of your current display; LCD monitors typically have a gamma of 2.2 +#define target_gamma 2.4 // the gamma you want the image to have; CRT TVs typically have a gamma of 2.4 +#define contrast 1.0 // image contrast; default 1.0 +#define luminance 1.0 // image luminance; default 1.0 +#define bright_boost 0.0 // adds to the total brightness. Negative values decrease it; Use values between 1.0 (totally white) and -1.0 (totally black); default is 0.0 +#define R 0.5//1.0 +#define G 1.0 +#define B 1.0 +#define ZOOM 1.0 +#define XPOS 0.0 +#define YPOS 0.0 +#define V_OSMASK 0.0 +#define H_OSMASK 0.0 + +// Image Adjustment +// Author: hunterk +// License: Public domain + +#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; + vec2 shift = 0.5 * global.SourceSize.zw / global.SourceSize.xy; + vec2 overscan_coord = ((TexCoord - shift) / ZOOM) * (1.0 - vec2(overscan_percent_x / 100.0, overscan_percent_y / 100.0)) + shift; + vTexCoord = overscan_coord + vec2(XPOS, YPOS); +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + +vec3 grayscale(vec3 col) +{ + // ATSC grayscale standard + return vec3(dot(col, vec3(0.2126, 0.7152, 0.0722))); +} + +void main() +{ +vec2 fragcoord = vTexCoord.xy * (global.SourceSize.xy / global.SourceSize.zw); + vec3 res = texture(Source, vTexCoord).rgb; // sample the texture + vec3 gamma = vec3(monitor_gamma / target_gamma); // setup ratio of display's gamma vs desired gamma + vec3 AvgLumin = vec3(0.5, 0.5, 0.5); + vec3 intensity = grayscale(res); // find luminance + vec3 satColor = mix(intensity, res, saturation); // apply saturation + vec3 conColor = mix(AvgLumin, satColor, contrast); // apply contrast + conColor = pow(conColor, 1.0 / vec3(gamma)); // Apply gamma correction + conColor = clamp(conColor * luminance, 0.0, 1.0); // apply luminance + conColor += vec3(bright_boost); // apply brightboost + conColor *= vec3(R, G, B); +if (fragcoord.y > V_OSMASK && fragcoord.y < (1.0 - V_OSMASK)) +conColor = conColor; +else +conColor = vec3(0.0); + +if (fragcoord.x > H_OSMASK && fragcoord.x < (1.0 - H_OSMASK)) +conColor = conColor; +else +conColor = vec3(0.0); + FragColor = vec4(fragcoord.x);//vec4(conColor, 1.0); +} \ No newline at end of file diff --git a/misc/interlacing.slang b/misc/interlacing.slang new file mode 100644 index 0000000..bd2efbd --- /dev/null +++ b/misc/interlacing.slang @@ -0,0 +1,56 @@ +#version 450 + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; + vec4 OutputSize; + vec4 OriginalSize; + vec4 SourceSize; + uint FrameCount; +} global; + +#define percent 0.0 +#define enable_480i 1.0 +#define top_field_first 0.0 + +/* + Interlacing + Author: hunterk + License: Public domain + + Note: This shader is designed to work with the typical interlaced output from an emulator, which displays both even and odd fields twice. + This shader will un-weave the image, resulting in a standard, alternating-field interlacing. +*/ + +#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; + +void main() +{ + vec4 res = texture(Source, vTexCoord).rgba; + float y = 0.0; + + // assume anything with a vertical resolution greater than 400 lines is interlaced + if (global.SourceSize.w > 400.0) + {y = global.SourceSize.y * vTexCoord.y + (global.FrameCount * enable_480i) + top_field_first;} + else + {y = 2.0 * global.SourceSize.y * vTexCoord.y + top_field_first;} + + if (mod(y, 2.0) > 0.99999) + {FragColor = res;} + else + {FragColor = vec4(percent) * res;} +} \ No newline at end of file diff --git a/stock.slang b/stock.slang new file mode 100644 index 0000000..3814272 --- /dev/null +++ b/stock.slang @@ -0,0 +1,30 @@ +#version 450 + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; + vec4 OutputSize; + vec4 OriginalSize; + vec4 SourceSize; +} 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; + +void main() +{ + FragColor = vec4(texture(Source, vTexCoord).rgb, 1.0); +} \ No newline at end of file