From 43c28f1f1596585ea9bb0eb98b703acf054ea57a Mon Sep 17 00:00:00 2001 From: hunterk Date: Thu, 29 Sep 2016 14:53:20 -0500 Subject: [PATCH] add a bunch of hyllian shaders --- ddt/ddt.slangp | 5 + ddt/shaders/ddt.slang | 146 ++++++++++++++ denoisers/fast-bilateral.slangp | 5 + denoisers/shaders/fast-bilateral.slang | 137 +++++++++++++ nedi/fast-bilateral-nedi.slangp | 32 ++++ nedi/nedi.slangp | 29 +++ nedi/shaders/nedi-jinc.slang | 201 +++++++++++++++++++ nedi/shaders/nedi-pass0.slang | 170 ++++++++++++++++ nedi/shaders/nedi-pass1.slang | 176 +++++++++++++++++ nedi/shaders/nedi-pass2.slang | 167 ++++++++++++++++ quad/shaders/biquad.slang | 133 +++++++++++++ quad/shaders/quad_interp.slang | 113 +++++++++++ sabr/shaders/sabr-v3.0.slang | 256 +++++++++++++++++++++++++ 13 files changed, 1570 insertions(+) create mode 100644 ddt/ddt.slangp create mode 100644 ddt/shaders/ddt.slang create mode 100644 denoisers/fast-bilateral.slangp create mode 100644 denoisers/shaders/fast-bilateral.slang create mode 100644 nedi/fast-bilateral-nedi.slangp create mode 100644 nedi/nedi.slangp create mode 100644 nedi/shaders/nedi-jinc.slang create mode 100644 nedi/shaders/nedi-pass0.slang create mode 100644 nedi/shaders/nedi-pass1.slang create mode 100644 nedi/shaders/nedi-pass2.slang create mode 100644 quad/shaders/biquad.slang create mode 100644 quad/shaders/quad_interp.slang create mode 100644 sabr/shaders/sabr-v3.0.slang diff --git a/ddt/ddt.slangp b/ddt/ddt.slangp new file mode 100644 index 00000000..3aa89407 --- /dev/null +++ b/ddt/ddt.slangp @@ -0,0 +1,5 @@ +shaders = 1 + +shader0 = shaders/ddt.slang +filter_linear0 = false +scale_type_0 = source \ No newline at end of file diff --git a/ddt/shaders/ddt.slang b/ddt/shaders/ddt.slang new file mode 100644 index 00000000..4805f346 --- /dev/null +++ b/ddt/shaders/ddt.slang @@ -0,0 +1,146 @@ +#version 450 + +/* + Hyllian's DDT Shader + + Copyright (C) 2011-2016 Hyllian/Jararaca - sergiogdb@gmail.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; +} params; + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; +} global; + +#define saturate(c) clamp(c, 0.0, 1.0) +#define lerp(c) mix(c) +#define mul(a,b) (b*a) +#define fmod(c) mod(c) +#define frac(c) fract(c) +#define tex2D(c,d) texture(c,d) +#define float2 vec2 +#define float3 vec3 +#define float4 vec4 +#define int2 ivec2 +#define int3 ivec3 +#define int4 ivec4 +#define bool2 bvec2 +#define bool3 bvec3 +#define bool4 bvec4 +#define float2x2 mat2x2 +#define float3x3 mat3x3 +#define float4x4 mat4x4 + +#define decal Source + +const float3 Y = float3(.2126, .7152, .0722); + +float luma(float3 color) +{ + return dot(color, Y); +} + +float3 bilinear(float p, float q, float3 A, float3 B, float3 C, float3 D) +{ + return ((1-p)*(1-q)*A + p*(1-q)*B + (1-p)*q*C + p*q*D); +} + +#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 vec4 t1; +layout(location = 2) out vec2 loc; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; + + float2 ps = float2(params.SourceSize.z, params.SourceSize.w); + float dx = ps.x; + float dy = ps.y; + + t1.xy = float2( dx, 0); // F + t1.zw = float2( 0, dy); // H + loc = vTexCoord*params.SourceSize.xy; +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 1) in vec4 t1; +layout(location = 2) in vec2 loc; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + +void main() +{ +float2 pos = frac(loc * 1.00001)-float2(0.4999, 0.4999); // pos = pixel position + float2 dir = sign(pos); // dir = pixel direction + + float2 g1 = dir*t1.xy; + float2 g2 = dir*t1.zw; + + float3 A = tex2D(decal, vTexCoord ).xyz; + float3 B = tex2D(decal, vTexCoord +g1 ).xyz; + float3 C = tex2D(decal, vTexCoord +g2).xyz; + float3 D = tex2D(decal, vTexCoord +g1+g2).xyz; + + float a = luma(A); + float b = luma(B); + float c = luma(C); + float d = luma(D); + + float p = abs(pos.x); + float q = abs(pos.y); + + float k = distance(pos,g1); + float l = distance(pos,g2); + + float wd1 = abs(a-d); + float wd2 = abs(b-c); + + if ( wd1 < wd2 ) + { + if (k < l) + { + C = A + D - B; + } + else + { + B = A + D - C; + } + } + else if (wd1 > wd2) + { + D = B + C - A; + } + + float3 color = bilinear(p, q, A, B, C, D); + FragColor = vec4(color, 1.0); +} \ No newline at end of file diff --git a/denoisers/fast-bilateral.slangp b/denoisers/fast-bilateral.slangp new file mode 100644 index 00000000..d87f25a1 --- /dev/null +++ b/denoisers/fast-bilateral.slangp @@ -0,0 +1,5 @@ +shaders = 1 + +shader0 = shaders/fast-bilateral.slang +filter_linear0 = false +scale_type_0 = source \ No newline at end of file diff --git a/denoisers/shaders/fast-bilateral.slang b/denoisers/shaders/fast-bilateral.slang new file mode 100644 index 00000000..fef452a1 --- /dev/null +++ b/denoisers/shaders/fast-bilateral.slang @@ -0,0 +1,137 @@ +#version 450 + +/* + Hyllian's Fast Bilateral Shader + + Copyright (C) 2011/2016 Hyllian - sergiogdb@gmail.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + +*/ + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; + float SIGMA_R; +} params; + +#pragma parameter SIGMA_R "Bilateral Blur" 0.4 0.0 1.0 0.1 + +#define SIGMA_R params.SIGMA_R + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; +} global; + +#define saturate(c) clamp(c, 0.0, 1.0) +#define lerp(c) mix(c) +#define mul(a,b) (b*a) +#define fmod(c) mod(c) +#define frac(c) fract(c) +#define tex2D(c,d) texture(c,d) +#define float2 vec2 +#define float3 vec3 +#define float4 vec4 +#define int2 ivec2 +#define int3 ivec3 +#define int4 ivec4 +#define bool2 bvec2 +#define bool3 bvec3 +#define bool4 bvec4 +#define float2x2 mat2x2 +#define float3x3 mat3x3 +#define float4x4 mat4x4 + +#define decal Source + +#define GET(M,K) (tex2D(decal,tc+M*dx+K*dy).xyz) + +#define BIL(M,K) {col=GET(M,K);ds=M*M+K*K;weight=exp(-ds/sd2)*exp(-(col-center)*(col-center)/si2);color+=(weight*col);wsum+=weight;} + +#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() +{ + float ds, sd2, si2; + float sigma_d = 3.0; + float sigma_r = SIGMA_R*0.04; + + float3 color = float3(0.0, 0.0, 0.0); + float3 wsum = float3(0.0, 0.0, 0.0); + float3 weight; + + float2 dx = float2(1.0, 0.0) * params.SourceSize.zw; + float2 dy = float2(0.0, 1.0) * params.SourceSize.zw; + + sd2 = 2.0 * sigma_d * sigma_d; + si2 = 2.0 * sigma_r * sigma_r; + + float2 tc = vTexCoord; + + float3 col; + float3 center = GET(0,0); + + BIL(-2,-2) + BIL(-1,-2) + BIL( 0,-2) + BIL( 1,-2) + BIL( 2,-2) + BIL(-2,-1) + BIL(-1,-1) + BIL( 0,-1) + BIL( 1,-1) + BIL( 2,-1) + BIL(-2, 0) + BIL(-1, 0) + BIL( 0, 0) + BIL( 1, 0) + BIL( 2, 0) + BIL(-2, 1) + BIL(-1, 1) + BIL( 0, 1) + BIL( 1, 1) + BIL( 2, 1) + BIL(-2, 2) + BIL(-1, 2) + BIL( 0, 2) + BIL( 1, 2) + BIL( 2, 2) + + // Weight normalization + color /= wsum; + FragColor = vec4(color, 1.0); +} \ No newline at end of file diff --git a/nedi/fast-bilateral-nedi.slangp b/nedi/fast-bilateral-nedi.slangp new file mode 100644 index 00000000..8502dcd1 --- /dev/null +++ b/nedi/fast-bilateral-nedi.slangp @@ -0,0 +1,32 @@ +shaders = "5" +shader0 = ../denoisers/shaders/fast-bilateral.slang +filter_linear0 = false +scale_type_0 = source +shader1 = "shaders/nedi-pass0.slang" +filter_linear1 = false +wrap_mode1 = "clamp_to_border" +float_framebuffer1 = "false" +scale_type_x1 = "source" +scale_x1 = "2.000000" +scale_type_y1 = "source" +scale_y1 = "1.000000" +shader2 = "shaders/nedi-pass1.slang" +filter_linear2 = false +wrap_mode2 = "clamp_to_border" +float_framebuffer2 = "false" +scale_type_x2 = "source" +scale_x2 = "1.000000" +scale_type_y2 = "source" +scale_y2 = "2.000000" +shader3 = "shaders/nedi-pass2.slang" +filter_linear3 = false +wrap_mode3 = "clamp_to_border" +float_framebuffer3 = "false" +scale_type_x3 = "source" +scale_x3 = "1.000000" +scale_type_y3 = "source" +scale_y3 = "1.000000" +shader4 = "shaders/nedi-jinc.slang" +filter_linear4 = false +wrap_mode4 = "clamp_to_border" +float_framebuffer4 = "false" \ No newline at end of file diff --git a/nedi/nedi.slangp b/nedi/nedi.slangp new file mode 100644 index 00000000..9d94c797 --- /dev/null +++ b/nedi/nedi.slangp @@ -0,0 +1,29 @@ +shaders = "4" +shader0 = "shaders/nedi-pass0.slang" +filter_linear0 = false +wrap_mode0 = "clamp_to_border" +float_framebuffer0 = "false" +scale_type_x0 = "source" +scale_x0 = "2.000000" +scale_type_y0 = "source" +scale_y0 = "1.000000" +shader1 = "shaders/nedi-pass1.slang" +filter_linear1 = false +wrap_mode1 = "clamp_to_border" +float_framebuffer1 = "false" +scale_type_x1 = "source" +scale_x1 = "1.000000" +scale_type_y1 = "source" +scale_y1 = "2.000000" +shader2 = "shaders/nedi-pass2.slang" +filter_linear2 = false +wrap_mode2 = "clamp_to_border" +float_framebuffer2 = "false" +scale_type_x2 = "source" +scale_x2 = "1.000000" +scale_type_y2 = "source" +scale_y2 = "1.000000" +shader3 = "shaders/nedi-jinc.slang" +filter_linear3 = false +wrap_mode3 = "clamp_to_border" +float_framebuffer3 = "false" \ No newline at end of file diff --git a/nedi/shaders/nedi-jinc.slang b/nedi/shaders/nedi-jinc.slang new file mode 100644 index 00000000..c92ea072 --- /dev/null +++ b/nedi/shaders/nedi-jinc.slang @@ -0,0 +1,201 @@ +#version 450 + +/* + Hyllian's jinc windowed-jinc 2-lobe with anti-ringing Shader + + Copyright (C) 2011-2016 Hyllian - sergiogdb@gmail.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + +*/ + + /* + This is an approximation of Jinc(x)*Jinc(x*r1/r2) for x < 2.5, + where r1 and r2 are the first two zeros of jinc function. + For a jinc 2-lobe best approximation, use A=0.5 and B=0.825. + */ + +// A=0.5, B=0.825 is the best jinc approximation for x<2.5. if B=1.0, it's a lanczos filter. +// Increase A to get more blur. Decrease it to get a sharper picture. +// B = 0.825 to get rid of dithering. Increase B to get a fine sharpness, though dithering returns. + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; + float JINC2_WINDOW_SINC; + float JINC2_SINC; + float JINC2_AR_STRENGTH; +} params; + +#pragma parameter JINC2_WINDOW_SINC "Window Sinc Param" 0.42 0.0 1.0 0.01 +#pragma parameter JINC2_SINC "Sinc Param" 0.92 0.0 1.0 0.01 +#pragma parameter JINC2_AR_STRENGTH "Anti-ringing Strength" 0.8 0.0 1.0 0.1 + +#define JINC2_WINDOW_SINC params.JINC2_WINDOW_SINC +#define JINC2_SINC params.JINC2_SINC +#define JINC2_AR_STRENGTH params.JINC2_AR_STRENGTH + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; +} global; + +#define saturate(c) clamp(c, 0.0, 1.0) +#define lerp(a,b,c) mix(a,b,c) +#define mul(a,b) (b*a) +#define fmod(c) mod(c) +#define frac(c) fract(c) +#define tex2D(c,d) texture(c,d) +#define float2 vec2 +#define float3 vec3 +#define float4 vec4 +#define int2 ivec2 +#define int3 ivec3 +#define int4 ivec4 +#define bool2 bvec2 +#define bool3 bvec3 +#define bool4 bvec4 +#define float2x2 mat2x2 +#define float3x3 mat3x3 +#define float4x4 mat4x4 +#define float4x3 mat4x3 + +#define halfpi 1.5707963267948966192313216916398 +#define pi 3.1415926535897932384626433832795 +#define wa (JINC2_WINDOW_SINC*pi) +#define wb (JINC2_SINC*pi) + +const float3 Y = float3(0.299, 0.587, 0.114); + +float df(float A, float B) +{ + return abs(A-B); +} + +// Calculates the distance between two points +float d(float2 pt1, float2 pt2) +{ + float2 v = pt2 - pt1; + return sqrt(dot(v,v)); +} + +float3 min4(float3 a, float3 b, float3 c, float3 d) +{ + return min(a, min(b, min(c, d))); +} + +float3 max4(float3 a, float3 b, float3 c, float3 d) +{ + return max(a, max(b, max(c, d))); +} + + float4 resampler(float4 x) + { + float4 res; + + res = (x==float4(0.0, 0.0, 0.0, 0.0)) ? float4(wa*wb) : sin(x*wa)*sin(x*wb)/(x*x); + + return res; + } + +#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 * 1.00001; +} + +#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() +{ + float3 color; + float4x4 weights; + + float2 dx = float2(1.0, 0.0); + float2 dy = float2(0.0, 1.0); + + float2 pc = vTexCoord*params.SourceSize.xy; + + float2 tc = (floor(pc-float2(0.4999,0.4999))+float2(0.4999,0.4999)); + + weights[0] = resampler(float4(d(pc, tc -dx -dy), d(pc, tc -dy), d(pc, tc +dx -dy), d(pc, tc+2.0*dx -dy))); + weights[1] = resampler(float4(d(pc, tc -dx ), d(pc, tc ), d(pc, tc +dx ), d(pc, tc+2.0*dx ))); + weights[2] = resampler(float4(d(pc, tc -dx +dy), d(pc, tc +dy), d(pc, tc +dx +dy), d(pc, tc+2.0*dx +dy))); + weights[3] = resampler(float4(d(pc, tc -dx+2.0*dy), d(pc, tc +2.0*dy), d(pc, tc +dx+2.0*dy), d(pc, tc+2.0*dx+2.0*dy))); + + //weights[0][0] = weights[0][3] = weights[3][0] = weights[3][3] = 0.0; + + dx = dx * params.SourceSize.zw; + dy = dy * params.SourceSize.zw; + tc = tc * params.SourceSize.zw; + + // reading the texels + + float3 c00 = tex2D(Source, tc -dx -dy).xyz; + float3 c10 = tex2D(Source, tc -dy).xyz; + float3 c20 = tex2D(Source, tc +dx -dy).xyz; + float3 c30 = tex2D(Source, tc+2.0*dx -dy).xyz; + float3 c01 = tex2D(Source, tc -dx ).xyz; + float3 c11 = tex2D(Source, tc ).xyz; + float3 c21 = tex2D(Source, tc +dx ).xyz; + float3 c31 = tex2D(Source, tc+2.0*dx ).xyz; + float3 c02 = tex2D(Source, tc -dx +dy).xyz; + float3 c12 = tex2D(Source, tc +dy).xyz; + float3 c22 = tex2D(Source, tc +dx +dy).xyz; + float3 c32 = tex2D(Source, tc+2.0*dx +dy).xyz; + float3 c03 = tex2D(Source, tc -dx+2.0*dy).xyz; + float3 c13 = tex2D(Source, tc +2.0*dy).xyz; + float3 c23 = tex2D(Source, tc +dx+2.0*dy).xyz; + float3 c33 = tex2D(Source, tc+2.0*dx+2.0*dy).xyz; + + + + color = mul(weights[0], float4x3(c00, c10, c20, c30)); + color+= mul(weights[1], float4x3(c01, c11, c21, c31)); + color+= mul(weights[2], float4x3(c02, c12, c22, c32)); + color+= mul(weights[3], float4x3(c03, c13, c23, c33)); + color = color/(dot(mul(weights, float4(1.0)), float4(1.0))); + + + + // Anti-ringing + // Get min/max samples + + float3 min_sample = min4(c11, c21, c12, c22); + float3 max_sample = max4(c11, c21, c12, c22); + + float3 aux = color; + color = clamp(color, min_sample, max_sample); + + color = mix(aux, color, JINC2_AR_STRENGTH); + + // final sum and weight normalization + FragColor = vec4(color, 1.0); +} \ No newline at end of file diff --git a/nedi/shaders/nedi-pass0.slang b/nedi/shaders/nedi-pass0.slang new file mode 100644 index 00000000..d09ff950 --- /dev/null +++ b/nedi/shaders/nedi-pass0.slang @@ -0,0 +1,170 @@ +#version 450 + +/* + NEDI Shader - pass0 + +// This file is a part of MPDN Extensions. +// https://github.com/zachsaw/MPDN_Extensions +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3.0 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library. +// + + Sources ported from this discussion thread: + + http://forum.doom9.org/showthread.php?t=170727 + + Ported by Hyllian - 2015. +*/ + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; +} params; + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; +} global; + +#define saturate(c) clamp(c, 0.0, 1.0) +#define lerp(c) mix(c) +#define mul(a,b) (b*a) +#define fmod(c) mod(c) +#define frac(c) fract(c) +#define tex2D(c,d) texture(c,d) +#define float2 vec2 +#define float3 vec3 +#define float4 vec4 +#define int2 ivec2 +#define int3 ivec3 +#define int4 ivec4 +#define bool2 bvec2 +#define bool3 bvec3 +#define bool4 bvec4 +#define float2x2 mat2x2 +#define float2x3 mat2x3 +#define float3x3 mat3x3 +#define float4x4 mat4x4 +#define float4x2 mat4x2 + +#define NEDI_WEIGHT 4.0 +#define NEDI_N 24.0 +#define NEDI_E 0.0 +#define NEDI_OFFSET 0.0 + +#define ITERATIONS 3 +#define WGT 2 + +#define width (params.SourceSize.x) +#define height (params.SourceSize.y) + +#define px (0.49999 / (params.SourceSize.x)) +#define py (0.49999 / (params.SourceSize.y)) + +#define offset NEDI_OFFSET +//#define offset 0.0 + +#define Value(xy) (tex2D(Source,tex+float2(px,py)*(xy)).rgb)//-float4(0.0,0.4999,0.4999,0.0)) + +#define Get(xy) (dot(Value(xy),float3(.2126, .7152, .0722))+offset) +#define Get4(xy) (float2(Get(xy+WGT*dir[0])+Get(xy+WGT*dir[1]),Get(xy+WGT*dir[2])+Get(xy+WGT*dir[3]))) + +#define sqr(x) (dot(x,x)) +#define I (float2x2(1,0,0,1)) + +//Cramer's method +float2 solve(float2x2 A,float2 b) { return float2(determinant(float2x2(b,A[1])),determinant(float2x2(A[0],b)))/determinant(A); } + +#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 * 1.00001; +} + +#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() +{ +float2 tex = vTexCoord + float2(0.0, 0.25*params.SourceSize.w); + + float4 c0 = tex2D(Source,tex); + +/* + wind[1] wind[2] +-3 +-2 dir wind[0] 2 1 +-1 4 4 4 4 + 0 1 2 1 2 + 1 3 3 3 3 + 2 1 2 + 3 +*/ +/* + wind[1] wind[2] +-3 3 3 +-2 dir wind[0] +-1 0 3 0 3 0 1 + 0 + 1 2 1 2 1 1 0 + 2 + 3 2 2 +*/ + + //Define window and directions - original + float2 dir[4] = {{-1,-1},{1,1},{-1,1},{1,-1}}; + float4x2 wind[4] = {{{-1,-1},{1,1},{-1,1},{1,-1}},{{-3,-1},{3,1},{-1,3},{1,-3}},{{-3,1},{3,-1},{1,3},{-1,-3}},{{-3,-3},{ 3,3},{-3, 3},{3,-3}}}; + + //Initialization + float2x2 R = float2x2(0.0); + float2 r = float2(0.0); + + float m[4] = {NEDI_WEIGHT, 1.0, 1.0, 1.0}; + + //Calculate (local) autocorrelation coefficients + for (int k = 0; k0.4999)&&(frac(tex.y*height)>0.4999)) FragColor = c0; + else FragColor = float4(c, 1.0);//+float4(0,0.49999,0.49999,0); +} \ No newline at end of file diff --git a/nedi/shaders/nedi-pass2.slang b/nedi/shaders/nedi-pass2.slang new file mode 100644 index 00000000..8f3f1a27 --- /dev/null +++ b/nedi/shaders/nedi-pass2.slang @@ -0,0 +1,167 @@ +#version 450 + +/* + NEDI Shader - pass2 + +// This file is a part of MPDN Extensions. +// https://github.com/zachsaw/MPDN_Extensions +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3.0 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library. +// + + Sources ported from this discussion thread: + + http://forum.doom9.org/showthread.php?t=170727 + + Ported by Hyllian - 2015. +*/ + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; +} params; + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; +} global; + +#define saturate(c) clamp(c, 0.0, 1.0) +#define lerp(c) mix(c) +#define mul(a,b) (b*a) +#define fmod(c) mod(c) +#define frac(c) fract(c) +#define tex2D(c,d) texture(c,d) +#define float2 vec2 +#define float3 vec3 +#define float4 vec4 +#define int2 ivec2 +#define int3 ivec3 +#define int4 ivec4 +#define bool2 bvec2 +#define bool3 bvec3 +#define bool4 bvec4 +#define float2x2 mat2x2 +#define float2x3 mat2x3 +#define float3x3 mat3x3 +#define float4x4 mat4x4 +#define float4x2 mat4x2 + +#define s0 Source + +#define NEDI_WEIGHT3 2.0 +#define NEDI_N3 24.0 +#define NEDI_E3 0.0 + +#define ITERATIONS 3 +#define WGT NEDI_WEIGHT3 + +#define width (params.SourceSize.x) +#define height (params.SourceSize.y) + +#define px (0.49999 * (params.SourceSize.z)) +#define py (0.49999 * (params.SourceSize.w)) + +#define offset 0.0 + +#define Value(xy) (tex2D(s0,tex+float2(px,py)*(xy)).rgb)//-float4(0,0.5,0.5,0)) + +#define Get(xy) (dot(Value(xy),float3(0.299,0.587,0.114))+offset) +#define Get4(xy) (float2(Get(xy+WGT*dir[0])+Get(xy+WGT*dir[1]),Get(xy+WGT*dir[2])+Get(xy+WGT*dir[3]))) + +#define sqr(x) (dot(x,x)) +#define I (float2x2(1,0,0,1)) + +//Cramer's method +float2 solve(float2x2 A,float2 b) { return float2(determinant(float2x2(b,A[1])),determinant(float2x2(A[0],b)))/determinant(A); } + +#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 * 1.00001; +} + +#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() +{ + float2 tex = vTexCoord - float2(0.4999,0.4999)/params.SourceSize.xy; + +/* + wind[1] wind[2] +-3 +-2 dir wind[0] 2 1 +-1 4 4 4 4 + 0 1 2 1 2 + 1 3 3 3 3 + 2 1 2 + 3 +*/ +/* + wind[1] wind[2] +-3 3 1 +-2 dir wind[0] +-1 1 4 1 3 1 3 + 0 + 1 3 2 2 4 4 2 + 2 + 3 2 4 +*/ + + //Define window and directions + float2 dir[4] = {{-1,-1},{1,1},{-1,1},{1,-1}}; + float4x2 wind[4] = {{{-1,-1},{1,1},{-1,1},{1,-1}},{{-3,-1},{3,1},{-1,3},{1,-3}},{{-3,1},{3,-1},{1,3},{-1,-3}},{{-3,-3},{ 3,3},{-3, 3},{3,-3}}}; + + //Initialization + float2x2 R = float2x2(0.0); + float2 r = float2(0.0); + + //Calculate (local) autocorrelation coefficients + for (int k = 0; k