mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-23 08:11:29 +11:00
Update crt-geom.slang
Changed the formatting, tab size is 4 spaces. Based on the discussion in IRC, I carefully deleted every instance of global.SourceSize.zw, because z = 1/x and w = 1/y and zw is NOT the same as IN.video_size.
This commit is contained in:
parent
f14ba96715
commit
c864dbb2d4
|
@ -90,6 +90,7 @@ float intersect(vec2 xy)
|
||||||
float A = dot(xy,xy) + d*d;
|
float A = dot(xy,xy) + d*d;
|
||||||
float B = 2.0*(R*(dot(xy,sinangle)-d*cosangle.x*cosangle.y)-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;
|
float C = d*d + 2.0*R*d*cosangle.x*cosangle.y;
|
||||||
|
|
||||||
return (-B-sqrt(B*B-4.0*A*C))/(2.0*A);
|
return (-B-sqrt(B*B-4.0*A*C))/(2.0*A);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,12 +102,15 @@ vec2 bkwtrans(vec2 xy)
|
||||||
point /= vec2(R);
|
point /= vec2(R);
|
||||||
vec2 tang = sinangle/cosangle;
|
vec2 tang = sinangle/cosangle;
|
||||||
vec2 poc = point/cosangle;
|
vec2 poc = point/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;
|
||||||
|
|
||||||
float a = (-B+sqrt(B*B-4.0*A*C))/(2.0*A);
|
float a = (-B+sqrt(B*B-4.0*A*C))/(2.0*A);
|
||||||
vec2 uv = (point-a*sinangle)/cosangle;
|
vec2 uv = (point-a*sinangle)/cosangle;
|
||||||
float r = R*acos(a);
|
float r = R*acos(a);
|
||||||
|
|
||||||
return uv*r/sin(r/R);
|
return uv*r/sin(r/R);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +120,7 @@ vec2 fwtrans(vec2 uv)
|
||||||
uv *= sin(r/R)/r;
|
uv *= sin(r/R)/r;
|
||||||
float x = 1.0-cos(r/R);
|
float x = 1.0-cos(r/R);
|
||||||
float D = d/R + x*cosangle.x*cosangle.y+dot(uv,sinangle);
|
float D = d/R + x*cosangle.x*cosangle.y+dot(uv,sinangle);
|
||||||
|
|
||||||
return d*(uv*cosangle-x*sinangle)/D;
|
return d*(uv*cosangle-x*sinangle)/D;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,6 +132,7 @@ vec3 maxscale()
|
||||||
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;
|
||||||
|
|
||||||
return vec3((hi+lo)*aspect*0.5,max(hi.x-lo.x,hi.y-lo.y));
|
return vec3((hi+lo)*aspect*0.5,max(hi.x-lo.x,hi.y-lo.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,10 +157,12 @@ vec3 maxscale()
|
||||||
#ifdef USEGAUSSIAN
|
#ifdef USEGAUSSIAN
|
||||||
vec4 wid = 0.3 + 0.1 * pow(color, vec4(3.0));
|
vec4 wid = 0.3 + 0.1 * pow(color, vec4(3.0));
|
||||||
vec4 weights = vec4(distance / wid);
|
vec4 weights = vec4(distance / wid);
|
||||||
|
|
||||||
return 0.4 * exp(-weights * weights) / wid;
|
return 0.4 * exp(-weights * weights) / wid;
|
||||||
#else
|
#else
|
||||||
vec4 wid = 2.0 + 2.0 * pow(color, vec4(4.0));
|
vec4 wid = 2.0 + 2.0 * pow(color, vec4(4.0));
|
||||||
vec4 weights = vec4(distance / scanline_weight);
|
vec4 weights = vec4(distance / scanline_weight);
|
||||||
|
|
||||||
return 1.4 * exp(-pow(weights * inversesqrt(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
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -176,7 +184,7 @@ void main()
|
||||||
one = ilfac / global.SourceSize.xy;
|
one = ilfac / global.SourceSize.xy;
|
||||||
|
|
||||||
// Resulting X pixel-coordinate of the pixel we're drawing.
|
// Resulting X pixel-coordinate of the pixel we're drawing.
|
||||||
mod_factor = TexCoord.x * (global.SourceSize.x / global.SourceSize.z) * (global.SourceSize.z / global.SourceSize.x);
|
mod_factor = TexCoord.x * global.SourceSize.x * global.OutputSize.x / global.SourceSize.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma stage fragment
|
#pragma stage fragment
|
||||||
|
@ -195,6 +203,7 @@ float intersect(vec2 xy)
|
||||||
float A = dot(xy,xy) + d*d;
|
float A = dot(xy,xy) + d*d;
|
||||||
float B = 2.0*(R*(dot(xy,sinangle)-d*cosangle.x*cosangle.y) - 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;
|
float C = d*d + 2.0*R*d*cosangle.x*cosangle.y;
|
||||||
|
|
||||||
return (-B-sqrt(B*B - 4.0*A*C))/(2.0*A);
|
return (-B-sqrt(B*B - 4.0*A*C))/(2.0*A);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,16 +211,21 @@ vec2 bkwtrans(vec2 xy)
|
||||||
{
|
{
|
||||||
float c = intersect(xy);
|
float c = intersect(xy);
|
||||||
vec2 point = vec2(c)*xy;
|
vec2 point = vec2(c)*xy;
|
||||||
|
|
||||||
point -= vec2(-R)*sinangle;
|
point -= vec2(-R)*sinangle;
|
||||||
point /= vec2(R);
|
point /= vec2(R);
|
||||||
|
|
||||||
vec2 tang = sinangle/cosangle;
|
vec2 tang = sinangle/cosangle;
|
||||||
vec2 poc = point/cosangle;
|
vec2 poc = point/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;
|
||||||
|
|
||||||
float a = (-B+sqrt(B*B-4.0*A*C))/(2.0*A);
|
float a = (-B+sqrt(B*B-4.0*A*C))/(2.0*A);
|
||||||
vec2 uv = (point-a*sinangle)/cosangle;
|
vec2 uv = (point-a*sinangle)/cosangle;
|
||||||
float r = R*acos(a);
|
float r = R*acos(a);
|
||||||
|
|
||||||
return uv*r/sin(r/R);
|
return uv*r/sin(r/R);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,6 +235,7 @@ vec2 fwtrans(vec2 uv)
|
||||||
uv *= sin(r/R)/r;
|
uv *= sin(r/R)/r;
|
||||||
float x = 1.0-cos(r/R);
|
float x = 1.0-cos(r/R);
|
||||||
float D = d/R + x*cosangle.x*cosangle.y + dot(uv,sinangle);
|
float D = d/R + x*cosangle.x*cosangle.y + dot(uv,sinangle);
|
||||||
|
|
||||||
return d*(uv*cosangle-x*sinangle)/D;
|
return d*(uv*cosangle-x*sinangle)/D;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,10 +243,12 @@ 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;
|
||||||
|
|
||||||
return vec3((hi+lo)*aspect*0.5,max(hi.x-lo.x, hi.y-lo.y));
|
return vec3((hi+lo)*aspect*0.5,max(hi.x-lo.x, hi.y-lo.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,9 +283,10 @@ vec3 maxscale()
|
||||||
|
|
||||||
vec2 transform(vec2 coord)
|
vec2 transform(vec2 coord)
|
||||||
{
|
{
|
||||||
coord *= global.SourceSize.xy / global.SourceSize.zw;
|
coord *= global.SourceSize.xy;
|
||||||
coord = (coord-vec2(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.zw / global.SourceSize.xy;
|
|
||||||
|
return (bkwtrans(coord)/vec2(overscan_x / 100.0, overscan_y / 100.0)/aspect+vec2(0.5)) * global.SourceSize.xy;
|
||||||
}
|
}
|
||||||
|
|
||||||
float corner(vec2 coord)
|
float corner(vec2 coord)
|
||||||
|
@ -279,6 +297,7 @@ float corner(vec2 coord)
|
||||||
vec2 cdist = vec2(cornersize);
|
vec2 cdist = vec2(cornersize);
|
||||||
coord = (cdist - min(coord, cdist));
|
coord = (cdist - min(coord, cdist));
|
||||||
float dist = sqrt(dot(coord, coord));
|
float dist = sqrt(dot(coord, coord));
|
||||||
|
|
||||||
return clamp((cdist.x-dist)*cornersmooth, 0.0, 1.0);
|
return clamp((cdist.x-dist)*cornersmooth, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,18 +365,24 @@ void main()
|
||||||
// Calculate the effective colour of the current and next
|
// Calculate the effective colour of the current and next
|
||||||
// scanlines at the horizontal location of the current pixel,
|
// scanlines at the horizontal location of the current pixel,
|
||||||
// using the Lanczos coefficients above.
|
// using the Lanczos coefficients above.
|
||||||
vec4 col = clamp(mat4(
|
vec4 col = clamp(
|
||||||
|
mat4(
|
||||||
TEX2D(xy + vec2(-one.x, 0.0)),
|
TEX2D(xy + vec2(-one.x, 0.0)),
|
||||||
TEX2D(xy),
|
TEX2D(xy),
|
||||||
TEX2D(xy + vec2(one.x, 0.0)),
|
TEX2D(xy + vec2(one.x, 0.0)),
|
||||||
TEX2D(xy + vec2(2.0 * one.x, 0.0))) * coeffs,
|
TEX2D(xy + vec2(2.0 * one.x, 0.0))
|
||||||
0.0, 1.0);
|
) * coeffs,
|
||||||
vec4 col2 = clamp(mat4(
|
0.0, 1.0
|
||||||
|
);
|
||||||
|
vec4 col2 = clamp(
|
||||||
|
mat4(
|
||||||
TEX2D(xy + vec2(-one.x, one.y)),
|
TEX2D(xy + vec2(-one.x, one.y)),
|
||||||
TEX2D(xy + vec2(0.0, one.y)),
|
TEX2D(xy + vec2(0.0, one.y)),
|
||||||
TEX2D(xy + one),
|
TEX2D(xy + one),
|
||||||
TEX2D(xy + vec2(2.0 * one.x, one.y))) * coeffs,
|
TEX2D(xy + vec2(2.0 * one.x, one.y))
|
||||||
0.0, 1.0);
|
) * coeffs,
|
||||||
|
0.0, 1.0
|
||||||
|
);
|
||||||
|
|
||||||
#ifndef LINEAR_PROCESSING
|
#ifndef LINEAR_PROCESSING
|
||||||
col = pow(col , vec4(CRTgamma));
|
col = pow(col , vec4(CRTgamma));
|
||||||
|
|
Loading…
Reference in a new issue