mirror of
https://github.com/libretro/slang-shaders.git
synced 2025-03-01 14:27:39 +00:00
update still-broken crt-geom
This commit is contained in:
parent
fb4f5d002b
commit
f14ba96715
@ -12,7 +12,7 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
||||
#define CRTgamma 2.4
|
||||
#define monitorgamma 2.2
|
||||
#define d 1.5
|
||||
#define CURVATURE 1.0
|
||||
//#define CURVATURE 1.0
|
||||
#define R 2.0
|
||||
#define cornersize 0.03
|
||||
#define cornersmooth 1000.0
|
||||
@ -54,14 +54,10 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
||||
#define OVERSAMPLE
|
||||
|
||||
// Use the older, purely gaussian beam profile; uncomment for speed
|
||||
//#define USEGAUSSIAN
|
||||
#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
|
||||
|
||||
// Macros.
|
||||
#define FIX(c) max(abs(c), 1e-5);
|
||||
@ -74,9 +70,22 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
||||
#endif
|
||||
|
||||
// aspect ratio
|
||||
static vec2 aspect = vec2(1.0, 0.75);
|
||||
vec2 aspect = vec2(1.0, 0.75);
|
||||
vec2 angle = vec2(0.0, 0.0);
|
||||
vec2 overscan = vec2(1.01, 1.01);
|
||||
|
||||
float intersect(vec2 xy, vec2 sinangle, vec2 cosangle)
|
||||
#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 sinangle;
|
||||
layout(location = 2) out vec2 cosangle;
|
||||
layout(location = 3) out vec3 stretch;
|
||||
layout(location = 4) out vec2 ilfac;
|
||||
layout(location = 5) out vec2 one;
|
||||
layout(location = 6) out float mod_factor;
|
||||
|
||||
float intersect(vec2 xy)
|
||||
{
|
||||
float A = dot(xy,xy)+d*d;
|
||||
float B = 2.0*(R*(dot(xy,sinangle)-d*cosangle.x*cosangle.y)-d*d);
|
||||
@ -84,10 +93,10 @@ float intersect(vec2 xy, vec2 sinangle, vec2 cosangle)
|
||||
return (-B-sqrt(B*B-4.0*A*C))/(2.0*A);
|
||||
}
|
||||
|
||||
loat2 bkwtrans(vec2 xy, vec2 sinangle, vec2 cosangle)
|
||||
vec2 bkwtrans(vec2 xy)
|
||||
{
|
||||
float c = intersect(xy, sinangle, cosangle);
|
||||
float2 point = vec2(c)*xy;
|
||||
float c = intersect(xy);
|
||||
vec2 point = vec2(c)*xy;
|
||||
point -= vec2(-R)*sinangle;
|
||||
point /= vec2(R);
|
||||
vec2 tang = sinangle/cosangle;
|
||||
@ -97,11 +106,11 @@ loat2 bkwtrans(vec2 xy, vec2 sinangle, vec2 cosangle)
|
||||
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));
|
||||
float r = R*acos(a);
|
||||
return uv*r/sin(r/R);
|
||||
}
|
||||
|
||||
vec2 fwtrans(vec2 uv, vec2 sinangle, vec2 cosangle)
|
||||
vec2 fwtrans(vec2 uv)
|
||||
{
|
||||
float r = FIX(sqrt(dot(uv,uv)));
|
||||
uv *= sin(r/R)/r;
|
||||
@ -110,15 +119,15 @@ vec2 fwtrans(vec2 uv, vec2 sinangle, vec2 cosangle)
|
||||
return d*(uv*cosangle-x*sinangle)/D;
|
||||
}
|
||||
|
||||
vec3 maxscale(vec2 sinangle, float2 cosangle)
|
||||
vec3 maxscale()
|
||||
{
|
||||
vec2 c = bkwtrans(-R * sinangle / (1.0 + R/d*cosangle.x*cosangle.y), sinangle, cosangle);
|
||||
vec2 c = bkwtrans(-R * sinangle / (1.0 + R/d*cosangle.x*cosangle.y));
|
||||
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 vec2((hi+lo)*aspect*0.5,max(hi.x-lo.x,hi.y-lo.y));
|
||||
vec2 lo = vec2(fwtrans(vec2(-a.x,c.y)).x,
|
||||
fwtrans(vec2(c.x,-a.y)).y)/aspect;
|
||||
vec2 hi = vec2(fwtrans(vec2(+a.x,c.y)).x,
|
||||
fwtrans(vec2(c.x,+a.y)).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.
|
||||
@ -127,7 +136,7 @@ vec3 maxscale(vec2 sinangle, float2 cosangle)
|
||||
// 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, float4 color)
|
||||
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
|
||||
@ -146,42 +155,133 @@ vec3 maxscale(vec2 sinangle, float2 cosangle)
|
||||
#else
|
||||
vec4 wid = 2.0 + 2.0 * pow(color, vec4(4.0));
|
||||
vec4 weights = vec4(distance / scanline_weight);
|
||||
return 1.4 * exp(-pow(weights * rsqrt(0.5 * wid), wid)) / (0.6 + 0.2 * wid);
|
||||
return 1.4 * exp(-pow(weights * inversesqrt(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;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
|
||||
|
||||
|
||||
// Precalculate a bunch of useful values we'll need in the fragment
|
||||
// shader.
|
||||
vec2 sinangle = sin(angle);
|
||||
vec2 cosangle = cos(angle);
|
||||
vec3 stretch = maxscale();
|
||||
sinangle = sin(angle);
|
||||
cosangle = cos(angle);
|
||||
stretch = maxscale();
|
||||
|
||||
vec2 ilfac = vec2(1.0,floor(sourceSize[0].y/200.0));
|
||||
ilfac = vec2(1.0,(global.SourceSize.y/200.0));
|
||||
|
||||
// The size of one texel, in texture-coordinates.
|
||||
vec2 one = ilfac / sourceSize[0].xy;
|
||||
one = ilfac / global.SourceSize.xy;
|
||||
|
||||
// Resulting X pixel-coordinate of the pixel we're drawing.
|
||||
float mod_factor = texCoord.x * targetSize.x;
|
||||
mod_factor = TexCoord.x * (global.SourceSize.x / global.SourceSize.z) * (global.SourceSize.z / global.SourceSize.x);
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 1) in vec2 sinangle;
|
||||
layout(location = 2) in vec2 cosangle;
|
||||
layout(location = 3) in vec3 stretch;
|
||||
layout(location = 4) in vec2 ilfac;
|
||||
layout(location = 5) in vec2 one;
|
||||
layout(location = 6) in float mod_factor;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
float intersect(vec2 xy)
|
||||
{
|
||||
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)
|
||||
{
|
||||
float c = intersect(xy);
|
||||
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 = R*acos(a);
|
||||
return uv*r/sin(r/R);
|
||||
}
|
||||
|
||||
vec2 fwtrans(vec2 uv)
|
||||
{
|
||||
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 c = bkwtrans(-R * sinangle / (1.0 + R/d*cosangle.x*cosangle.y));
|
||||
vec2 a = vec2(0.5,0.5)*aspect;
|
||||
vec2 lo = vec2(fwtrans(vec2(-a.x,c.y)).x,
|
||||
fwtrans(vec2(c.x,-a.y)).y)/aspect;
|
||||
vec2 hi = vec2(fwtrans(vec2(+a.x,c.y)).x,
|
||||
fwtrans(vec2(c.x,+a.y)).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 / scanline_weight);
|
||||
return 1.4 * exp(-pow(weights * inversesqrt(0.5 * wid), wid)) / (0.6 + 0.2 * wid);
|
||||
#endif
|
||||
}
|
||||
|
||||
vec2 transform(vec2 coord)
|
||||
{
|
||||
coord *= global.SourceSize.xy / global.SourceSize.zw;
|
||||
coord = (coord-vec2(0.5))*aspect*stretch.z+stretch.xy;
|
||||
return (bkwtrans(coord)/vec2(overscan_x / 100.0, overscan_y / 100.0)/aspect+vec2(0.5)) * global.SourceSize.zw / global.SourceSize.xy;
|
||||
}
|
||||
|
||||
float corner(vec2 coord)
|
||||
{
|
||||
// coord *= global.SourceSize.xy / global.SourceSize.zw;
|
||||
coord = (coord - vec2(0.5)) * vec2(overscan_x / 100.0, overscan_y / 100.0) + vec2(0.5);
|
||||
coord = min(coord, vec2(1.0)-coord) * aspect;
|
||||
vec2 cdist = vec2(cornersize);
|
||||
coord = (cdist - min(coord,cdist));
|
||||
float dist = sqrt(dot(coord,coord));
|
||||
return clamp((cdist.x-dist)*cornersmooth,0.0, 1.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// Here's a helpful diagram to keep in mind while trying to
|
||||
@ -222,12 +322,12 @@ void main()
|
||||
#endif
|
||||
vec2 ratio_scale = (xy * global.SourceSize.xy - vec2(0.5, 0.5) + ilvec)/ilfac;
|
||||
#ifdef OVERSAMPLE
|
||||
float filter_ = global.SourceSize.y / global.OutputSize.y;
|
||||
float filter_ = fwidth(ratio_scale.y);//global.SourceSize.y / global.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, 0.5) - ilvec) / global.OutputSize.xy;
|
||||
xy = (floor(ratio_scale)*ilfac + vec2(0.5, 0.5) - ilvec) / global.SourceSize.xy;
|
||||
|
||||
// Calculate Lanczos scaling coefficients describing the effect
|
||||
// of various neighbour texels in a scanline on the current
|
||||
@ -281,9 +381,9 @@ void main()
|
||||
// dot-mask emulation:
|
||||
// Output pixels are alternately tinted green and magenta.
|
||||
vec3 dotMaskWeights = mix(
|
||||
vec3(1.0, 0.7, 1.0),
|
||||
vec3(0.7, 1.0, 0.7),
|
||||
floor(mod(mod_factor, 2.0))
|
||||
vec3(1.0, 1.0 - DOTMASK, 1.0),
|
||||
vec3(1.0 - DOTMASK, 1.0, 1.0 - DOTMASK),
|
||||
floor(mod(mod_factor, 2.01))
|
||||
);
|
||||
|
||||
mul_res *= dotMaskWeights;
|
||||
|
Loading…
x
Reference in New Issue
Block a user