add a bunch of hyllian shaders

This commit is contained in:
hunterk 2016-09-29 14:53:20 -05:00
parent 91a3e4d8d9
commit 43c28f1f15
13 changed files with 1570 additions and 0 deletions

5
ddt/ddt.slangp Normal file
View file

@ -0,0 +1,5 @@
shaders = 1
shader0 = shaders/ddt.slang
filter_linear0 = false
scale_type_0 = source

146
ddt/shaders/ddt.slang Normal file
View file

@ -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);
}

View file

@ -0,0 +1,5 @@
shaders = 1
shader0 = shaders/fast-bilateral.slang
filter_linear0 = false
scale_type_0 = source

View file

@ -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);
}

View file

@ -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"

29
nedi/nedi.slangp Normal file
View file

@ -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"

View file

@ -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);
}

View file

@ -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; k<ITERATIONS; k+= 1){
float4 y = float4(Get(wind[k][0]),Get(wind[k][1]),Get(wind[k][2]),Get(wind[k][3]));
float4x2 C = float4x2(Get4(wind[k][0]),Get4(wind[k][1]),Get4(wind[k][2]),Get4(wind[k][3]));
R += mul(transpose(C),m[k]*C);
r += mul(y,m[k]*C);
}
//Normalize
float n = NEDI_N;
R /= n; r /= n;
//Calculate a = R^-1 . r
float e = NEDI_E;
float2 a = solve(R+e*e*I,r+e*e/2.0);
//Nomalize 'a' (prevents overshoot)
a = .25 + float2(.4999,-.4999)*clamp(a[0]-a[1],-1.0,1.0);
//Calculate result
float2x3 x = float2x3(Value(dir[0])+Value(dir[1]),Value(dir[2])+Value(dir[3])) * float2x2(a,a);
float3 c = float3(x[0].xyz);
//Skip pixels on wrong grid
if (frac(tex.x*width)<0.499999) FragColor = c0;
else FragColor = vec4(c, 1.0);
}

View file

@ -0,0 +1,176 @@
#version 450
/*
NEDI Shader - pass1
// 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 FIX(c) (c * 1.00001)
#define NEDI_WEIGHT2 4.0
#define NEDI_N2 24.0
#define NEDI_E2 0.0
#define NEDI_OFFSET2 0.0
#define ITERATIONS 3
#define WGT 2
#define width (params.SourceSize.x)
#define height (params.SourceSize.y)
#define px (0.4999 * (params.SourceSize.z))
#define py (0.4999 * (params.SourceSize.w))
#define offset NEDI_OFFSET2
#define Value(xy) (tex2D(s0,tex+float2(px,py)*(xy)).rgb)//-float4(0,0.4999,0.4999,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;
float4 c0 = tex2D(s0,tex);
//Define window and directions
float2 dir[4] = {{-1,0},{1,0},{0,1},{0,-1}};
float4x2 wind[7] = {{{-1,0},{1,0},{0,1},{0,-1}},{{-2,-1},{2,1},{-1,2},{1,-2}},{{-3,-2},{3,2},{-2,3},{2,-3}},
{{-2,1},{2,-1},{1,2},{-1,-2}},{{-3,2},{3,-2},{2,3},{-2,-3}},
{{-4,-1},{4,1},{-1,4},{1,-4}},{{-4,1},{4,-1},{1,4},{-1,-4}}};
/*
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
*/
//Initialization
float2x2 R = float2x2(0.0);
float2 r = float2(0.0);
float m[7] = {NEDI_WEIGHT2, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
//Calculate (local) autocorrelation coefficients
for (int k = 0; k<ITERATIONS; k+= 1){
float4 y = float4(Get(wind[k][0]),Get(wind[k][1]),Get(wind[k][2]),Get(wind[k][3]));
float4x2 C = float4x2(Get4(wind[k][0]),Get4(wind[k][1]),Get4(wind[k][2]),Get4(wind[k][3]));
R += mul(transpose(C),m[k]*C);
r += mul(y,m[k]*C);
}
//Normalize
float n = NEDI_N2;
R /= n; r /= n;
//Calculate a = R^-1 . r
float e = NEDI_E2;
float2 a = solve(R+e*e*I,r+e*e/2.0);
//Nomalize 'a' (prevents overshoot)
a = .25 + float2(.4999,-.4999)*clamp(a[0]-a[1],-1.0,1.0);
//Calculate result
float2x3 x = float2x3(Value(dir[0])+Value(dir[1]),Value(dir[2])+Value(dir[3])) * float2x2(a,a);
float3 c = float3(x[0].xyz);
//Skip pixels on wrong grid
if ((frac(tex.x*width/2.0)<0.4999)&&(frac(tex.y*height)<0.4999) || (frac(tex.x*width/2.0)>0.4999)&&(frac(tex.y*height)>0.4999)) FragColor = c0;
else FragColor = float4(c, 1.0);//+float4(0,0.49999,0.49999,0);
}

View file

@ -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<ITERATIONS; k+= 1){
float4 y = float4(Get(wind[k][0]),Get(wind[k][1]),Get(wind[k][2]),Get(wind[k][3]));
float4x2 C = float4x2(Get4(wind[k][0]),Get4(wind[k][1]),Get4(wind[k][2]),Get4(wind[k][3]));
R += mul(transpose(C),C);
r += mul(y,C);
}
//Normalize
float n = NEDI_N3;
R /= n; r /= n;
//Calculate a = R^-1 . r
float e = NEDI_E3;
float2 a = solve(R+e*e*I,r+e*e/2.0);
//Nomalize 'a' (prevents overshoot)
a = .25 + float2(.4999,-.4999)*clamp(a[0]-a[1],-1.0,1.0);
//Calculate result
float2x3 x = float2x3(Value(dir[0])+Value(dir[1]),Value(dir[2])+Value(dir[3])) * float2x2(a,a);
float3 c = float3(x[0].xyz);
// float3 c = Value(dir[0]);
FragColor = float4(c, 1.0);//+float4(0,0.5,0.5,0);
}

133
quad/shaders/biquad.slang Normal file
View file

@ -0,0 +1,133 @@
#version 450
/*
Hyllian's biquad Shader
Copyright (C) 2011-2015 Hyllian/Jararaca - sergiogdb@gmail.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float K;
} params;
#pragma parameter K "Blurring Param" 0.8 0.0 1.0 0.01
#define K params.K
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 s_p Source
// Calculates the distance between two points
float d(float2 pt1, float2 pt2)
{
float2 v = pt2 - pt1;
return sqrt(dot(v,v));
}
float3 resampler(float3 x)
{
float3 res;
res = lessThanEqual(x,float3(0.5, 0.5, 0.5)) == bvec3(true) ? (-2*K*x*x + 0.5*(K+1)) : (lessThanEqual(x,float3(1.5, 1.5, 1.5)) == bvec3(true) ? (K*x*x + (-2*K - 0.5)*x + 0.75*(K+1)) : float3(0.00001, 0.00001, 0.00001));
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;
}
#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;
float3x3 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.5,0.5));
weights[0] = resampler(float3(d(pc, tc -dx -dy), d(pc, tc -dy), d(pc, tc +dx -dy)));
weights[1] = resampler(float3(d(pc, tc -dx ), d(pc, tc ), d(pc, tc +dx )));
weights[2] = resampler(float3(d(pc, tc -dx +dy), d(pc, tc +dy), d(pc, tc +dx +dy)));
dx = dx * params.SourceSize.zw;
dy = dy * params.SourceSize.zw;
tc = tc * params.SourceSize.zw;
// reading the texels
float3 c00 = tex2D(s_p, tc -dx -dy).xyz;
float3 c10 = tex2D(s_p, tc -dy).xyz;
float3 c20 = tex2D(s_p, tc +dx -dy).xyz;
float3 c01 = tex2D(s_p, tc -dx ).xyz;
float3 c11 = tex2D(s_p, tc ).xyz;
float3 c21 = tex2D(s_p, tc +dx ).xyz;
float3 c02 = tex2D(s_p, tc -dx +dy).xyz;
float3 c12 = tex2D(s_p, tc +dy).xyz;
float3 c22 = tex2D(s_p, tc +dx +dy).xyz;
color = mul(weights[0], float3x3(c00, c10, c20));
color+= mul(weights[1], float3x3(c01, c11, c21));
color+= mul(weights[2], float3x3(c02, c12, c22));
color = color/(dot(mul(weights, float3(1.0)), float3(1.0)));
// final sum and weight normalization
FragColor = vec4(color, 1.0);
}

View file

@ -0,0 +1,113 @@
#version 450
/*
Author: Themaister
License: Public domain
*/
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float QUAD_INTERP_RESOLUTION_X;
float QUAD_INTERP_RESOLUTION_Y;
float QUAD_INTERP_SHARPNESS;
} params;
#pragma parameter QUAD_INTERP_RESOLUTION_X "QuadInterp Input Resolution X" 0.0 0.0 1920.0 1.0
#pragma parameter QUAD_INTERP_RESOLUTION_Y "QuadInterp Input Resolution Y" 0.0 0.0 1920.0 1.0
#pragma parameter QUAD_INTERP_SHARPNESS "QuadInterp Sharpness" 2.01 0.0 10.0 0.01
#define QUAD_INTERP_RESOLUTION_X params.QUAD_INTERP_RESOLUTION_X
#define QUAD_INTERP_RESOLUTION_Y params.QUAD_INTERP_RESOLUTION_Y
#define QUAD_INTERP_SHARPNESS params.QUAD_INTERP_SHARPNESS
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 s0 Source
#define tex vTexCoord
#define QUAD_INTERP_RESOLUTION_X_DEF params.SourceSize.x
#define QUAD_INTERP_RESOLUTION_Y_DEF params.SourceSize.y
float3 quad_inter(float3 x0, float3 x1, float3 x2, float x)
{
float3 poly[3];
poly[2] = 0.5 * x0 - x1 + 0.5*x2;
poly[1] = -1.5 * x0 + 2.0 * x1 - 0.5*x2;
poly[0] = x0;
return poly[2] * x * x + poly[1] * x + poly[0];
}
#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()
{
/* messy I know but we need to make it possible to have it default to input resolution x/y in case RESOLUTION_X is 0.0 */
float2 texsize = float2(1.0/((QUAD_INTERP_RESOLUTION_X == 0) ? QUAD_INTERP_RESOLUTION_X_DEF : QUAD_INTERP_RESOLUTION_X), 1.0/((QUAD_INTERP_RESOLUTION_Y == 0) ? QUAD_INTERP_RESOLUTION_Y_DEF : QUAD_INTERP_RESOLUTION_Y));
float dx = float(pow(QUAD_INTERP_SHARPNESS * texsize.x, -1.0));
float dy = float(pow(QUAD_INTERP_SHARPNESS * texsize.y, -1.0));
float3 c00 = tex2D(s0, tex + float2(-dx, -dy)).xyz;
float3 c01 = tex2D(s0, tex + float2(-dx, 0)).xyz;
float3 c02 = tex2D(s0, tex + float2(-dx, dy)).xyz;
float3 c10 = tex2D(s0, tex + float2(0, -dy)).xyz;
float3 c11 = tex2D(s0, tex + float2(0, 0)).xyz;
float3 c12 = tex2D(s0, tex + float2(0, dy)).xyz;
float3 c20 = tex2D(s0, tex + float2(dx, -dy)).xyz;
float3 c21 = tex2D(s0, tex + float2(dx, 0)).xyz;
float3 c22 = tex2D(s0, tex + float2(dx, dy)).xyz;
float frac_amt_x = frac(tex.x * texsize.x);
float frac_amt_y = frac(tex.y * texsize.y);
float3 loval = quad_inter(c00, c10, c20, frac_amt_x + 0.5);
float3 midval = quad_inter(c01, c11, c21, frac_amt_x + 0.5);
float3 hival = quad_inter(c02, c12, c22, frac_amt_x + 0.5);
float3 res = quad_inter(loval, midval, hival, frac_amt_y + 0.5);
// Bilinear!
// float3 first = lerp(c00, c20, frac(tex.x * texsize.x + 0.5));
// float3 second = lerp(c02, c22, frac(tex.x * texsize.x + 0.5));
// float3 res = lerp(first, second, frac(tex.y * texsize.y + 0.5));
// OUT.color = float4(res, 1.0);
FragColor = vec4(res, 1.0);
}

View file

@ -0,0 +1,256 @@
#version 450
/*
SABR v3.0 Shader
Joshua Street
Portions of this algorithm were taken from Hyllian's 5xBR v3.7c
shader.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
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(a,b,c) mix(a,b,c)
#define mul(a,b) (b*a)
#define fmod(a,b) mod(a,b)
#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 float4 Ai = float4( 1.0, -1.0, -1.0, 1.0);
const float4 B45 = float4( 1.0, 1.0, -1.0, -1.0);
const float4 C45 = float4( 1.5, 0.5, -0.5, 0.5);
const float4 B30 = float4( 0.5, 2.0, -0.5, -2.0);
const float4 C30 = float4( 1.0, 1.0, -0.5, 0.0);
const float4 B60 = float4( 2.0, 0.5, -2.0, -0.5);
const float4 C60 = float4( 2.0, 0.0, -1.0, 0.5);
const float4 M45 = float4(0.4, 0.4, 0.4, 0.4);
const float4 M30 = float4(0.2, 0.4, 0.2, 0.4);
const float4 M60 = M30.yxwz;
const float4 Mshift = float4(0.2, 0.2, 0.2, 0.2);
const float coef = 2.0;
const float4 threshold = float4(0.32, 0.32, 0.32, 0.32);
const float3 lum = float3(0.21, 0.72, 0.07);
float4 lum_to(float3 v0, float3 v1, float3 v2, float3 v3) {
return float4(dot(lum, v0), dot(lum, v1), dot(lum, v2), dot(lum, v3));
}
float4 lum_df(float4 A, float4 B) {
return abs(A - B);
}
bool4 lum_eq(float4 A, float4 B) {
return lessThan(lum_df(A, B) , float4(threshold));
}
float4 lum_wd(float4 a, float4 b, float4 c, float4 d, float4 e, float4 f, float4 g, float4 h) {
return lum_df(a, b) + lum_df(a, c) + lum_df(d, e) + lum_df(d, f) + 4.0 * lum_df(g, h);
}
float c_df(float3 c1, float3 c2) {
float3 df = abs(c1 - c2);
return df.r + df.g + df.b;
}
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 tc;
layout(location = 1) out vec4 xyp_1_2_3;
layout(location = 2) out vec4 xyp_5_10_15;
layout(location = 3) out vec4 xyp_6_7_8;
layout(location = 4) out vec4 xyp_9_14_9;
layout(location = 5) out vec4 xyp_11_12_13;
layout(location = 6) out vec4 xyp_16_17_18;
layout(location = 7) out vec4 xyp_21_22_23;
void main()
{
gl_Position = global.MVP * Position;
float x = params.SourceSize.z;//1.0 / IN.texture_size.x;
float y = params.SourceSize.w;//1.0 / IN.texture_size.y;
tc = TexCoord * 1.00001;
xyp_1_2_3 = tc.xxxy + float4( -x, 0.0, x, -2.0 * y);
xyp_6_7_8 = tc.xxxy + float4( -x, 0.0, x, -y);
xyp_11_12_13 = tc.xxxy + float4( -x, 0.0, x, 0.0);
xyp_16_17_18 = tc.xxxy + float4( -x, 0.0, x, y);
xyp_21_22_23 = tc.xxxy + float4( -x, 0.0, x, 2.0 * y);
xyp_5_10_15 = tc.xyyy + float4(-2.0 * x, -y, 0.0, y);
xyp_9_14_9 = tc.xyyy + float4( 2.0 * x, -y, 0.0, y);
}
#pragma stage fragment
layout(location = 0) in vec2 tc;
layout(location = 1) in vec4 xyp_1_2_3;
layout(location = 2) in vec4 xyp_5_10_15;
layout(location = 3) in vec4 xyp_6_7_8;
layout(location = 4) in vec4 xyp_9_14_9;
layout(location = 5) in vec4 xyp_11_12_13;
layout(location = 6) in vec4 xyp_16_17_18;
layout(location = 7) in vec4 xyp_21_22_23;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
/*
Mask for algorithm
+-----+-----+-----+-----+-----+
| | 1 | 2 | 3 | |
+-----+-----+-----+-----+-----+
| 5 | 6 | 7 | 8 | 9 |
+-----+-----+-----+-----+-----+
| 10 | 11 | 12 | 13 | 14 |
+-----+-----+-----+-----+-----+
| 15 | 16 | 17 | 18 | 19 |
+-----+-----+-----+-----+-----+
| | 21 | 22 | 23 | |
+-----+-----+-----+-----+-----+
*/
// Store mask values
float3 P1 = tex2D(decal, xyp_1_2_3.xw ).rgb;
float3 P2 = tex2D(decal, xyp_1_2_3.yw ).rgb;
float3 P3 = tex2D(decal, xyp_1_2_3.zw ).rgb;
float3 P6 = tex2D(decal, xyp_6_7_8.xw ).rgb;
float3 P7 = tex2D(decal, xyp_6_7_8.yw ).rgb;
float3 P8 = tex2D(decal, xyp_6_7_8.zw ).rgb;
float3 P11 = tex2D(decal, xyp_11_12_13.xw).rgb;
float3 P12 = tex2D(decal, xyp_11_12_13.yw).rgb;
float3 P13 = tex2D(decal, xyp_11_12_13.zw).rgb;
float3 P16 = tex2D(decal, xyp_16_17_18.xw).rgb;
float3 P17 = tex2D(decal, xyp_16_17_18.yw).rgb;
float3 P18 = tex2D(decal, xyp_16_17_18.zw).rgb;
float3 P21 = tex2D(decal, xyp_21_22_23.xw).rgb;
float3 P22 = tex2D(decal, xyp_21_22_23.yw).rgb;
float3 P23 = tex2D(decal, xyp_21_22_23.zw).rgb;
float3 P5 = tex2D(decal, xyp_5_10_15.xy ).rgb;
float3 P10 = tex2D(decal, xyp_5_10_15.xz ).rgb;
float3 P15 = tex2D(decal, xyp_5_10_15.xw ).rgb;
float3 P9 = tex2D(decal, xyp_9_14_9.xy ).rgb;
float3 P14 = tex2D(decal, xyp_9_14_9.xz ).rgb;
float3 P19 = tex2D(decal, xyp_9_14_9.xw ).rgb;
// Store luminance values of each point
float4 p7 = lum_to(P7, P11, P17, P13);
float4 p8 = lum_to(P8, P6, P16, P18);
float4 p11 = p7.yzwx; // P11, P17, P13, P7
float4 p12 = lum_to(P12, P12, P12, P12);
float4 p13 = p7.wxyz; // P13, P7, P11, P17
float4 p14 = lum_to(P14, P2, P10, P22);
float4 p16 = p8.zwxy; // P16, P18, P8, P6
float4 p17 = p7.zwxy; // P11, P17, P13, P7
float4 p18 = p8.wxyz; // P18, P8, P6, P16
float4 p19 = lum_to(P19, P3, P5, P21);
float4 p22 = p14.wxyz; // P22, P14, P2, P10
float4 p23 = lum_to(P23, P9, P1, P15);
float2 fp = frac(tc * params.SourceSize.xy);
float4 ma45 = smoothstep(C45 - M45, C45 + M45, Ai * fp.y + B45 * fp.x);
float4 ma30 = smoothstep(C30 - M30, C30 + M30, Ai * fp.y + B30 * fp.x);
float4 ma60 = smoothstep(C60 - M60, C60 + M60, Ai * fp.y + B60 * fp.x);
float4 marn = smoothstep(C45 - M45 + Mshift, C45 + M45 + Mshift, Ai * fp.y + B45 * fp.x);
float4 e45 = lum_wd(p12, p8, p16, p18, p22, p14, p17, p13);
float4 econt = lum_wd(p17, p11, p23, p13, p7, p19, p12, p18);
float4 e30 = lum_df(p13, p16);
float4 e60 = lum_df(p8, p17);
/* The whole edge detection thing seems broken here, so may as well comment it out to save cycles
bool4 r45 = (notEqual(p12 , p13) == bool4(true) && notEqual(p12 , p17) == bool4(true) && (
lum_eq(p13, p7) == bool4(false) && lum_eq(p13, p8) == bool4(false) ||
lum_eq(p17, p11) == bool4(false) && lum_eq(p17, p16) == bool4(false) ||
lum_eq(p12, p18) == bool4(true) && (
lum_eq(p13, p14) == bool4(false) && lum_eq(p13, p19) == bool4(false) ||
lum_eq(p17, p22) == bool4(false) && lum_eq(p17, p23) == bool4(false)) ||
lum_eq(p12, p16) == bool4(true) ||
lum_eq(p12, p8) == bool4(true))) ? bool4(true) : bool4(false);
bool4 r30 = (notEqual(p12 , p16) == bool4(true) && notEqual(p11 , p16) == bool4(true)) ? bool4(true) : bool4(false);
bool4 r60 = (notEqual(p12 , p8) == bool4(true) && notEqual(p7 , p8) == bool4(true)) ? bool4(true) : bool4(false);
bool4 edr45 = (lessThan(e45 , econt) == bool4(true) && r45 == bool4(true)) ? bool4(true) : bool4(false);
bool4 edrrn = (lessThanEqual(e45 , econt) == bool4(true)) ? bool4(true) : bool4(false);
bool4 edr30 = (lessThanEqual(e30 * coef , e60) == bool4(true) && (r30 == bool4(true))) ? bool4(true) : bool4(false);
bool4 edr60 = (lessThanEqual(e60 * coef , e30) == bool4(true) && (r60 == bool4(true))) ? bool4(true) : bool4(false);
*/
//FIXME: dunno what's up here. final45 is the only one that seems to matter and it's either all on or all off
// again, may as well comment it out to save cycles :/
float4 final45 = float4(1.0);//(edr30 == bool4(false) && edr60 == bool4(false) && edr45 == bool4(true)) ? float4(1.0) : float4(1.0);
float4 final30 = float4(0.0);//(edr45 == bool4(true) && edr30 == bool4(true) && edr60 == bool4(false)) ? float4(1.0) : float4(0.0);
float4 final60 = float4(0.0);//(edr45 == bool4(true) && edr60 == bool4(true) && edr30 == bool4(false)) ? float4(1.0) : float4(0.0);
float4 final36 = float4(0.0);//(edr45 == bool4(true) && edr30 == bool4(true) && edr60 == bool4(true)) ? float4(1.0) : float4(0.0);
float4 finalrn = float4(0.0);//(edr45 == bool4(false) && edrrn == bool4(true)) ? float4(1.0) : float4(0.0);
float4 px = step(lum_df(p12, p17), lum_df(p12, p13));
float4 mac = final36 * max(ma30, ma60) + final30 * ma30 + final60 * ma60 + final45 * ma45 + finalrn * marn;
float3 res1 = P12;
res1 = lerp(res1, lerp(P13, P17, px.x), mac.x);
res1 = lerp(res1, lerp(P7 , P13, px.y), mac.y);
res1 = lerp(res1, lerp(P11, P7 , px.z), mac.z);
res1 = lerp(res1, lerp(P17, P11, px.w), mac.w);
float3 res2 = P12;
res2 = lerp(res2, lerp(P17, P11, px.w), mac.w);
res2 = lerp(res2, lerp(P11, P7 , px.z), mac.z);
res2 = lerp(res2, lerp(P7 , P13, px.y), mac.y);
res2 = lerp(res2, lerp(P13, P17, px.x), mac.x);
FragColor = float4(lerp(res1, res2, step(c_df(P12, res1), c_df(P12, res2))), 1.0);
}