mirror of
https://github.com/libretro/slang-shaders.git
synced 2024-11-26 18:10:33 +00:00
Update fake-crt-geom-potato.slang (#425)
* Update fake-crt-geom-potato.slang * add retro-palettes * Add EGA filter with dithering
This commit is contained in:
parent
836bd4f634
commit
954467430c
@ -19,12 +19,13 @@ layout(push_constant) uniform Push
|
||||
#pragma parameter boost "Bright boost " 1.00 1.00 2.00 0.02
|
||||
#define boost params.boost
|
||||
|
||||
#pragma parameter SCANLINE "Scanline Intensity" 0.30 0.0 1.0 0.05
|
||||
#pragma parameter SCANLINE "Scanline Intensity" 0.70 0.0 1.0 0.05
|
||||
#define SCANLINE params.SCANLINE
|
||||
|
||||
#pragma parameter cgwg "CGWG mask brightness " 0.7 0.0 1.0 0.1
|
||||
#pragma parameter cgwg "Mask Intensity " 0.8 0.0 1.0 0.05
|
||||
#define cgwg params.cgwg
|
||||
|
||||
|
||||
#define pi 3.141592654
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
@ -36,47 +37,38 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
layout(location = 1) out float omega;
|
||||
layout(location = 1) out vec2 p;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord * 1.0001;
|
||||
omega = pi * params.SourceSize.y * 2.0;
|
||||
p = vTexCoord * params.SourceSize.xy;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 1) in float omega;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(location = 1) in vec2 p;
|
||||
|
||||
layout(set = 0, binding = 1) uniform sampler2D Source;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// CGWG mask calculation
|
||||
|
||||
vec3 Mask(float pos)
|
||||
{
|
||||
|
||||
float mf = fract(pos * 0.5);
|
||||
|
||||
if (mf <0.5) return vec3(1.0,cgwg,1.0);
|
||||
else return vec3(cgwg,1.0,cgwg);
|
||||
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 pos = vTexCoord.xy;
|
||||
|
||||
vec3 res = texture(Source, pos).rgb;
|
||||
|
||||
if (params.OriginalSize.y < 400.0)
|
||||
res = res * (1.0 + SCANLINE * sin(pos.y * omega));
|
||||
else res;
|
||||
res *=res;
|
||||
res *= SCANLINE * sin(fract(p.y)*pi) +(1.0-SCANLINE);
|
||||
|
||||
// apply the mask
|
||||
res *= Mask(pos.x*params.OutputSize.x * 1.0001);
|
||||
res *= cgwg * sin(fract(pos.x*0.5*params.OutputSize.x)*pi) +(1.0-cgwg);
|
||||
res = sqrt(res);
|
||||
res *= boost;
|
||||
|
||||
FragColor = vec4(res,1.0);
|
||||
|
4
misc/ega.slangp
Normal file
4
misc/ega.slangp
Normal file
@ -0,0 +1,4 @@
|
||||
shaders = 1
|
||||
|
||||
shader0 = shaders/ega.slang
|
||||
scale_type0 = source
|
4
misc/retro-palettes.slangp
Normal file
4
misc/retro-palettes.slangp
Normal file
@ -0,0 +1,4 @@
|
||||
shaders = 1
|
||||
|
||||
shader0 = shaders/retro-palettes.slang
|
||||
scale_type0 = source
|
132
misc/shaders/ega.slang
Normal file
132
misc/shaders/ega.slang
Normal file
@ -0,0 +1,132 @@
|
||||
#version 450
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
|
||||
} params;
|
||||
|
||||
#define _ 0.0
|
||||
#define o (1./3.)
|
||||
#define b (2./3.)
|
||||
#define B 1.0
|
||||
|
||||
#define color_enhance 1.0
|
||||
#define SourceSize params.SourceSize
|
||||
|
||||
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*1.0001;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
|
||||
// Color lookup table (RGBI palette with brown fix)
|
||||
const vec3 rgbi_palette[19] =
|
||||
{
|
||||
vec3(_, _, _),
|
||||
vec3(_, _, b),
|
||||
vec3(_, b, _),
|
||||
vec3(_, b, _),
|
||||
vec3(_, b, _),
|
||||
vec3(_, b, _),
|
||||
vec3(_, b, b),
|
||||
vec3(b, _, _),
|
||||
vec3(b, _, b),
|
||||
vec3(b, o, _),
|
||||
vec3(b, b, b),
|
||||
vec3(o, o, o),
|
||||
vec3(o, o, B),
|
||||
vec3(o, B, o),
|
||||
vec3(o, B, B),
|
||||
vec3(B, o, o),
|
||||
vec3(B, o, B),
|
||||
vec3(B, B, o),
|
||||
vec3(B, B, B),
|
||||
};
|
||||
|
||||
|
||||
// Came off the wikipedia(R) article for Ordered_Dithering
|
||||
const int dithertable[16] =
|
||||
{
|
||||
1, 9, 3,11,
|
||||
13, 5,15, 7,
|
||||
4,12, 2,10,
|
||||
16, 8,14, 6,
|
||||
};
|
||||
|
||||
|
||||
// Compare vector distances and return nearest RGBI color
|
||||
vec3 nearest_rgbi (vec3 original)
|
||||
{
|
||||
float dst;
|
||||
float min_dst = 2.0;
|
||||
int idx = 0;
|
||||
for (int i=0; i<19; i++)
|
||||
{
|
||||
dst = distance(original, rgbi_palette[i]);
|
||||
if (dst < min_dst)
|
||||
{
|
||||
min_dst = dst;
|
||||
idx = i;
|
||||
}
|
||||
}
|
||||
return rgbi_palette[idx];
|
||||
}
|
||||
|
||||
|
||||
float modu(float x, float y)
|
||||
{
|
||||
return x - y * floor(x/y);
|
||||
}
|
||||
|
||||
//fragment
|
||||
void main()
|
||||
{
|
||||
vec3 color = texture(Source, vTexCoord.xy).rgb;
|
||||
|
||||
// leilei - dither
|
||||
vec2 res;
|
||||
vec2 tex=vTexCoord.xy;
|
||||
res.x = SourceSize.x;
|
||||
|
||||
if (SourceSize.y < 900.0)
|
||||
res.y = SourceSize.y;
|
||||
else
|
||||
res.y = SourceSize.y / 2.0;
|
||||
|
||||
int ohyes;
|
||||
int i;
|
||||
vec2 ditheu = tex.xy * res.xy;
|
||||
|
||||
int ditdex = int(modu(ditheu.x, 4))*4 + int(modu(ditheu.y, 4)); // 4x4!
|
||||
|
||||
// looping through a lookup table matrix
|
||||
|
||||
for (i = ditdex; i < (ditdex+16); i = i+1)
|
||||
ohyes = dithertable[i-15] * 2 - 21;
|
||||
ohyes = ohyes - 6;
|
||||
|
||||
color *= 255.0;
|
||||
color += ohyes;
|
||||
color /= 255.0;
|
||||
FragColor = vec4(nearest_rgbi(color*color_enhance), 1.0);
|
||||
}
|
47
misc/shaders/retro-palettes.slang
Normal file
47
misc/shaders/retro-palettes.slang
Normal file
@ -0,0 +1,47 @@
|
||||
#version 450
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float pal;
|
||||
} params;
|
||||
|
||||
#pragma parameter pal "color palette colors: (1+x)^3" 1.0 1.0 15.0 1.0
|
||||
#pragma parameter something "1: ZX Spectrum, 2: Amstrad, 3: EGA, 7:Genesis, 15:Amiga" 0.0 0.0 0.0 0.0
|
||||
#define pal params.pal
|
||||
|
||||
#define SourceSize params.SourceSize
|
||||
#define OutputSize params.OutputSize
|
||||
#define OriginalSize params.OriginalSize
|
||||
|
||||
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*1.0001;
|
||||
}
|
||||
|
||||
#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 res = texture(Source,vTexCoord).rgb;
|
||||
|
||||
res= round(res*pal)/pal;
|
||||
FragColor = vec4(res,1.0);
|
||||
}
|
Loading…
Reference in New Issue
Block a user