mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-23 00:01:31 +11:00
commit
e518f8fae0
|
@ -3,9 +3,9 @@
|
|||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
vec4 OutputSize; /* .xy is Cg equivalent of output_size */
|
||||
vec4 OutputSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 SourceSize; /* .xy is Cg equivalent of both texture_size and video_size */
|
||||
vec4 SourceSize;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
|
@ -16,7 +16,7 @@ layout(location = 0) out vec2 vTexCoord;
|
|||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
vTexCoord = TexCoord;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -28,29 +28,28 @@ void main()
|
|||
Recommended Settings:
|
||||
|
||||
Video
|
||||
- Aspect Ratio: 4:3
|
||||
- Aspect Ratio: 4:3
|
||||
- Integer Scale: Off
|
||||
|
||||
Shader
|
||||
- Filter: Nearest
|
||||
- Scale: Don't Care
|
||||
- Scale: Don't Care
|
||||
|
||||
Example RGB Mask Parameter Settings:
|
||||
|
||||
Aperture Grille (Default)
|
||||
- Dot Width: 1
|
||||
- Dot Width: 1
|
||||
- Dot Height: 1
|
||||
- Stagger: 0
|
||||
- Stagger: 0
|
||||
|
||||
Lottes' Shadow Mask
|
||||
- Dot Width: 2
|
||||
- Dot Width: 2
|
||||
- Dot Height: 1
|
||||
- Stagger: 3
|
||||
- Stagger: 3
|
||||
*/
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 1) in vec2 FragCoord;
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
|
@ -80,8 +79,6 @@ layout(set = 0, binding = 2) uniform sampler2D Source;
|
|||
// Set to 0 to use linear filter and gain speed
|
||||
#define ENABLE_LANCZOS 1
|
||||
|
||||
|
||||
|
||||
vec4 dilate(vec4 col)
|
||||
{
|
||||
vec4 x = mix(vec4(1.0), col, DILATION);
|
||||
|
@ -104,14 +101,14 @@ float curve_distance(float x, float sharp)
|
|||
return mix(x, curve, sharp);
|
||||
}
|
||||
|
||||
mat4x4 get_color_matrix(sampler2D tex, vec2 co, vec2 dx)
|
||||
mat4x4 get_color_matrix(vec2 co, vec2 dx)
|
||||
{
|
||||
return mat4x4(TEX2D(co - dx), TEX2D(co), TEX2D(co + dx), TEX2D(co + 2.0 * dx));
|
||||
}
|
||||
|
||||
vec3 filter_lanczos(vec4 coeffs, mat4x4 color_matrix)
|
||||
{
|
||||
vec4 col = coeffs * color_matrix;
|
||||
vec4 col = coeffs * color_matrix;
|
||||
vec4 sample_min = min(color_matrix[1], color_matrix[2]);
|
||||
vec4 sample_max = max(color_matrix[1], color_matrix[2]);
|
||||
|
||||
|
@ -123,10 +120,10 @@ vec3 filter_lanczos(vec4 coeffs, mat4x4 color_matrix)
|
|||
/* main_fragment */
|
||||
void main()
|
||||
{
|
||||
vec2 dx = vec2(1.0 / global.SourceSize.x, 0.0);
|
||||
vec2 dy = vec2(0.0, 1.0 / global.SourceSize.y);
|
||||
vec2 dx = vec2(global.SourceSize.z, 0.0);
|
||||
vec2 dy = vec2(0.0, global.SourceSize.w);
|
||||
vec2 pix_co = vTexCoord * global.SourceSize.xy - vec2(0.5, 0.5);
|
||||
vec2 tex_co = (floor(pix_co) + vec2(0.5, 0.5)) / global.SourceSize.xy;
|
||||
vec2 tex_co = (floor(pix_co) + vec2(0.5, 0.5)) * global.SourceSize.zw;
|
||||
vec2 dist = fract(pix_co);
|
||||
float curve_x;
|
||||
vec3 col, col2;
|
||||
|
@ -137,11 +134,11 @@ void main()
|
|||
vec4 coeffs = PI * vec4(1.0 + curve_x, curve_x, 1.0 - curve_x, 2.0 - curve_x);
|
||||
|
||||
coeffs = FIX(coeffs);
|
||||
coeffs = 2.0 * sin(coeffs) * sin(coeffs / 2.0) / (coeffs * coeffs);
|
||||
coeffs = 2.0 * sin(coeffs) * sin(coeffs * 0.5) / (coeffs * coeffs);
|
||||
coeffs /= dot(coeffs, vec4(1.0));
|
||||
|
||||
col = filter_lanczos(coeffs, get_color_matrix(Source, tex_co, dx));
|
||||
col2 = filter_lanczos(coeffs, get_color_matrix(Source, tex_co + dy, dx));
|
||||
col = filter_lanczos(coeffs, get_color_matrix(tex_co, dx));
|
||||
col2 = filter_lanczos(coeffs, get_color_matrix(tex_co + dy, dx));
|
||||
#else
|
||||
curve_x = curve_distance(dist.x, SHARPNESS_H);
|
||||
|
||||
|
@ -153,21 +150,22 @@ void main()
|
|||
col = pow(col, vec3(GAMMA_INPUT / (DILATION + 1.0)));
|
||||
|
||||
float luma = dot(vec3(0.2126, 0.7152, 0.0722), col);
|
||||
float bright = (max(col.r, max(col.g, col.b)) + luma) / 2.0;
|
||||
float bright = (max(col.r, max(col.g, col.b)) + luma) * 0.5;
|
||||
float scan_bright = clamp(bright, SCANLINE_BRIGHT_MIN, SCANLINE_BRIGHT_MAX);
|
||||
float scan_beam = clamp(bright * SCANLINE_BEAM_WIDTH_MAX, SCANLINE_BEAM_WIDTH_MIN, SCANLINE_BEAM_WIDTH_MAX);
|
||||
float scan_weight = 1.0 - pow(cos(vTexCoord.y * 2.0 * PI * global.SourceSize.y) * 0.5 + 0.5, scan_beam) * SCANLINE_STRENGTH;
|
||||
|
||||
float mask = 1.0 - MASK_STRENGTH;
|
||||
vec2 mod_fac = floor(vTexCoord * global.OutputSize.xy * global.SourceSize.xy / (global.SourceSize.xy * vec2(MASK_SIZE, MASK_DOT_HEIGHT * MASK_SIZE)));
|
||||
vec2 mod_fac = floor(vTexCoord * global.OutputSize.xy * global.SourceSize.zw * (global.SourceSize.xy * vec2(MASK_SIZE, MASK_DOT_HEIGHT * MASK_SIZE)));
|
||||
int dot_no = int(mod((mod_fac.x + mod(mod_fac.y, 2.0) * MASK_STAGGER) / MASK_DOT_WIDTH, 3.0));
|
||||
vec3 mask_weight;
|
||||
|
||||
if (dot_no == 0) mask_weight = vec3(1.0, mask, mask);
|
||||
else if (dot_no == 1) mask_weight = vec3(mask, 1.0, mask);
|
||||
if (dot_no == 0) mask_weight = vec3(1.0, mask, mask);
|
||||
else if (dot_no == 1) mask_weight = vec3(mask, 1.0, mask);
|
||||
else mask_weight = vec3(mask, mask, 1.0);
|
||||
|
||||
if (global.SourceSize.y >= SCANLINE_CUTOFF) scan_weight = 1.0;
|
||||
if (global.SourceSize.y >= SCANLINE_CUTOFF)
|
||||
scan_weight = 1.0;
|
||||
|
||||
col2 = col.rgb;
|
||||
col *= vec3(scan_weight);
|
||||
|
|
Loading…
Reference in a new issue