From a450ac1b2f13735d3309c425a7bb2b37d121ef42 Mon Sep 17 00:00:00 2001 From: hunterk Date: Tue, 14 Mar 2017 21:03:52 -0500 Subject: [PATCH] add crt-nes-mini --- crt/crt-nes-mini.slangp | 3 ++ crt/shaders/crt-nes-mini.slang | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 crt/crt-nes-mini.slangp create mode 100644 crt/shaders/crt-nes-mini.slang diff --git a/crt/crt-nes-mini.slangp b/crt/crt-nes-mini.slangp new file mode 100644 index 0000000..591af6d --- /dev/null +++ b/crt/crt-nes-mini.slangp @@ -0,0 +1,3 @@ +shaders = 1 + +shader0 = shaders/crt-nes-mini.slang diff --git a/crt/shaders/crt-nes-mini.slang b/crt/shaders/crt-nes-mini.slang new file mode 100644 index 0000000..d73a3fd --- /dev/null +++ b/crt/shaders/crt-nes-mini.slang @@ -0,0 +1,50 @@ +#version 450 + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; + float BRIGHTBOOST; + float INTENSITY; + float SCANTHICK; +} params; + +#pragma parameter SCANTHICK "Scanline Thickness" 2.0 2.0 4.0 2.0 +#pragma parameter INTENSITY "Scanline Intensity" 0.15 0.0 1.0 0.01 +#pragma parameter BRIGHTBOOST "Luminance Boost" 0.15 0.0 1.0 0.01 + +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; + +void main() +{ + vec3 texel = texture(Source, vTexCoord.xy).rgb; + vec3 pixelHigh = ((1.0 + params.BRIGHTBOOST) - (0.2 * texel)) * texel; + vec3 pixelLow = ((1.0 - params.INTENSITY) + (0.1 * texel)) * texel; + float selectY = mod(vTexCoord.y * params.SCANTHICK * params.SourceSize.y, 2.0); + float selectHigh = step(1.0, selectY); + float selectLow = 1.0 - selectHigh; + vec3 pixelColor = (selectLow * pixelLow) + (selectHigh * pixelHigh); + + FragColor = vec4(pixelColor, 1.0); +}