mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-22 15:51:30 +11:00
add crt-interlaced-halation and quilez shaders and presets
This commit is contained in:
parent
973ccff893
commit
81faa39b3f
26
crt/crt-interlaced-halation.slangp
Normal file
26
crt/crt-interlaced-halation.slangp
Normal file
|
@ -0,0 +1,26 @@
|
|||
shaders = "4"
|
||||
shader0 = shaders/crt-interlaced-halation/crt-interlaced-halation-pass0.slang
|
||||
filter_linear0 = "false"
|
||||
float_framebuffer0 = "false"
|
||||
scale_type_x0 = "source"
|
||||
scale_x0 = "1.000000"
|
||||
scale_type_y0 = "source"
|
||||
scale_y0 = "1.000000"
|
||||
shader1 = shaders/crt-interlaced-halation/crt-interlaced-halation-pass1.slang
|
||||
filter_linear1 = "false"
|
||||
float_framebuffer1 = "false"
|
||||
scale_type_x1 = "source"
|
||||
scale_x1 = "1.000000"
|
||||
scale_type_y1 = "source"
|
||||
scale_y1 = "1.000000"
|
||||
shader2 = shaders/crt-interlaced-halation/crt-interlaced-halation-pass2.slang
|
||||
filter_linear2 = "false"
|
||||
float_framebuffer2 = "false"
|
||||
scale_type_x2 = "source"
|
||||
scale_x2 = "3.000000"
|
||||
scale_type_y2 = "source"
|
||||
scale_y2 = "3.000000"
|
||||
shader3 = ../stock.slang
|
||||
filter_linear3 = "true"
|
||||
float_framebuffer3 = "false"
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
CRT-interlaced-halation shader - pass0
|
||||
|
||||
Like the CRT-interlaced shader, but adds a subtle glow around bright areas
|
||||
of the screen.
|
||||
|
||||
Copyright (C) 2010-2012 cgwg, Themaister and DOLLS
|
||||
|
||||
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.
|
||||
|
||||
(cgwg gave their consent to have the original version of this shader
|
||||
distributed under the GPL in this message:
|
||||
|
||||
http://board.byuu.org/viewtopic.php?p=26075#p26075
|
||||
|
||||
"Feel free to distribute my shaders under the GPL. After all, the
|
||||
barrel distortion code was taken from the Curvature shader, which is
|
||||
under the GPL."
|
||||
)
|
||||
*/
|
||||
|
||||
#define CRTgamma 2.5
|
||||
#define display_gamma 2.2
|
||||
#define TEX2D(c) pow(texture(Source,(c)),vec4(CRTgamma))
|
||||
|
||||
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;
|
||||
|
||||
#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;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
|
||||
float dy = params.SourceSize.w;
|
||||
|
||||
t1 = vTexCoord.xyyy + vec4( 0, -4.0*dy, -3.0*dy, -2.0*dy);
|
||||
t2 = vTexCoord.xyyy + vec4( 0, -dy, 0, dy);
|
||||
t3 = vTexCoord.xyyy + vec4( 0, 2.0*dy, 3.0*dy, 4.0*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 = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
void main()
|
||||
{
|
||||
float wid = 2.0;
|
||||
|
||||
float c1 = exp(-1.0/wid/wid);
|
||||
float c2 = exp(-4.0/wid/wid);
|
||||
float c3 = exp(-9.0/wid/wid);
|
||||
float c4 = exp(-16.0/wid/wid);
|
||||
float norm = 1.0 / (1.0 + 2.0*(c1+c2+c3+c4));
|
||||
|
||||
vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
sum += TEX2D(t1.xy) * vec4(c4);
|
||||
sum += TEX2D(t1.xz) * vec4(c3);
|
||||
sum += TEX2D(t1.xw) * vec4(c2);
|
||||
sum += TEX2D(t2.xy) * vec4(c1);
|
||||
sum += TEX2D(vTexCoord);
|
||||
sum += TEX2D(t2.xw) * vec4(c1);
|
||||
sum += TEX2D(t3.xy) * vec4(c2);
|
||||
sum += TEX2D(t3.xz) * vec4(c3);
|
||||
sum += TEX2D(t3.xw) * vec4(c4);
|
||||
|
||||
FragColor = vec4(pow(sum*vec4(norm), vec4(1.0/display_gamma)));
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
CRT-interlaced-halation shader - pass1
|
||||
|
||||
Like the CRT-interlaced shader, but adds a subtle glow around bright areas
|
||||
of the screen.
|
||||
|
||||
Copyright (C) 2010-2012 cgwg, Themaister and DOLLS
|
||||
|
||||
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.
|
||||
|
||||
(cgwg gave their consent to have the original version of this shader
|
||||
distributed under the GPL in this message:
|
||||
|
||||
http://board.byuu.org/viewtopic.php?p=26075#p26075
|
||||
|
||||
"Feel free to distribute my shaders under the GPL. After all, the
|
||||
barrel distortion code was taken from the Curvature shader, which is
|
||||
under the GPL."
|
||||
)
|
||||
*/
|
||||
|
||||
#define display_gamma 2.2
|
||||
#define TEX2D(c) pow(texture(Source,(c)),vec4(display_gamma))
|
||||
|
||||
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;
|
||||
|
||||
#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;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
|
||||
float dx = params.SourceSize.z;
|
||||
|
||||
t1 = vTexCoord.xxxy + vec4( -4.0*dx, -3.0*dx, -2.0*dx, 0);
|
||||
t2 = vTexCoord.xxxy + vec4( -dx, 0, dx, 0);
|
||||
t3 = vTexCoord.xxxy + vec4( 2.0*dx, 3.0*dx, 4.0*dx, 0);
|
||||
}
|
||||
|
||||
#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 = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
void main()
|
||||
{
|
||||
float wid = 2.0;
|
||||
|
||||
float c1 = exp(-1.0/wid/wid);
|
||||
float c2 = exp(-4.0/wid/wid);
|
||||
float c3 = exp(-9.0/wid/wid);
|
||||
float c4 = exp(-16.0/wid/wid);
|
||||
float norm = 1.0 / (1.0 + 2.0*(c1+c2+c3+c4));
|
||||
|
||||
vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
sum += TEX2D(t1.xw) * vec4(c4);
|
||||
sum += TEX2D(t1.yw) * vec4(c3);
|
||||
sum += TEX2D(t1.zw) * vec4(c2);
|
||||
sum += TEX2D(t2.xw) * vec4(c1);
|
||||
sum += TEX2D(vTexCoord);
|
||||
sum += TEX2D(t2.zw) * vec4(c1);
|
||||
sum += TEX2D(t3.xw) * vec4(c2);
|
||||
sum += TEX2D(t3.yw) * vec4(c3);
|
||||
sum += TEX2D(t3.zw) * vec4(c4);
|
||||
|
||||
FragColor = vec4(pow(sum*vec4(norm), vec4(1.0/display_gamma)));
|
||||
}
|
|
@ -0,0 +1,362 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
CRT-interlaced-halation shader - pass2
|
||||
|
||||
Like the CRT-interlaced shader, but adds a subtle glow around bright areas
|
||||
of the screen.
|
||||
|
||||
Copyright (C) 2010-2012 cgwg, Themaister and DOLLS
|
||||
|
||||
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.
|
||||
|
||||
(cgwg gave their consent to have the original version of this shader
|
||||
distributed under the GPL in this message:
|
||||
|
||||
http://board.byuu.org/viewtopic.php?p=26075#p26075
|
||||
|
||||
"Feel free to distribute my shaders under the GPL. After all, the
|
||||
barrel distortion code was taken from the Curvature shader, which is
|
||||
under the GPL."
|
||||
)
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
// Comment the next line to disable interpolation in linear gamma (and
|
||||
// gain speed).
|
||||
#define LINEAR_PROCESSING
|
||||
|
||||
// Enable screen curvature.
|
||||
#define CURVATURE
|
||||
|
||||
// Enable 3x oversampling of the beam profile
|
||||
//#define OVERSAMPLE
|
||||
|
||||
// Use the older, purely gaussian beam profile
|
||||
#define USEGAUSSIAN
|
||||
|
||||
// Use interlacing detection; may interfere with other shaders if combined
|
||||
#define INTERLACED
|
||||
|
||||
// Enable Dot-mask emulation:
|
||||
// Output pixels are alternately tinted green and magenta.
|
||||
//#define DOTMASK
|
||||
|
||||
//Enable if using several shaders.
|
||||
//Disabling it reduces moire for single pass.
|
||||
#define MULTIPASS
|
||||
|
||||
// Macros.
|
||||
#define FIX(c) max(abs(c), 1e-5);
|
||||
#define PI 3.141592653589
|
||||
|
||||
#ifdef LINEAR_PROCESSING
|
||||
# define TEX2D(c) pow(texture(Original, (c)), vec4(CRTgamma))
|
||||
#else
|
||||
# define TEX2D(c) texture(Original, (c))
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// START of parameters
|
||||
|
||||
// gamma of simulated CRT
|
||||
float CRTgamma = 2.4;
|
||||
// gamma of display monitor (typically 2.2 is correct)
|
||||
float monitorgamma = 2.2;
|
||||
// overscan (e.g. 1.02 for 2% overscan)
|
||||
vec2 overscan = vec2(1.0,1.0);
|
||||
// aspect ratio
|
||||
vec2 aspect = vec2(1.0, 0.75);
|
||||
// lengths are measured in units of (approximately) the width
|
||||
// of the monitor simulated distance from viewer to monitor
|
||||
float d = 2.0;
|
||||
// radius of curvature
|
||||
float R = 2.0;
|
||||
// tilt angle in radians
|
||||
// (behavior might be a bit wrong if both components are
|
||||
// nonzero)
|
||||
const vec2 angle = vec2(0.0,0.0);
|
||||
// size of curved corners
|
||||
float cornersize = 0.01;
|
||||
// border smoothness parameter
|
||||
// decrease if borders are too aliased
|
||||
float cornersmooth = 800.0;
|
||||
|
||||
// END of parameters
|
||||
|
||||
|
||||
float intersect(vec2 xy, vec2 sinangle, vec2 cosangle)
|
||||
{
|
||||
float A = dot(xy,xy)+d*d;
|
||||
float B = 2.0*(R*(dot(xy,sinangle)-d*cosangle.x*cosangle.y)-d*d);
|
||||
float C = d*d + 2.0*R*d*cosangle.x*cosangle.y;
|
||||
return (-B-sqrt(B*B-4.0*A*C))/(2.0*A);
|
||||
}
|
||||
|
||||
vec2 bkwtrans(vec2 xy, vec2 sinangle, vec2 cosangle)
|
||||
{
|
||||
float c = intersect(xy, sinangle, cosangle);
|
||||
vec2 point = vec2(c)*xy;
|
||||
point -= vec2(-R)*sinangle;
|
||||
point /= vec2(R);
|
||||
vec2 tang = sinangle/cosangle;
|
||||
vec2 poc = point/cosangle;
|
||||
float A = dot(tang,tang)+1.0;
|
||||
float B = -2.0*dot(poc,tang);
|
||||
float C = dot(poc,poc)-1.0;
|
||||
float a = (-B+sqrt(B*B-4.0*A*C))/(2.0*A);
|
||||
vec2 uv = (point-a*sinangle)/cosangle;
|
||||
float r = FIX(R*acos(a));
|
||||
return uv*r/sin(r/R);
|
||||
}
|
||||
|
||||
vec2 fwtrans(vec2 uv, vec2 sinangle, vec2 cosangle)
|
||||
{
|
||||
float r = FIX(sqrt(dot(uv,uv)));
|
||||
uv *= sin(r/R)/r;
|
||||
float x = 1.0-cos(r/R);
|
||||
float D = d/R + x*cosangle.x*cosangle.y+dot(uv,sinangle);
|
||||
return d*(uv*cosangle-x*sinangle)/D;
|
||||
}
|
||||
|
||||
vec3 maxscale(vec2 sinangle, vec2 cosangle)
|
||||
{
|
||||
vec2 c = bkwtrans(-R * sinangle / (1.0 + R/d*cosangle.x*cosangle.y), sinangle, cosangle);
|
||||
vec2 a = vec2(0.5,0.5)*aspect;
|
||||
vec2 lo = vec2(fwtrans(vec2(-a.x,c.y), sinangle, cosangle).x,
|
||||
fwtrans(vec2(c.x,-a.y), sinangle, cosangle).y)/aspect;
|
||||
vec2 hi = vec2(fwtrans(vec2(+a.x,c.y), sinangle, cosangle).x,
|
||||
fwtrans(vec2(c.x,+a.y), sinangle, cosangle).y)/aspect;
|
||||
return vec3((hi+lo)*aspect*0.5,max(hi.x-lo.x,hi.y-lo.y));
|
||||
}
|
||||
|
||||
// Calculate the influence of a scanline on the current pixel.
|
||||
//
|
||||
// 'distance' is the distance in texture coordinates from the current
|
||||
// pixel to the scanline in question.
|
||||
// 'color' is the colour of the scanline at the horizontal location of
|
||||
// the current pixel.
|
||||
vec4 scanlineWeights(float distance, vec4 color)
|
||||
{
|
||||
// "wid" controls the width of the scanline beam, for each RGB
|
||||
// channel The "weights" lines basically specify the formula
|
||||
// that gives you the profile of the beam, i.e. the intensity as
|
||||
// a function of distance from the vertical center of the
|
||||
// scanline. In this case, it is gaussian if width=2, and
|
||||
// becomes nongaussian for larger widths. Ideally this should
|
||||
// be normalized so that the integral across the beam is
|
||||
// independent of its width. That is, for a narrower beam
|
||||
// "weights" should have a higher peak at the center of the
|
||||
// scanline than for a wider beam.
|
||||
#ifdef USEGAUSSIAN
|
||||
vec4 wid = 0.3 + 0.1 * pow(color, vec4(3.0));
|
||||
vec4 weights = vec4(distance / wid);
|
||||
return 0.4 * exp(-weights * weights) / wid;
|
||||
#else
|
||||
vec4 wid = 2.0 + 2.0 * pow(color, vec4(4.0));
|
||||
vec4 weights = vec4(distance / 0.3);
|
||||
return 1.4 * exp(-pow(weights * rsqrt(0.5 * wid), wid)) / (0.6 + 0.2 * wid);
|
||||
#endif
|
||||
}
|
||||
|
||||
#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 vec2 one;
|
||||
layout(location = 2) out float mod_factor;
|
||||
layout(location = 3) out vec2 ilfac;
|
||||
layout(location = 4) out vec3 stretch;
|
||||
layout(location = 5) out vec2 sinangle;
|
||||
layout(location = 6) out vec2 cosangle;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
|
||||
// Precalculate a bunch of useful values we'll need in the fragment
|
||||
// shader.
|
||||
sinangle = sin(angle);
|
||||
cosangle = cos(angle);
|
||||
stretch = maxscale(sinangle, cosangle);
|
||||
|
||||
#ifdef INTERLACED
|
||||
ilfac = vec2(1.0,clamp(floor(params.SourceSize.y/200.0),1.0,2.0));
|
||||
#else
|
||||
ilfac = vec2(1.0,clamp(floor(params.SourceSize.y/1000.0),1.0,2.0));
|
||||
#endif
|
||||
|
||||
// The size of one texel, in texture-coordinates.
|
||||
one = ilfac / params.OriginalSize.xy;
|
||||
|
||||
// Resulting X pixel-coordinate of the pixel we're drawing.
|
||||
mod_factor = vTexCoord.x * params.OriginalSize.x * params.OutputSize.x / params.OriginalSize.x;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 1) in vec2 one;
|
||||
layout(location = 2) in float mod_factor;
|
||||
layout(location = 3) in vec2 ilfac;
|
||||
layout(location = 4) in vec3 stretch;
|
||||
layout(location = 5) in vec2 sinangle;
|
||||
layout(location = 6) in vec2 cosangle;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
layout(set = 0, binding = 3) uniform sampler2D Original;
|
||||
|
||||
#define mul(a, b) (b * a)
|
||||
|
||||
void main()
|
||||
{
|
||||
// Here's a helpful diagram to keep in mind while trying to
|
||||
// understand the code:
|
||||
//
|
||||
// | | | | |
|
||||
// -------------------------------
|
||||
// | | | | |
|
||||
// | 01 | 11 | 21 | 31 | <-- current scanline
|
||||
// | | @ | | |
|
||||
// -------------------------------
|
||||
// | | | | |
|
||||
// | 02 | 12 | 22 | 32 | <-- next scanline
|
||||
// | | | | |
|
||||
// -------------------------------
|
||||
// | | | | |
|
||||
//
|
||||
// Each character-cell represents a pixel on the output
|
||||
// surface, "@" represents the current pixel (always somewhere
|
||||
// in the bottom half of the current scan-line, or the top-half
|
||||
// of the next scanline). The grid of lines represents the
|
||||
// edges of the texels of the underlying texture.
|
||||
|
||||
// Texture coordinates of the texel containing the active pixel.
|
||||
#ifdef CURVATURE
|
||||
vec2 cd = vTexCoord;
|
||||
//cd *= ORIG.texture_size / ORIG.video_size;
|
||||
cd = (cd-vec2(0.5))*aspect*stretch.z+stretch.xy;
|
||||
vec2 xy = (bkwtrans(cd, sinangle, cosangle)/overscan/aspect+vec2(0.5));// * ORIG.video_size / ORIG.texture_size;
|
||||
|
||||
#else
|
||||
vec2 xy = texCoord;
|
||||
#endif
|
||||
vec2 cd2 = xy;
|
||||
//cd2 *= ORIG.texture_size / ORIG.video_size;
|
||||
cd2 = (cd2 - vec2(0.5)) * overscan + vec2(0.5);
|
||||
cd2 = min(cd2, vec2(1.0)-cd2) * aspect;
|
||||
vec2 cdist = vec2(cornersize);
|
||||
cd2 = (cdist - min(cd2,cdist));
|
||||
float dist = sqrt(dot(cd2,cd2));
|
||||
float cval = clamp((cdist.x-dist)*cornersmooth,0.0, 1.0);
|
||||
|
||||
vec2 xy2 = ((xy-vec2(0.5))*vec2(1.0,1.0)+vec2(0.5));//*IN.video_size/IN.texture_size;
|
||||
// Of all the pixels that are mapped onto the texel we are
|
||||
// currently rendering, which pixel are we currently rendering?
|
||||
vec2 ilfloat = vec2(0.0,ilfac.y > 1.5 ? mod(vec2(params.FrameCount,params.FrameCount).x,2.0) : 0.0);
|
||||
|
||||
vec2 ratio_scale = (xy * params.SourceSize.xy - vec2(0.5) + ilfloat)/ilfac;
|
||||
|
||||
#ifdef OVERSAMPLE
|
||||
//float filter = fwidth(ratio_scale.y);
|
||||
float filter = params.SourceSize.y / params.OutputSize.y;
|
||||
#endif
|
||||
vec2 uv_ratio = fract(ratio_scale);
|
||||
|
||||
// Snap to the center of the underlying texel.
|
||||
xy = (floor(ratio_scale)*ilfac + vec2(0.5) - ilfloat) / params.SourceSize.xy;
|
||||
|
||||
// Calculate Lanczos scaling coefficients describing the effect
|
||||
// of various neighbour texels in a scanline on the current
|
||||
// pixel.
|
||||
vec4 coeffs = PI * vec4(1.0 + uv_ratio.x, uv_ratio.x, 1.0 - uv_ratio.x, 2.0 - uv_ratio.x);
|
||||
|
||||
// Prevent division by zero.
|
||||
coeffs = FIX(coeffs);
|
||||
|
||||
// Lanczos2 kernel.
|
||||
coeffs = 2.0 * sin(coeffs) * sin(coeffs / 2.0) / (coeffs * coeffs);
|
||||
|
||||
// Normalize.
|
||||
coeffs /= dot(coeffs, vec4(1.0));
|
||||
|
||||
// Calculate the effective colour of the current and next
|
||||
// scanlines at the horizontal location of the current pixel,
|
||||
// using the Lanczos coefficients above.
|
||||
vec4 col = clamp(mul(coeffs, mat4x4(
|
||||
TEX2D(xy + vec2(-one.x, 0.0)),
|
||||
TEX2D(xy),
|
||||
TEX2D(xy + vec2(one.x, 0.0)),
|
||||
TEX2D(xy + vec2(2.0 * one.x, 0.0)))),
|
||||
0.0, 1.0);
|
||||
vec4 col2 = clamp(mul(coeffs, mat4x4(
|
||||
TEX2D(xy + vec2(-one.x, one.y)),
|
||||
TEX2D(xy + vec2(0.0, one.y)),
|
||||
TEX2D(xy + one),
|
||||
TEX2D(xy + vec2(2.0 * one.x, one.y)))),
|
||||
0.0, 1.0);
|
||||
|
||||
|
||||
#ifndef LINEAR_PROCESSING
|
||||
col = pow(col , vec4(CRTgamma));
|
||||
col2 = pow(col2, vec4(CRTgamma));
|
||||
#endif
|
||||
|
||||
// Calculate the influence of the current and next scanlines on
|
||||
// the current pixel.
|
||||
vec4 weights = scanlineWeights(uv_ratio.y, col);
|
||||
vec4 weights2 = scanlineWeights(1.0 - uv_ratio.y, col2);
|
||||
#ifdef OVERSAMPLE
|
||||
uv_ratio.y =uv_ratio.y+1.0/3.0*filter;
|
||||
weights = (weights+scanlineWeights(uv_ratio.y, col))/3.0;
|
||||
weights2=(weights2+scanlineWeights(abs(1.0-uv_ratio.y), col2))/3.0;
|
||||
uv_ratio.y =uv_ratio.y-2.0/3.0*filter;
|
||||
weights=weights+scanlineWeights(abs(uv_ratio.y), col)/3.0;
|
||||
weights2=weights2+scanlineWeights(abs(1.0-uv_ratio.y), col2)/3.0;
|
||||
#endif
|
||||
vec3 mul_res = (col * weights + col2 * weights2).rgb;
|
||||
#ifdef MULTIPASS
|
||||
mul_res += pow(texture(Source, xy2).rgb, vec3(monitorgamma))*0.1;
|
||||
#endif
|
||||
mul_res *= vec3(cval);
|
||||
|
||||
// dot-mask emulation:
|
||||
// Output pixels are alternately tinted green and magenta.
|
||||
#ifdef DOTMASK
|
||||
vec3 dotMaskWeights = mix(
|
||||
vec3(1.0, 0.7, 1.0),
|
||||
vec3(0.7, 1.0, 0.7),
|
||||
floor(mod(mod_factor, 2.0))
|
||||
);
|
||||
#else
|
||||
vec3 dotMaskWeights = mix(
|
||||
vec3(1.0, 1.0, 1.0),
|
||||
vec3(1.0, 1.0, 1.0),
|
||||
floor(mod(mod_factor, 2.0)));
|
||||
#endif
|
||||
|
||||
|
||||
mul_res *= dotMaskWeights;
|
||||
|
||||
// Convert the image gamma for display on our output device.
|
||||
mul_res = pow(mul_res, vec3(1.0 / monitorgamma));
|
||||
|
||||
// Color the texel.
|
||||
FragColor = vec4(mul_res, 1.0);
|
||||
}
|
4
retro/quilez.slangp
Normal file
4
retro/quilez.slangp
Normal file
|
@ -0,0 +1,4 @@
|
|||
shaders = 1
|
||||
|
||||
shader0 = shaders/quilez.slang
|
||||
filter_linear0 = true
|
53
retro/shaders/quilez.slang
Normal file
53
retro/shaders/quilez.slang
Normal file
|
@ -0,0 +1,53 @@
|
|||
#version 450
|
||||
|
||||
/*
|
||||
Fragment shader based on "Improved texture interpolation" by Iñigo Quílez
|
||||
Original description: http://www.iquilezles.org/www/articles/texture/texture.htm
|
||||
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
#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()
|
||||
{
|
||||
vec2 p = vTexCoord.xy;
|
||||
|
||||
p = p * params.SourceSize.xy + vec2(0.5, 0.5);
|
||||
|
||||
vec2 i = floor(p);
|
||||
vec2 f = p - i;
|
||||
f = f * f * f * (f * (f * 6.0 - vec2(15.0, 15.0)) + vec2(10.0, 10.0));
|
||||
p = i + f;
|
||||
|
||||
p = (p - vec2(0.5, 0.5)) * params.SourceSize.zw;
|
||||
|
||||
// final sum and weight normalization
|
||||
FragColor = vec4(texture(Source, p));
|
||||
}
|
Loading…
Reference in a new issue