diff --git a/eagle/shaders/supereagle.slang b/eagle/shaders/supereagle.slang new file mode 100644 index 0000000..e00d3fb --- /dev/null +++ b/eagle/shaders/supereagle.slang @@ -0,0 +1,183 @@ +#version 450 + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; + vec4 OutputSize; + vec4 OriginalSize; + vec4 SourceSize; +} global; + +vec3 dtt = vec3(65536.0,255.0,1.0); + +float reduce(vec3 color) +{ + return dot(color, dtt); +} + +#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 vec4 t2; +layout(location = 3) out vec4 t3; +layout(location = 4) out vec4 t4; +layout(location = 5) out vec4 t5; +layout(location = 6) out vec4 t6; +layout(location = 7) out vec4 t7; +layout(location = 8) out vec4 t8; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; + + float dx = global.SourceSize.z; + float dy = global.SourceSize.w; + t1.xy = vTexCoord + vec2(-dx,-dy); + t1.zw = vTexCoord + vec2(-dx, 0); + t2.xy = vTexCoord + vec2(+dx,-dy); + t2.zw = vTexCoord + vec2(+dx+dx,-dy); + t3.xy = vTexCoord + vec2(-dx, 0); + t3.zw = vTexCoord + vec2(+dx, 0); + t4.xy = vTexCoord + vec2(+dx+dx, 0); + t4.zw = vTexCoord + vec2(-dx,+dy); + t5.xy = vTexCoord + vec2( 0,+dy); + t5.zw = vTexCoord + vec2(+dx,+dy); + t6.xy = vTexCoord + vec2(+dx+dx,+dy); + t6.zw = vTexCoord + vec2(-dx,+dy+dy); + t7.xy = vTexCoord + vec2( 0,+dy+dy); + t7.zw = vTexCoord + vec2(+dx,+dy+dy); + t8.xy = vTexCoord + vec2(+dx+dx,+dy+dy); +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 1) in vec4 t1; +layout(location = 2) in vec4 t2; +layout(location = 3) in vec4 t3; +layout(location = 4) in vec4 t4; +layout(location = 5) in vec4 t5; +layout(location = 6) in vec4 t6; +layout(location = 7) in vec4 t7; +layout(location = 8) in vec4 t8; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + +/* GET_RESULT function */ +/* Copyright (c) 1999-2001 by Derek Liauw Kie Fa */ +/* License: GNU-GPL */ + +int GET_RESULT(float A, float B, float C, float D) +{ + int x = 0; int y = 0; int r = 0; + if (A == C) x+=1; else if (B == C) y+=1; + if (A == D) x+=1; else if (B == D) y+=1; + if (x <= 1) r+=1; + if (y <= 1) r-=1; + return r; +} + +void main() +{ + vec2 fp = fract(vTexCoord * global.SourceSize.xy); + + // Reading the texels + + vec3 C0 = texture(Source, t1.xy).xyz; + vec3 C1 = texture(Source, t1.zw).xyz; + vec3 C2 = texture(Source, t2.xy).xyz; + vec3 D3 = texture(Source, t2.zw).xyz; + vec3 C3 = texture(Source, t3.xy).xyz; + vec3 C4 = texture(Source, vTexCoord).xyz; + vec3 C5 = texture(Source, t3.zw).xyz; + vec3 D4 = texture(Source, t4.xy).xyz; + vec3 C6 = texture(Source, t4.zw).xyz; + vec3 C7 = texture(Source, t5.xy).xyz; + vec3 C8 = texture(Source, t5.zw).xyz; + vec3 D5 = texture(Source, t6.xy).xyz; + vec3 D0 = texture(Source, t6.zw).xyz; + vec3 D1 = texture(Source, t7.xy).xyz; + vec3 D2 = texture(Source, t7.zw).xyz; + vec3 D6 = texture(Source, t8.xy).xyz; + + vec3 p00,p10,p01,p11; + + // reducing vec3 to float + float c0 = reduce(C0);float c1 = reduce(C1); + float c2 = reduce(C2);float c3 = reduce(C3); + float c4 = reduce(C4);float c5 = reduce(C5); + float c6 = reduce(C6);float c7 = reduce(C7); + float c8 = reduce(C8);float d0 = reduce(D0); + float d1 = reduce(D1);float d2 = reduce(D2); + float d3 = reduce(D3);float d4 = reduce(D4); + float d5 = reduce(D5);float d6 = reduce(D6); + +/* SuperEagle code */ +/* Copied from the Dosbox source code */ +/* Copyright (C) 2002-2007 The DOSBox Team */ +/* License: GNU-GPL */ +/* Adapted by guest(r) on 16.4.2007 */ + + if (c4 != c8) { + if (c7 == c5) { + p01 = p10 = C7; + if ((c6 == c7) || (c5 == c2)) { + p00 = 0.25*(3.0*C7+C4); + } else { + p00 = 0.5*(C4+C5); + } + + if ((c5 == d4) || (c7 == d1)) { + p11 = 0.25*(3.0*C7+C8); + } else { + p11 = 0.5*(C7+C8); + } + } else { + p11 = 0.125*(6.0*C8+C7+C5); + p00 = 0.125*(6.0*C4+C7+C5); + + p10 = 0.125*(6.0*C7+C4+C8); + p01 = 0.125*(6.0*C5+C4+C8); + } + } else { + if (c7 != c5) { + p11 = p00 = C4; + + if ((c1 == c4) || (c8 == d5)) { + p01 = 0.25*(3.0*C4+C5); + } else { + p01 = 0.5*(C4+C5); + } + + if ((c8 == d2) || (c3 == c4)) { + p10 = 0.25*(3.0*C4+C7); + } else { + p10 = 0.5*(C7+C8); + } + } else { + int r = 0; + r += GET_RESULT(c5,c4,c6,d1); + r += GET_RESULT(c5,c4,c3,c1); + r += GET_RESULT(c5,c4,d2,d5); + r += GET_RESULT(c5,c4,c2,d4); + + if (r > 0) { + p01 = p10 = C7; + p00 = p11 = 0.5*(C4+C5); + } else if (r < 0) { + p11 = p00 = C4; + p01 = p10 = 0.5*(C4+C5); + } else { + p11 = p00 = C4; + p01 = p10 = C7; + } + } + } + +// Distributing the four products + p10 = (fp.x < 0.50) ? (fp.y < 0.50 ? p00 : p10) : (fp.y < 0.50 ? p01: p11); + + FragColor = vec4(p10, 1.0); +} \ No newline at end of file diff --git a/eagle/supereagle.slangp b/eagle/supereagle.slangp new file mode 100644 index 0000000..2e14b81 --- /dev/null +++ b/eagle/supereagle.slangp @@ -0,0 +1,5 @@ +shaders = 1 + +shader0 = "shaders/supereagle.slang" +filter_linear0 = false +scale_type_0 = source diff --git a/scalehq/2xScaleHQ.slangp b/scalehq/2xScaleHQ.slangp new file mode 100644 index 0000000..8fc8793 --- /dev/null +++ b/scalehq/2xScaleHQ.slangp @@ -0,0 +1,5 @@ +shaders = 1 + +shader0 = "shaders/2xScaleHQ.slang" +filter_linear0 = false +scale_type_0 = source diff --git a/scalehq/4xScaleHQ.slangp b/scalehq/4xScaleHQ.slangp new file mode 100644 index 0000000..9d16458 --- /dev/null +++ b/scalehq/4xScaleHQ.slangp @@ -0,0 +1,5 @@ +shaders = 1 + +shader0 = "shaders/4xScaleHQ.slang" +filter_linear0 = false +scale_type_0 = source diff --git a/scalehq/shaders/2xScaleHQ.slang b/scalehq/shaders/2xScaleHQ.slang new file mode 100644 index 0000000..2944b4b --- /dev/null +++ b/scalehq/shaders/2xScaleHQ.slang @@ -0,0 +1,87 @@ +#version 450 + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; + vec4 OutputSize; + vec4 OriginalSize; + vec4 SourceSize; +} global; + +vec3 dt = vec3(1.0); + +#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 vec4 t2; +layout(location = 3) out vec4 t3; +layout(location = 4) out vec4 t4; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; + float x = 0.5 * global.SourceSize.z; + float y = 0.5 * global.SourceSize.w; + vec2 dg1 = vec2( x, y); + vec2 dg2 = vec2(-x, y); + vec2 dx = vec2(x, 0.0); + vec2 dy = vec2(0.0, y); + t1 = vec4(vTexCoord - dg1, vTexCoord - dy); + t2 = vec4(vTexCoord - dg2, vTexCoord + dx); + t3 = vec4(vTexCoord + dg1, vTexCoord + dy); + t4 = vec4(vTexCoord + dg2, vTexCoord - dx); +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 1) in vec4 t1; +layout(location = 2) in vec4 t2; +layout(location = 3) in vec4 t3; +layout(location = 4) in vec4 t4; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + +float mx = 0.325; // start smoothing wt. +float k = -0.250; // wt. decrease factor +float max_w = 0.25; // max filter weigth +float min_w =-0.05; // min filter weigth +float lum_add = 0.25; // affects smoothing + +void main() +{ + vec3 c00 = texture(Source, t1.xy).xyz; + vec3 c10 = texture(Source, t1.zw).xyz; + vec3 c20 = texture(Source, t2.xy).xyz; + vec3 c01 = texture(Source, t4.zw).xyz; + vec3 c11 = texture(Source, vTexCoord).xyz; + vec3 c21 = texture(Source, t2.zw).xyz; + vec3 c02 = texture(Source, t4.xy).xyz; + vec3 c12 = texture(Source, t3.zw).xyz; + vec3 c22 = texture(Source, t3.xy).xyz; + + float md1 = dot(abs(c00 - c22), dt); + float md2 = dot(abs(c02 - c20), dt); + + float w1 = dot(abs(c22 - c11), dt) * md2; + float w2 = dot(abs(c02 - c11), dt) * md1; + float w3 = dot(abs(c00 - c11), dt) * md2; + float w4 = dot(abs(c20 - c11), dt) * md1; + + float t1 = w1 + w3; + float t2 = w2 + w4; + float ww = max(t1, t2) + 0.0001; + + c11 = (w1 * c00 + w2 * c20 + w3 * c22 + w4 * c02 + ww * c11) / (t1 + t2 + ww); + + float lc1 = k / (0.12 * dot(c10 + c12 + c11, dt) + lum_add); + float lc2 = k / (0.12 * dot(c01 + c21 + c11, dt) + lum_add); + + w1 = clamp(lc1 * dot(abs(c11 - c10), dt) + mx, min_w, max_w); + w2 = clamp(lc2 * dot(abs(c11 - c21), dt) + mx, min_w, max_w); + w3 = clamp(lc1 * dot(abs(c11 - c12), dt) + mx, min_w, max_w); + w4 = clamp(lc2 * dot(abs(c11 - c01), dt) + mx, min_w, max_w); + FragColor = vec4(w1 * c10 + w2 * c21 + w3 * c12 + w4 * c01 + (1.0 - w1 - w2 - w3 - w4) * c11, 1.0); +} \ No newline at end of file diff --git a/scalehq/shaders/4xScaleHQ.slang b/scalehq/shaders/4xScaleHQ.slang new file mode 100644 index 0000000..6f234a7 --- /dev/null +++ b/scalehq/shaders/4xScaleHQ.slang @@ -0,0 +1,122 @@ +#version 450 + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; + vec4 OutputSize; + vec4 OriginalSize; + vec4 SourceSize; +} global; + +/* + 4xGLSLHqFilter shader + + Copyright (C) 2005 guest(r) - guest.r@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. +*/ + +vec3 dt = vec3(1.0); + +#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 vec4 t2; +layout(location = 3) out vec4 t3; +layout(location = 4) out vec4 t4; +layout(location = 5) out vec4 t5; +layout(location = 6) out vec4 t6; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; + float x = 0.5 * global.SourceSize.z; + float y = 0.5 * global.SourceSize.w; + vec2 dg1 = vec2( x, y); + vec2 dg2 = vec2(-x, y); + vec2 sd1 = dg1 * 0.5; + vec2 sd2 = dg2 * 0.5; + vec2 ddx = vec2(x, 0.0); + vec2 ddy = vec2(0.0, y); + t1 = vec4(vTexCoord - sd1, vTexCoord - ddy); + t2 = vec4(vTexCoord - sd2, vTexCoord + ddx); + t3 = vec4(vTexCoord + sd1, vTexCoord + ddy); + t4 = vec4(vTexCoord + sd2, vTexCoord - ddx); + t5 = vec4(vTexCoord - dg1, vTexCoord - dg2); + t6 = vec4(vTexCoord + dg1, vTexCoord + dg2); +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 1) in vec4 t1; +layout(location = 2) in vec4 t2; +layout(location = 3) in vec4 t3; +layout(location = 4) in vec4 t4; +layout(location = 5) in vec4 t5; +layout(location = 6) in vec4 t6; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + +float mx = 1.0; // start smoothing wt. +float k = -1.10; // wt. decrease factor +float max_w = 0.75; // max filter weigth +float min_w = 0.03; // min filter weigth +float lum_add = 0.33; // affects smoothing + +void main() +{ + vec3 c = texture(Source, vTexCoord).xyz; + vec3 i1 = texture(Source, t1.xy).xyz; + vec3 i2 = texture(Source, t2.xy).xyz; + vec3 i3 = texture(Source, t3.xy).xyz; + vec3 i4 = texture(Source, t4.xy).xyz; + vec3 o1 = texture(Source, t5.xy).xyz; + vec3 o3 = texture(Source, t6.xy).xyz; + vec3 o2 = texture(Source, t5.zw).xyz; + vec3 o4 = texture(Source, t6.zw).xyz; + vec3 s1 = texture(Source, t1.zw).xyz; + vec3 s2 = texture(Source, t2.zw).xyz; + vec3 s3 = texture(Source, t3.zw).xyz; + vec3 s4 = texture(Source, t4.zw).xyz; + + float ko1=dot(abs(o1-c),dt); + float ko2=dot(abs(o2-c),dt); + float ko3=dot(abs(o3-c),dt); + float ko4=dot(abs(o4-c),dt); + + float k1=min(dot(abs(i1-i3),dt),max(ko1,ko3)); + float k2=min(dot(abs(i2-i4),dt),max(ko2,ko4)); + + float w1 = k2; if(ko3