From aaca9c96aaee94024dcec5b333530cf2023e9640 Mon Sep 17 00:00:00 2001 From: metallic77 <43163462+metallic77@users.noreply.github.com> Date: Tue, 25 Apr 2023 15:59:48 +0300 Subject: [PATCH] add bilinear-adjustable (#401) * add bilinear-adjustable * add bilinear-adjustable --- interpolation/bilinear-adjustable.slangp | 5 ++ .../shaders/bilinear-adjustable.slang | 79 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 interpolation/bilinear-adjustable.slangp create mode 100644 interpolation/shaders/bilinear-adjustable.slang diff --git a/interpolation/bilinear-adjustable.slangp b/interpolation/bilinear-adjustable.slangp new file mode 100644 index 0000000..84bd261 --- /dev/null +++ b/interpolation/bilinear-adjustable.slangp @@ -0,0 +1,5 @@ +shaders = 1 + +shader0 = "shaders/bilinear-adjustable.slang" +filter_linear0 = true +scale_type0 = viewport diff --git a/interpolation/shaders/bilinear-adjustable.slang b/interpolation/shaders/bilinear-adjustable.slang new file mode 100644 index 0000000..0679113 --- /dev/null +++ b/interpolation/shaders/bilinear-adjustable.slang @@ -0,0 +1,79 @@ +#version 450 + +/* + April 2023 + Adjustable Bilinear by DariusG + +*/ +#pragma parameter sharp1 "Horizontal Sharpness" 1.0 1.0 10.0 0.1 +#pragma parameter sharp2 "Vertical Sharpness" 1.0 1.0 10.0 0.1 + + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + float sharp1; + float sharp2; + +} params; + +#define sharp1 params.sharp1 +#define sharp2 params.sharp2 +#define SourceSize params.SourceSize + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; + vec4 FinalViewportSize; + vec4 OutputSize; +} 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 = 1) uniform sampler2D Source; + + +void main() +{ + +vec2 OneTexel = SourceSize.zw; + +vec2 OGL2Pos = vTexCoord * SourceSize.xy; +vec2 pC4 = floor(OGL2Pos) * OneTexel + 0.5*OneTexel; + +vec2 coord4 = vec2 (0.0); +vec2 coord2 = vec2 (OneTexel.x, 0.0 ); +vec2 coord1 = vec2 (0.0, OneTexel.y); +vec2 coord3 = vec2 (OneTexel.x, OneTexel.y); + + +vec4 s4 = vec4(texture(Source, pC4 + coord4)); +vec4 s2 = vec4(texture(Source, pC4 + coord2)); +vec4 s1 = vec4(texture(Source, pC4 + coord1)); +vec4 s3 = vec4(texture(Source, pC4 + coord3)); + +float fu = pow(fract(OGL2Pos.x),sharp1); +float fv = pow(fract(OGL2Pos.y),sharp2); + +vec4 tmp1 = mix(s4, s2, fu); +vec4 tmp2 = mix(s1, s3, fu); + +vec4 t0 = mix(tmp1, tmp2, fv); + + FragColor = t0; +}