diff --git a/crt/shaders/crt-slangtest/scanline.slang b/crt/shaders/crt-slangtest/scanline.slang index dd10f98..f771de0 100644 --- a/crt/shaders/crt-slangtest/scanline.slang +++ b/crt/shaders/crt-slangtest/scanline.slang @@ -33,7 +33,7 @@ void main() { vec2 tex = vTexCoord * global.SourceSize.xy; - float frac = fract(tex.y) - 0.5; + float fraction = fract(tex.y) - 0.5; tex.y = floor(tex.y) + 0.5; tex = tex * global.SourceSize.zw; @@ -42,7 +42,7 @@ void main() vec3 l1 = TEX(0, 0); vec3 l2 = TEX(0, 1); - vec3 dist = (3.5 - 1.0 * vec3(luma(l0), luma(l1), luma(l2))) * (frac + vec3(+1.0, 0.0, -1.0)); + vec3 dist = (3.5 - 1.0 * vec3(luma(l0), luma(l1), luma(l2))) * (fraction + vec3(+1.0, 0.0, -1.0)); dist = exp2(-dist * dist); vec3 color = diff --git a/scanlines/shaders/res-independent-scanlines.slang b/scanlines/shaders/res-independent-scanlines.slang new file mode 100644 index 0000000..d2b5ae9 --- /dev/null +++ b/scanlines/shaders/res-independent-scanlines.slang @@ -0,0 +1,55 @@ +#version 450 + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; + vec4 FinalViewportSize; + float SCANLINE_SINE_COMP_B; + float scanline_size; +} params; + +#pragma parameter SCANLINE_SINE_COMP_B "Scanline Sine Comp B" 0.25 0.0 1.0 0.05 +#pragma parameter scanline_size "Scanline Scale" 4.0 2.0 10.0 0.5 + +#define SCANLINE_SINE_COMP_B params.SCANLINE_SINE_COMP_B +#define scanline_size params.scanline_size + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; +} global; + +#define pi 3.141592654 + +#pragma stage vertex +layout(location = 0) in vec4 Position; +layout(location = 1) in vec2 TexCoord; +layout(location = 0) out vec2 vTexCoord; +layout(location = 1) out vec2 omega; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; + + omega = vec2(pi * params.OutputSize.x, 2.0 * pi * params.SourceSize.y); +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 1) in vec2 omega; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + +void main() +{ + vec2 sine_comp = vec2(0.0, SCANLINE_SINE_COMP_B); + vec3 res = texture(Source, vTexCoord).xyz; + vec2 fragcoord = vTexCoord.xy * params.FinalViewportSize.xy; + // picked 224 here as a magic number because it's a common 240p res and therefore a good starting point + vec3 scanline = res * ((1. - 0.75 * SCANLINE_SINE_COMP_B) + dot(sine_comp * sin((fragcoord / (224. * scanline_size)) * omega), vec2(1.0, 1.0))); + FragColor = vec4(scanline.x, scanline.y, scanline.z, 1.0); +} diff --git a/misc/scanline-fract.slang b/scanlines/shaders/scanline-fract.slang similarity index 100% rename from misc/scanline-fract.slang rename to scanlines/shaders/scanline-fract.slang diff --git a/misc/scanline.slang b/scanlines/shaders/scanline.slang similarity index 99% rename from misc/scanline.slang rename to scanlines/shaders/scanline.slang index fe8be73..a0d5eb6 100644 --- a/misc/scanline.slang +++ b/scanlines/shaders/scanline.slang @@ -53,3 +53,4 @@ void main() vec3 scanline = res * (SCANLINE_BASE_BRIGHTNESS + dot(sine_comp * sin(vTexCoord * omega), vec2(1.0, 1.0))); FragColor = vec4(scanline.x, scanline.y, scanline.z, 1.0); } + diff --git a/misc/scanlines-sine-abs.slang b/scanlines/shaders/scanlines-sine-abs.slang similarity index 100% rename from misc/scanlines-sine-abs.slang rename to scanlines/shaders/scanlines-sine-abs.slang