mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-26 09:21:30 +11:00
Update crt-geom.slang
CURVATURE is now working. The problem was due to the replacement of ´´´IN.video_size / IN.texture_size´´´ (a small number representing the scale between the two sizes) with ´´´global.SourceSize.xy ´´´ (much bigger than the previous number). SHARPER was made to work too. @hizzlekizzle: I deleted your vec2 angle variable, which was hardcoded to (0, 0) while I was trying to fix the curvature stuff. Feel free to revert that.
This commit is contained in:
parent
cfa2d35646
commit
b4a3d72ca5
|
@ -12,7 +12,7 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
||||||
#define CRTgamma 2.4
|
#define CRTgamma 2.4
|
||||||
#define monitorgamma 2.2
|
#define monitorgamma 2.2
|
||||||
#define d 1.5
|
#define d 1.5
|
||||||
//#define CURVATURE 1.0
|
#define CURVATURE 1.0
|
||||||
#define R 2.0
|
#define R 2.0
|
||||||
#define cornersize 0.03
|
#define cornersize 0.03
|
||||||
#define cornersmooth 1000.0
|
#define cornersmooth 1000.0
|
||||||
|
@ -71,7 +71,6 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
||||||
|
|
||||||
// aspect ratio
|
// aspect ratio
|
||||||
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);
|
vec2 overscan = vec2(1.01, 1.01);
|
||||||
|
|
||||||
#pragma stage vertex
|
#pragma stage vertex
|
||||||
|
@ -84,6 +83,7 @@ layout(location = 3) out vec3 stretch;
|
||||||
layout(location = 4) out vec2 ilfac;
|
layout(location = 4) out vec2 ilfac;
|
||||||
layout(location = 5) out vec2 one;
|
layout(location = 5) out vec2 one;
|
||||||
layout(location = 6) out float mod_factor;
|
layout(location = 6) out float mod_factor;
|
||||||
|
layout(location = 7) out vec2 TextureSize;
|
||||||
|
|
||||||
float intersect(vec2 xy)
|
float intersect(vec2 xy)
|
||||||
{
|
{
|
||||||
|
@ -97,12 +97,10 @@ float intersect(vec2 xy)
|
||||||
vec2 bkwtrans(vec2 xy)
|
vec2 bkwtrans(vec2 xy)
|
||||||
{
|
{
|
||||||
float c = intersect(xy);
|
float c = intersect(xy);
|
||||||
vec2 point = vec2(c)*xy;
|
vec2 point = (vec2(c, c)*xy - vec2(-R, -R)*sinangle) / vec2(R, R);
|
||||||
point -= vec2(-R)*sinangle;
|
|
||||||
point /= vec2(R);
|
|
||||||
vec2 tang = sinangle/cosangle;
|
|
||||||
vec2 poc = point/cosangle;
|
vec2 poc = point/cosangle;
|
||||||
|
|
||||||
|
vec2 tang = sinangle/cosangle;
|
||||||
float A = dot(tang, tang) + 1.0;
|
float A = dot(tang, tang) + 1.0;
|
||||||
float B = -2.0*dot(poc, tang);
|
float B = -2.0*dot(poc, tang);
|
||||||
float C = dot(poc, poc) - 1.0;
|
float C = dot(poc, poc) - 1.0;
|
||||||
|
@ -128,8 +126,10 @@ vec3 maxscale()
|
||||||
{
|
{
|
||||||
vec2 c = bkwtrans(-R * sinangle / (1.0 + R/d*cosangle.x*cosangle.y));
|
vec2 c = bkwtrans(-R * sinangle / (1.0 + R/d*cosangle.x*cosangle.y));
|
||||||
vec2 a = vec2(0.5,0.5)*aspect;
|
vec2 a = vec2(0.5,0.5)*aspect;
|
||||||
|
|
||||||
vec2 lo = vec2(fwtrans(vec2(-a.x, c.y)).x,
|
vec2 lo = vec2(fwtrans(vec2(-a.x, c.y)).x,
|
||||||
fwtrans(vec2( c.x, -a.y)).y)/aspect;
|
fwtrans(vec2( c.x, -a.y)).y)/aspect;
|
||||||
|
|
||||||
vec2 hi = vec2(fwtrans(vec2(+a.x, c.y)).x,
|
vec2 hi = vec2(fwtrans(vec2(+a.x, c.y)).x,
|
||||||
fwtrans(vec2( c.x, +a.y)).y)/aspect;
|
fwtrans(vec2( c.x, +a.y)).y)/aspect;
|
||||||
|
|
||||||
|
@ -174,14 +174,19 @@ void main()
|
||||||
|
|
||||||
// Precalculate a bunch of useful values we'll need in the fragment
|
// Precalculate a bunch of useful values we'll need in the fragment
|
||||||
// shader.
|
// shader.
|
||||||
sinangle = sin(angle);
|
sinangle = sin(vec2(x_tilt, y_tilt));
|
||||||
cosangle = cos(angle);
|
cosangle = cos(vec2(x_tilt, y_tilt));
|
||||||
stretch = maxscale();
|
stretch = maxscale();
|
||||||
|
TextureSize = vec2(SHARPER * global.SourceSize.x, global.SourceSize.y);
|
||||||
|
|
||||||
ilfac = vec2(1.0, 1.0000001);//vec2(1.0,(global.SourceSize.y/200.0));
|
#ifdef INTERLACED
|
||||||
|
ilfac = vec2(1.0, clamp(floor(global.SourceSize.y/200.0), 1.0, 2.0));
|
||||||
|
#else
|
||||||
|
ilfac = vec2(1.0, clamp(floor(global.SourceSize.y/1000.0), 1.0, 2.0));
|
||||||
|
#endif
|
||||||
|
|
||||||
// The size of one texel, in texture-coordinates.
|
// The size of one texel, in texture-coordinates.
|
||||||
one = ilfac / global.SourceSize.xy;
|
one = ilfac / TextureSize;
|
||||||
|
|
||||||
// Resulting X pixel-coordinate of the pixel we're drawing.
|
// Resulting X pixel-coordinate of the pixel we're drawing.
|
||||||
mod_factor = vTexCoord.x * global.SourceSize.x * global.OutputSize.x / global.SourceSize.x;
|
mod_factor = vTexCoord.x * global.SourceSize.x * global.OutputSize.x / global.SourceSize.x;
|
||||||
|
@ -195,6 +200,7 @@ layout(location = 3) in vec3 stretch;
|
||||||
layout(location = 4) in vec2 ilfac;
|
layout(location = 4) in vec2 ilfac;
|
||||||
layout(location = 5) in vec2 one;
|
layout(location = 5) in vec2 one;
|
||||||
layout(location = 6) in float mod_factor;
|
layout(location = 6) in float mod_factor;
|
||||||
|
layout(location = 7) in vec2 TextureSize;
|
||||||
layout(location = 0) out vec4 FragColor;
|
layout(location = 0) out vec4 FragColor;
|
||||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||||
|
|
||||||
|
@ -210,13 +216,9 @@ float intersect(vec2 xy)
|
||||||
vec2 bkwtrans(vec2 xy)
|
vec2 bkwtrans(vec2 xy)
|
||||||
{
|
{
|
||||||
float c = intersect(xy);
|
float c = intersect(xy);
|
||||||
vec2 point = vec2(c)*xy;
|
vec2 point = (vec2(c, c)*xy - vec2(-R, -R)*sinangle) / vec2(R, R);
|
||||||
|
|
||||||
point -= vec2(-R)*sinangle;
|
|
||||||
point /= vec2(R);
|
|
||||||
|
|
||||||
vec2 tang = sinangle/cosangle;
|
|
||||||
vec2 poc = point/cosangle;
|
vec2 poc = point/cosangle;
|
||||||
|
vec2 tang = sinangle/cosangle;
|
||||||
|
|
||||||
float A = dot(tang, tang) + 1.0;
|
float A = dot(tang, tang) + 1.0;
|
||||||
float B = -2.0*dot(poc, tang);
|
float B = -2.0*dot(poc, tang);
|
||||||
|
@ -283,16 +285,15 @@ vec4 scanlineWeights(float distance, vec4 color)
|
||||||
|
|
||||||
vec2 transform(vec2 coord)
|
vec2 transform(vec2 coord)
|
||||||
{
|
{
|
||||||
coord *= global.SourceSize.xy;
|
coord = (coord - vec2(0.5, 0.5))*aspect*stretch.z + stretch.xy;
|
||||||
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.xy;
|
return (bkwtrans(coord) /
|
||||||
|
vec2(overscan_x / 100.0, overscan_y / 100.0)/aspect + vec2(0.5, 0.5));
|
||||||
}
|
}
|
||||||
|
|
||||||
float corner(vec2 coord)
|
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, 0.5);
|
||||||
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;
|
coord = min(coord, vec2(1.0) - coord) * aspect;
|
||||||
vec2 cdist = vec2(cornersize);
|
vec2 cdist = vec2(cornersize);
|
||||||
coord = (cdist - min(coord, cdist));
|
coord = (cdist - min(coord, cdist));
|
||||||
|
@ -330,6 +331,7 @@ void main()
|
||||||
#else
|
#else
|
||||||
vec2 xy = vTexCoord;
|
vec2 xy = vTexCoord;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
float cval = corner(xy);
|
float cval = corner(xy);
|
||||||
|
|
||||||
// Of all the pixels that are mapped onto the texel we are
|
// Of all the pixels that are mapped onto the texel we are
|
||||||
|
@ -339,14 +341,12 @@ void main()
|
||||||
#else
|
#else
|
||||||
vec2 ilvec = vec2(0.0, ilfac.y);
|
vec2 ilvec = vec2(0.0, ilfac.y);
|
||||||
#endif
|
#endif
|
||||||
vec2 ratio_scale = (xy * global.SourceSize.xy - vec2(0.5, 0.5) + ilvec)/ilfac;
|
|
||||||
#ifdef OVERSAMPLE
|
vec2 ratio_scale = (xy * TextureSize - vec2(0.5, 0.5) + ilvec) / ilfac;
|
||||||
float filter_ = fwidth(ratio_scale.y);//global.SourceSize.y / global.OutputSize.y;
|
|
||||||
#endif
|
|
||||||
vec2 uv_ratio = fract(ratio_scale);
|
vec2 uv_ratio = fract(ratio_scale);
|
||||||
|
|
||||||
// Snap to the center of the underlying texel.
|
// Snap to the center of the underlying texel.
|
||||||
xy = (floor(ratio_scale)*ilfac + vec2(0.5, 0.5) - ilvec) / global.SourceSize.xy;
|
xy = (floor(ratio_scale)*ilfac + vec2(0.5, 0.5) - ilvec) / TextureSize;
|
||||||
|
|
||||||
// Calculate Lanczos scaling coefficients describing the effect
|
// Calculate Lanczos scaling coefficients describing the effect
|
||||||
// of various neighbour texels in a scanline on the current
|
// of various neighbour texels in a scanline on the current
|
||||||
|
@ -393,7 +393,9 @@ void main()
|
||||||
// the current pixel.
|
// the current pixel.
|
||||||
vec4 weights = scanlineWeights(uv_ratio.y, col);
|
vec4 weights = scanlineWeights(uv_ratio.y, col);
|
||||||
vec4 weights2 = scanlineWeights(1.0 - uv_ratio.y, col2);
|
vec4 weights2 = scanlineWeights(1.0 - uv_ratio.y, col2);
|
||||||
|
|
||||||
#ifdef OVERSAMPLE
|
#ifdef OVERSAMPLE
|
||||||
|
float filter_ = fwidth(ratio_scale.y);
|
||||||
uv_ratio.y = uv_ratio.y + 1.0/3.0*filter_;
|
uv_ratio.y = uv_ratio.y + 1.0/3.0*filter_;
|
||||||
weights = (weights + scanlineWeights(uv_ratio.y, col))/3.0;
|
weights = (weights + scanlineWeights(uv_ratio.y, col))/3.0;
|
||||||
weights2 = (weights2 + scanlineWeights(abs(1.0 - uv_ratio.y), col2))/3.0;
|
weights2 = (weights2 + scanlineWeights(abs(1.0 - uv_ratio.y), col2))/3.0;
|
||||||
|
@ -401,6 +403,7 @@ void main()
|
||||||
weights = weights + scanlineWeights(abs(uv_ratio.y), col)/3.0;
|
weights = weights + scanlineWeights(abs(uv_ratio.y), col)/3.0;
|
||||||
weights2 = weights2 + scanlineWeights(abs(1.0 - uv_ratio.y), col2)/3.0;
|
weights2 = weights2 + scanlineWeights(abs(1.0 - uv_ratio.y), col2)/3.0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vec3 mul_res = (col * weights + col2 * weights2).rgb * vec3(cval);
|
vec3 mul_res = (col * weights + col2 * weights2).rgb * vec3(cval);
|
||||||
|
|
||||||
// dot-mask emulation:
|
// dot-mask emulation:
|
||||||
|
|
Loading…
Reference in a new issue