mirror of
https://github.com/libretro/glsl-shaders.git
synced 2024-11-23 07:40:29 +00:00
add cgwg-famicom-geom and move all NES raw palette shaders to a new subdir
This commit is contained in:
parent
257a5bb0fd
commit
acc1bef935
25
nes_raw_palette/cgwg-famicom-geom.glslp
Normal file
25
nes_raw_palette/cgwg-famicom-geom.glslp
Normal file
@ -0,0 +1,25 @@
|
||||
shaders = 5
|
||||
|
||||
shader0 = shaders/cgwg-famicom-geom/composite-encode.glsl
|
||||
filter_linear0 = false
|
||||
scale_type0 = source
|
||||
scale_x0 = 2.0
|
||||
frame_count_mod0 = 2
|
||||
alias0 = encode_pass
|
||||
float_framebuffer0 = true
|
||||
|
||||
shader1 = shaders/cgwg-famicom-geom/lowpass-notch-decode-yiq.glsl
|
||||
frame_count_mod1 = 2
|
||||
filter_linear1 = false
|
||||
float_framebuffer1 = true
|
||||
|
||||
shader2 = shaders/cgwg-famicom-geom/adaptive-comb-decode.glsl
|
||||
filter_linear2 = false
|
||||
frame_count_mod2 = 2
|
||||
float_framebuffer2 = true
|
||||
|
||||
shader3 = shaders/cgwg-famicom-geom/lowpass-chroma.glsl
|
||||
filter_linear3 = false
|
||||
float_framebuffer3 = true
|
||||
|
||||
shader4 = shaders/cgwg-famicom-geom/crt-geom-famicom.glsl
|
@ -1,7 +1,7 @@
|
||||
shaders = 3
|
||||
shader0 = ../misc/nes-color-decoder.glsl
|
||||
shader1 = shaders/ntsc-pass1-composite-3phase.glsl
|
||||
shader2 = shaders/ntsc-pass2-3phase.glsl
|
||||
shader0 = shaders/nes-color-decoder.glsl
|
||||
shader1 = ../ntsc/shaders/ntsc-pass1-composite-3phase.glsl
|
||||
shader2 = ../ntsc/shaders/ntsc-pass2-3phase.glsl
|
||||
|
||||
filter_linear0 = false
|
||||
filter_linear1 = false
|
@ -0,0 +1,172 @@
|
||||
#version 130
|
||||
#define phase FrameCount
|
||||
|
||||
#if defined(VERTEX)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING out
|
||||
#define COMPAT_ATTRIBUTE in
|
||||
#define COMPAT_TEXTURE texture
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define COMPAT_ATTRIBUTE attribute
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
COMPAT_ATTRIBUTE vec4 VertexCoord;
|
||||
COMPAT_ATTRIBUTE vec4 COLOR;
|
||||
COMPAT_ATTRIBUTE vec4 TexCoord;
|
||||
COMPAT_VARYING vec4 COL0;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
vec4 _oPosition1;
|
||||
uniform mat4 MVPMatrix;
|
||||
uniform COMPAT_PRECISION int FrameDirection;
|
||||
uniform COMPAT_PRECISION int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
|
||||
// compatibility #defines
|
||||
#define vTexCoord TEX0.xy
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVPMatrix * VertexCoord;
|
||||
TEX0.xy = TexCoord.xy;
|
||||
}
|
||||
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#ifdef GL_ES
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING in
|
||||
#define COMPAT_TEXTURE texture
|
||||
out COMPAT_PRECISION vec4 FragColor;
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define FragColor gl_FragColor
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
uniform COMPAT_PRECISION int FrameDirection;
|
||||
uniform COMPAT_PRECISION int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 PassPrev2TextureSize;
|
||||
#define encode_passSize vec4(PassPrev2TextureSize.xy, 1.0/PassPrev2TextureSize.xy)
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
uniform sampler2D Texture;
|
||||
uniform sampler2D PassPrev2Texture;
|
||||
#define encode_pass PassPrev2Texture
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
// compatibility #defines
|
||||
#define Source Texture
|
||||
#define texCoord TEX0.xy
|
||||
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
vec4 decode_sample(vec2 shift) {
|
||||
const float min = 0.350*0.746;
|
||||
const float max = 1.962;
|
||||
const float black = 0.518;
|
||||
vec2 coord = texCoord + encode_passSize.zw*shift;
|
||||
if (coord.x < 0.0 || coord.x > 1.0 || coord.y < 0.0 || coord.y > 1.0) return vec4(0.0);
|
||||
return (COMPAT_TEXTURE(encode_pass, coord) * vec4(max-min) + vec4(min-black)) / vec4(max-black);
|
||||
}
|
||||
|
||||
vec3 filtsample(vec2 shift) {
|
||||
vec2 coord = texCoord + SourceSize.zw*shift;
|
||||
if (coord.x < 0.0 || coord.x > 1.0 || coord.y < 0.0 || coord.y > 1.0) return vec3(0.0);
|
||||
return COMPAT_TEXTURE(Source, texCoord + SourceSize.zw*shift).xyz-vec3(0,0.5,0.5);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 samps[] = vec4[](decode_sample(vec2(-1,0)),
|
||||
decode_sample(vec2( 0,0)),
|
||||
decode_sample(vec2( 1,0)));
|
||||
// quarter-pixel shift between scanlines needed for comb filter
|
||||
vec4 s1, s2, s3, s4;
|
||||
s1 = decode_sample(vec2(-2,-1));
|
||||
s2 = decode_sample(vec2(-1,-1));
|
||||
s3 = decode_sample(vec2( 0,-1));
|
||||
s4 = decode_sample(vec2( 1,-1));
|
||||
vec4 samps_prev[] = vec4[](vec4(s1.zw,s2.xy),
|
||||
vec4(s2.zw,s3.xy),
|
||||
vec4(s3.zw,s4.xy));
|
||||
s1 = decode_sample(vec2(-1,1));
|
||||
s2 = decode_sample(vec2(-0,1));
|
||||
s3 = decode_sample(vec2( 1,1));
|
||||
s4 = decode_sample(vec2( 2,1));
|
||||
vec4 samps_next[] = vec4[](vec4(s1.zw,s2.xy),
|
||||
vec4(s2.zw,s3.xy),
|
||||
vec4(s3.zw,s4.xy));
|
||||
|
||||
uint x = uint(floor(texCoord.x*SourceSize.x));
|
||||
uint y = uint(floor(texCoord.y*SourceSize.y));
|
||||
uint p = (x+y+uint(phase)) % 3u;
|
||||
|
||||
const vec4 one = vec4(1.0);
|
||||
const vec4 PI_6 = vec4(3.14159265359/6.0);
|
||||
const vec4 offs = vec4(-0.0);
|
||||
const vec4 sins[] = vec4[](sin((vec4(0,1, 2, 3)+offs)*PI_6),
|
||||
sin((vec4(4,5, 6, 7)+offs)*PI_6),
|
||||
sin((vec4(8,9,10,11)+offs)*PI_6));
|
||||
const vec4 coss[] = vec4[](cos((vec4(0,1, 2, 3)+offs)*PI_6),
|
||||
cos((vec4(4,5, 6, 7)+offs)*PI_6),
|
||||
cos((vec4(8,9,10,11)+offs)*PI_6));
|
||||
|
||||
vec3 filt = filtsample(vec2(0, 0));
|
||||
vec3 filt_cur = (filt + filtsample(vec2(-1,0))+filtsample(vec2(1,0)))/3.0;
|
||||
vec3 filt_prev = (filtsample(vec2(0,-1))+filtsample(vec2(-1,-1))+filtsample(vec2(1,-1)))/3.0;
|
||||
vec3 filt_next = (filtsample(vec2(0, 1))+filtsample(vec2(-1, 1))+filtsample(vec2(1, 1)))/3.0;
|
||||
vec3 dif1 = filt_cur-filt_prev;
|
||||
vec3 dif2 = filt_cur-filt_next;
|
||||
// this formula can be tweaked
|
||||
float xprev = clamp(0.5-sqrt(dot(dif1,dif1)),0,0.5);
|
||||
float xnext = clamp(0.5-sqrt(dot(dif2,dif2)),0,0.5);
|
||||
float xcur = clamp(xprev+xnext,0,0.5);
|
||||
float scale = (xcur+0.0001)/(xprev+xnext+0.0001);
|
||||
xprev *= scale;
|
||||
xnext *= scale;
|
||||
float xfilt = 1.0 - 2.0*xcur;
|
||||
|
||||
vec3 yiq = vec3(0.0);
|
||||
yiq.x = xcur*dot(samps[1],one) + xprev*dot(samps_prev[1],one) + xnext*dot(samps_next[1],one);
|
||||
for (uint i = 0u; i < 3u; i++) {
|
||||
samps[i] = xcur*samps[i] - xprev*samps_prev[i] - xnext*samps_next[i];
|
||||
yiq.y += dot(samps[i],coss[(i+p+2u)%3u]);
|
||||
yiq.z += dot(samps[i],sins[(i+p+2u)%3u]);
|
||||
}
|
||||
|
||||
yiq *= vec3(1.0/4.0, 1.0/6.0, 1.0/6.0);
|
||||
yiq += xfilt*filt;
|
||||
|
||||
//FragColor = vec4(dot(yiq, vec3(1.0, 0.946882, 0.623557)),
|
||||
// dot(yiq, vec3(1.0,-0.274788,-0.635691)),
|
||||
// dot(yiq, vec3(1.0,-1.108545, 1.709007)),
|
||||
// 0.0);
|
||||
FragColor = vec4(yiq+vec3(0,0.5,0.5),0.0);
|
||||
}
|
||||
#endif
|
129
nes_raw_palette/shaders/cgwg-famicom-geom/composite-encode.glsl
Normal file
129
nes_raw_palette/shaders/cgwg-famicom-geom/composite-encode.glsl
Normal file
@ -0,0 +1,129 @@
|
||||
#version 130
|
||||
|
||||
#if defined(VERTEX)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING out
|
||||
#define COMPAT_ATTRIBUTE in
|
||||
#define COMPAT_TEXTURE texture
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define COMPAT_ATTRIBUTE attribute
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
COMPAT_ATTRIBUTE vec4 VertexCoord;
|
||||
COMPAT_ATTRIBUTE vec4 COLOR;
|
||||
COMPAT_ATTRIBUTE vec4 TexCoord;
|
||||
COMPAT_VARYING vec4 COL0;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
vec4 _oPosition1;
|
||||
uniform mat4 MVPMatrix;
|
||||
uniform COMPAT_PRECISION int FrameDirection;
|
||||
uniform COMPAT_PRECISION int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
|
||||
// compatibility #defines
|
||||
#define vTexCoord TEX0.xy
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVPMatrix * VertexCoord;
|
||||
TEX0.xy = TexCoord.xy;
|
||||
}
|
||||
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#ifdef GL_ES
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING in
|
||||
#define COMPAT_TEXTURE texture
|
||||
out COMPAT_PRECISION vec4 FragColor;
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define FragColor gl_FragColor
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
uniform COMPAT_PRECISION int FrameDirection;
|
||||
uniform COMPAT_PRECISION int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
uniform sampler2D Texture;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
// compatibility #defines
|
||||
#define Source Texture
|
||||
#define vTexCoord TEX0.xy
|
||||
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
bool wave (int p, int color)
|
||||
{
|
||||
return ((color + p + 8) % 12 < 6);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
/* original palette decode for historical purposes:
|
||||
uint n = uint(COMPAT_TEXTURE(Source, vTexCoord).r);
|
||||
uint color = n & 0xfu;
|
||||
uint level = color < 0xeu ? (n>>4u)&3u : 1u;
|
||||
uint emphasis = n >> 6u;
|
||||
*/
|
||||
|
||||
vec4 c = COMPAT_TEXTURE(Source, vTexCoord.xy);
|
||||
|
||||
// Extract the chroma, level, and emphasis from the normalized RGB triplet
|
||||
int color = int(floor((c.r * 15.0) + 0.5));
|
||||
int level = int(floor((c.g * 3.0) + 0.5));
|
||||
int emphasis = int(floor((c.b * 7.0) + 0.5));
|
||||
|
||||
const float levels[] = float[](0.350, 0.518, 0.962, 1.550,
|
||||
1.094, 1.506, 1.962, 1.962);
|
||||
const float attenuation = 0.746;
|
||||
const float min = levels[0]*attenuation;
|
||||
const float max = levels[7];
|
||||
|
||||
float lo_hi[] = float[](levels[uint(level) + 4u*uint(color == int(0x0u))],
|
||||
levels[uint(level) + 4u*uint(color < int(0xdu))]);
|
||||
|
||||
uint x = uint(floor(vTexCoord.x*SourceSize.x*2.0));
|
||||
uint y = uint(floor(vTexCoord.y*SourceSize.y));
|
||||
float frag[4];
|
||||
for (uint i = 0u; i < 4u; i++) {
|
||||
uint p = (x*4u+i + y*4u + uint(FrameCount*4)) % 12u;
|
||||
#define wave(ph,co) ((uint(co)+uint(ph)+8u)%12u<6u)
|
||||
float spot = lo_hi[uint(wave(p,color))];
|
||||
if ( (((uint(emphasis)&1u)==1u) && wave(p,12u))
|
||||
|| (((uint(emphasis)&2u)==1u) && wave(p,4u))
|
||||
|| (((uint(emphasis)&4u)==1u) && wave(p,8u)))
|
||||
spot *= attenuation;
|
||||
frag[i] = spot;
|
||||
}
|
||||
FragColor = (vec4(frag[0], frag[1], frag[2], frag[3]) - vec4(min))/vec4(max-min);
|
||||
}
|
||||
#endif
|
406
nes_raw_palette/shaders/cgwg-famicom-geom/crt-geom-famicom.glsl
Normal file
406
nes_raw_palette/shaders/cgwg-famicom-geom/crt-geom-famicom.glsl
Normal file
@ -0,0 +1,406 @@
|
||||
#pragma parameter CURVATURE_toggle "Curvature Toggle" 1.0 0.0 1.0 1.0
|
||||
#define CURVATURE bool(CURVATURE_toggle)
|
||||
// gamma of simulated CRT
|
||||
#pragma parameter CRTgamma "CRT Gamma" 2.4 1.0 4.0 0.05
|
||||
// overscan (e.g. 1.02 for 2% overscan)
|
||||
#pragma parameter overscan_x "Overscan X" 1.0 0.0 2.0 0.01
|
||||
#pragma parameter overscan_y "Overscan Y" 1.0 0.0 2.0 0.01
|
||||
#define overscan vec2(overscan_x, overscan_y)
|
||||
#pragma parameter distance "Viewing Distance" 2.0 0.1 5.0 0.1
|
||||
// radius of curvature
|
||||
#pragma parameter radius "Curvature Radius" 2.0 0.1 5.0 0.1
|
||||
// tilt angle in radians
|
||||
// (behavior might be a bit wrong if both components are nonzero)
|
||||
#pragma parameter tiltangle_x "Tilt Angle X" 0.0 -1.0 1.0 0.05
|
||||
#pragma parameter tiltangle_y "Tilt Angle Y" 0.0 -1.0 1.0 0.05
|
||||
#define tiltangle vec2(tiltangle_x, tiltangle_y) + 0.001
|
||||
// size of curved corners
|
||||
#pragma parameter cornersize "Corner Size" 0.02 0.0001 0.1 0.01
|
||||
// border smoothness parameter
|
||||
// decrease if borders are too aliased
|
||||
#pragma parameter cornersmooth "Corner Smoothness" 800.0 0.8 2000.0 50.0
|
||||
|
||||
#if defined(VERTEX)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING out
|
||||
#define COMPAT_ATTRIBUTE in
|
||||
#define COMPAT_TEXTURE texture
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define COMPAT_ATTRIBUTE attribute
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
COMPAT_ATTRIBUTE vec4 VertexCoord;
|
||||
COMPAT_ATTRIBUTE vec4 COLOR;
|
||||
COMPAT_ATTRIBUTE vec4 TexCoord;
|
||||
COMPAT_VARYING vec4 COL0;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
COMPAT_VARYING vec3 stretch;
|
||||
|
||||
vec4 _oPosition1;
|
||||
uniform mat4 MVPMatrix;
|
||||
uniform COMPAT_PRECISION int FrameDirection;
|
||||
uniform COMPAT_PRECISION int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
|
||||
// compatibility #defines
|
||||
#define vTexCoord TEX0.xy
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
uniform COMPAT_PRECISION float CURVATURE_toggle, CRTgamma, overscan_x, overscan_y,
|
||||
distance, radius, tiltangle_x, tiltangle_y, cornersize, cornersmooth;
|
||||
#else
|
||||
#define CURVATURE_toggle 1.0
|
||||
#define CRTgamma 2.4
|
||||
#define overscan_x 1.0
|
||||
#define overscan_y 1.0
|
||||
#define distance 2.0
|
||||
#define radius 2.0
|
||||
#define tiltangle_x 0.0
|
||||
#define tiltangle_y 0.0
|
||||
#define cornersize 0.02
|
||||
#define cornersmooth 800.0
|
||||
#endif
|
||||
|
||||
const vec2 aspect = vec2(1.0, 0.75);
|
||||
float d = distance;
|
||||
float R = radius;
|
||||
vec2 sinangle = sin(tiltangle);
|
||||
vec2 cosangle = cos(tiltangle);
|
||||
|
||||
vec2 one;
|
||||
float mod_factor;
|
||||
vec2 ilfac;
|
||||
|
||||
#define FIX(c) max(abs(c), 1e-5);
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVPMatrix * VertexCoord;
|
||||
TEX0.xy = TexCoord.xy;
|
||||
stretch = maxscale();
|
||||
}
|
||||
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#ifdef GL_ES
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING in
|
||||
#define COMPAT_TEXTURE texture
|
||||
out COMPAT_PRECISION vec4 FragColor;
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define FragColor gl_FragColor
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
uniform COMPAT_PRECISION int FrameDirection;
|
||||
uniform COMPAT_PRECISION int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
uniform sampler2D Texture;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
COMPAT_VARYING vec3 stretch;
|
||||
|
||||
// compatibility #defines
|
||||
#define Source Texture
|
||||
#define texCoord TEX0.xy
|
||||
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
uniform COMPAT_PRECISION float CURVATURE_toggle, CRTgamma, overscan_x, overscan_y,
|
||||
distance, radius, tiltangle_x, tiltangle_y, cornersize, cornersmooth;
|
||||
#else
|
||||
#define CURVATURE_toggle 1.0
|
||||
#define CRTgamma 2.4
|
||||
#define overscan_x 1.0
|
||||
#define overscan_y 1.0
|
||||
#define distance 2.0
|
||||
#define radius 2.0
|
||||
#define tiltangle_x 0.0
|
||||
#define tiltangle_y 0.0
|
||||
#define cornersize 0.02
|
||||
#define cornersmooth 800.0
|
||||
#endif
|
||||
|
||||
// Comment the next line to disable interpolation in linear gamma (and gain speed).
|
||||
//#define LINEAR_PROCESSING
|
||||
|
||||
// Enable 3x oversampling of the beam profile
|
||||
#define OVERSAMPLE
|
||||
|
||||
// Use the older, purely gaussian beam profile
|
||||
//#define USEGAUSSIAN
|
||||
|
||||
// gamma of display monitor (typically 2.2 is correct)
|
||||
#define monitorgamma 2.2
|
||||
|
||||
// aspect ratio
|
||||
const 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 = distance;
|
||||
float R = radius;
|
||||
|
||||
vec2 sinangle = sin(tiltangle);
|
||||
vec2 cosangle = cos(tiltangle);
|
||||
|
||||
#define one (SourceSize.zw)
|
||||
|
||||
// Macros.
|
||||
#define FIX(c) max(abs(c), 1e-5);
|
||||
#define PI 3.141592653589
|
||||
|
||||
#ifdef LINEAR_PROCESSING
|
||||
# define TEX2D(c) pow(COMPAT_TEXTURE(Source, (c)), vec4(CRTgamma))
|
||||
#else
|
||||
# define TEX2D(c) COMPAT_TEXTURE(Source, (c))
|
||||
#endif
|
||||
|
||||
#define FIX(c) max(abs(c), 1e-5);
|
||||
|
||||
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 = FIX(R*acos(a));
|
||||
return uv*r/sin(r/R);
|
||||
}
|
||||
|
||||
vec2 transform(vec2 coord)
|
||||
{
|
||||
coord = (coord-vec2(0.5))*aspect*stretch.z+stretch.xy;
|
||||
return (bkwtrans(coord)/overscan/aspect+vec2(0.5));
|
||||
}
|
||||
|
||||
float corner(vec2 coord)
|
||||
{
|
||||
coord = (coord - vec2(0.5)) * overscan + 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);
|
||||
}
|
||||
|
||||
// Calculate the influence of a scanline on the current pixel.
|
||||
//
|
||||
// 'dist' 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 dist, 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(dist / wid);
|
||||
return 0.4 * exp(-weights * weights) / wid;
|
||||
#else
|
||||
vec4 wid = 2.0 + 2.0 * pow(color, vec4(4.0));
|
||||
vec4 weights = vec4(dist / 0.3);
|
||||
return 1.4 * exp(-pow(weights * inversesqrt(0.5 * wid), wid)) / (0.6 + 0.2 * wid);
|
||||
#endif
|
||||
}
|
||||
|
||||
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.
|
||||
vec2 xy = CURVATURE ? transform(texCoord) : texCoord;
|
||||
float cval = corner(xy);
|
||||
|
||||
// Of all the pixels that are mapped onto the texel we are
|
||||
// currently rendering, which pixel are we currently rendering?
|
||||
vec2 ratio_scale = xy * SourceSize.xy - vec2(0.5);
|
||||
|
||||
#ifdef OVERSAMPLE
|
||||
float filter_ = fwidth(ratio_scale.y);
|
||||
#endif
|
||||
vec2 uv_ratio = fract(ratio_scale);
|
||||
|
||||
// Snap to the center of the underlying texel.
|
||||
xy = (floor(ratio_scale) + vec2(0.5)) / 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(mat4(
|
||||
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))) * coeffs,
|
||||
0.0, 1.0);
|
||||
vec4 col2 = clamp(mat4(
|
||||
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))) * coeffs,
|
||||
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 * vec3(cval);
|
||||
|
||||
// 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(texCoord.x*OutputSize.x, 2.0))
|
||||
);
|
||||
|
||||
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);
|
||||
}
|
||||
#endif
|
138
nes_raw_palette/shaders/cgwg-famicom-geom/lowpass-chroma.glsl
Normal file
138
nes_raw_palette/shaders/cgwg-famicom-geom/lowpass-chroma.glsl
Normal file
@ -0,0 +1,138 @@
|
||||
// after mixing with the adaptive comb filter
|
||||
#pragma parameter postfilter_taps "Post-filter Taps" 15.0 1.0 30.0 1.0
|
||||
#define postfiltertaps int(postfilter_taps)
|
||||
#pragma parameter postfilterchromacutoff "Post-filter Chroma Cutoff" 0.3 0.1 1.0 0.05
|
||||
|
||||
#if defined(VERTEX)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING out
|
||||
#define COMPAT_ATTRIBUTE in
|
||||
#define COMPAT_TEXTURE texture
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define COMPAT_ATTRIBUTE attribute
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
COMPAT_ATTRIBUTE vec4 VertexCoord;
|
||||
COMPAT_ATTRIBUTE vec4 COLOR;
|
||||
COMPAT_ATTRIBUTE vec4 TexCoord;
|
||||
COMPAT_VARYING vec4 COL0;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
vec4 _oPosition1;
|
||||
uniform mat4 MVPMatrix;
|
||||
uniform COMPAT_PRECISION int FrameDirection;
|
||||
uniform COMPAT_PRECISION int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
|
||||
// compatibility #defines
|
||||
#define vTexCoord TEX0.xy
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVPMatrix * VertexCoord;
|
||||
TEX0.xy = TexCoord.xy;
|
||||
}
|
||||
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#ifdef GL_ES
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING in
|
||||
#define COMPAT_TEXTURE texture
|
||||
out COMPAT_PRECISION vec4 FragColor;
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define FragColor gl_FragColor
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
uniform COMPAT_PRECISION int FrameDirection;
|
||||
uniform COMPAT_PRECISION int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
uniform sampler2D Texture;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
// compatibility #defines
|
||||
#define Source Texture
|
||||
#define texCoord TEX0.xy
|
||||
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
uniform COMPAT_PRECISION float postfilter_taps, postfilterchromacutoff;
|
||||
#else
|
||||
#define postfilter_taps 15.0
|
||||
#define postfilterchromacutoff 0.3
|
||||
#endif
|
||||
|
||||
vec3 chroma_sample(vec2 shift) {
|
||||
vec2 coord = texCoord + SourceSize.zw*shift;
|
||||
if (coord.x < 0.0 || coord.x > 1.0) return vec3(0.0);
|
||||
return COMPAT_TEXTURE(Source, texCoord + SourceSize.zw*shift).xyz-vec3(0,0.5,0.5);
|
||||
}
|
||||
|
||||
float sinc(float x) {
|
||||
x = max(abs(x),0.0001);
|
||||
return sin(x)/x;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
int width = postfiltertaps;
|
||||
float bw_c = postfilterchromacutoff/3.0;
|
||||
|
||||
const vec4 one = vec4(1.0);
|
||||
const float PI = 3.14159265359;
|
||||
const vec4 PI_6 = vec4(PI/6.0);
|
||||
|
||||
float norm_c = 0.0;
|
||||
vec3 yiq = vec3(0.0);
|
||||
yiq.x = chroma_sample(vec2(0,0)).x;
|
||||
for (int i = -width/2; i <= width/2; i++) {
|
||||
// Hamming window
|
||||
const float alpha = 0.54;
|
||||
const float beta = 0.46;
|
||||
float window = alpha - beta * cos(2.0*PI/(width-1)*(width/2+i));
|
||||
|
||||
float chromafilt = 2.0*bw_c*sinc(2.0*PI*bw_c*i);
|
||||
|
||||
vec3 samp = chroma_sample(vec2(i,0));
|
||||
float filt = window*chromafilt;
|
||||
yiq.yz += samp.yz*vec2(filt);
|
||||
norm_c += filt;
|
||||
}
|
||||
|
||||
yiq *= vec3(1.0, 1.0/norm_c, 1.0/norm_c);
|
||||
|
||||
FragColor = vec4(dot(yiq, vec3(1.0, 0.946882, 0.623557)),
|
||||
dot(yiq, vec3(1.0,-0.274788,-0.635691)),
|
||||
dot(yiq, vec3(1.0,-1.108545, 1.709007)),
|
||||
0.0);
|
||||
}
|
||||
#endif
|
@ -0,0 +1,189 @@
|
||||
// frequencies are in units of the chroma subcarrier
|
||||
// these are for the lowpass+notch filter
|
||||
#pragma parameter filter_taps "Filter Taps" 15.0 1.0 30.0 1.0
|
||||
#define filtertaps int(filter_taps)
|
||||
#pragma parameter lumacutoff "Luma Cutoff" 0.9 0.1 1.0 0.05
|
||||
#pragma parameter chromacutoff "Chroma Cutoff" 0.3 0.1 1.0 0.05
|
||||
|
||||
#define phase int(FrameCount)
|
||||
|
||||
#if defined(VERTEX)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING out
|
||||
#define COMPAT_ATTRIBUTE in
|
||||
#define COMPAT_TEXTURE texture
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define COMPAT_ATTRIBUTE attribute
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
COMPAT_ATTRIBUTE vec4 VertexCoord;
|
||||
COMPAT_ATTRIBUTE vec4 COLOR;
|
||||
COMPAT_ATTRIBUTE vec4 TexCoord;
|
||||
COMPAT_VARYING vec4 COL0;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
vec4 _oPosition1;
|
||||
uniform mat4 MVPMatrix;
|
||||
uniform COMPAT_PRECISION int FrameDirection;
|
||||
uniform COMPAT_PRECISION int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
|
||||
// compatibility #defines
|
||||
#define vTexCoord TEX0.xy
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVPMatrix * VertexCoord;
|
||||
TEX0.xy = TexCoord.xy;
|
||||
}
|
||||
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#ifdef GL_ES
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING in
|
||||
#define COMPAT_TEXTURE texture
|
||||
out COMPAT_PRECISION vec4 FragColor;
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define FragColor gl_FragColor
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
uniform COMPAT_PRECISION int FrameDirection;
|
||||
uniform COMPAT_PRECISION int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
uniform sampler2D Texture;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
// compatibility #defines
|
||||
#define Source Texture
|
||||
#define texCoord TEX0.xy
|
||||
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
uniform COMPAT_PRECISION float filter_taps, lumacutoff, chromacutoff;
|
||||
#else
|
||||
#define filter_taps 15.0
|
||||
#define lumacutoff 0.9
|
||||
#define chromacutoff 0.3
|
||||
#endif
|
||||
|
||||
vec4 decode_sample(vec2 coord) {
|
||||
const float min = 0.350*0.746;
|
||||
const float max = 1.962;
|
||||
const float black = 0.518;
|
||||
if (coord.x < 0.0 || coord.x > 1.0) return vec4(0.0);
|
||||
return (COMPAT_TEXTURE(Source, coord) * vec4(max-min) + vec4(min-black)) / vec4(max-black);
|
||||
}
|
||||
|
||||
vec4 sinc(vec4 x) {
|
||||
x = max(abs(x),vec4(0.0001));
|
||||
return sin(x)/x;
|
||||
}
|
||||
vec2 sinc(vec2 x) {
|
||||
x = max(abs(x),vec2(0.0001));
|
||||
return sin(x)/x;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
int width = filtertaps;
|
||||
float bw_y = lumacutoff/12.0;
|
||||
float bw_c = chromacutoff/12.0;
|
||||
|
||||
int x = int(floor(texCoord.x*SourceSize.x));
|
||||
int y = int(floor(texCoord.y*SourceSize.y));
|
||||
int p = (x+y+phase) % 3;
|
||||
|
||||
const vec4 one = vec4(1.0);
|
||||
const float PI = 3.14159265359;
|
||||
const vec4 PI_6 = vec4(PI/6.0);
|
||||
|
||||
float norm_y = 0.0;
|
||||
float norm_c = 0.0;
|
||||
vec3 yiq = vec3(0.0);
|
||||
|
||||
vec4 samp = decode_sample(texCoord + vec2((-width/2 )*SourceSize.z,0));
|
||||
vec4 samp2 = decode_sample(texCoord + vec2((-width/2+1)*SourceSize.z,0));
|
||||
// Hamming window
|
||||
const float alpha = 0.54;
|
||||
const float beta = 0.46;
|
||||
int i;
|
||||
for (i = -width/2; i <= width/2-2; i++) {
|
||||
vec4 window = vec4(alpha) - vec4(beta) * cos(vec4(2.0*PI/(4*width-7))*(vec4(4*(width/2+i))+vec4(0,1,2,3)));
|
||||
|
||||
vec4 t = vec4(i*4)+vec4(-1.5,-0.5,+0.5,+1.5);
|
||||
#define lowpass(freq,x) vec4(2.0*(freq))*sinc(vec4(2.0*PI*(freq))*(x))
|
||||
vec4 lumafilt = lowpass(bw_y, t);
|
||||
vec4 chromafilt = lowpass(bw_c, t);
|
||||
#undef lowpass
|
||||
|
||||
vec4 samp3 = decode_sample(texCoord + vec2((i+2)*SourceSize.z,0));
|
||||
vec4 rsamp = vec4(samp2.zw, samp3.xy);
|
||||
vec4 filt = window*lumafilt;
|
||||
yiq.x += dot(samp, filt) + dot(rsamp,filt);
|
||||
norm_y += dot(one, filt);
|
||||
filt = window*chromafilt;
|
||||
yiq.y += dot(samp, filt*cos((vec4(0,1,2,3)+vec4(4*(i+p)))*PI_6));
|
||||
yiq.y += dot(rsamp,filt*cos((vec4(6,7,8,9)+vec4(4*(i+p)))*PI_6));
|
||||
yiq.z += dot(samp, filt*sin((vec4(0,1,2,3)+vec4(4*(i+p)))*PI_6));
|
||||
yiq.z += dot(rsamp,filt*sin((vec4(6,7,8,9)+vec4(4*(i+p)))*PI_6));
|
||||
norm_c += dot(one,filt);
|
||||
|
||||
samp = samp2;
|
||||
samp2 = samp3;
|
||||
}
|
||||
vec2 window = vec2(alpha) - vec2(beta) * cos(vec2(2.0*PI/(4*width-7))*(vec2(4*(width/2+i))+vec2(0,1)));
|
||||
vec2 t = vec2(i*4)+vec2(-1.5,-0.5);
|
||||
|
||||
#define lowpass(freq,x) vec2(2.0*(freq))*sinc(vec2(2.0*PI*(freq))*(x))
|
||||
vec2 lumafilt = lowpass(bw_y, t);
|
||||
vec2 chromafilt = lowpass(bw_c, t);
|
||||
#undef lowpass
|
||||
vec2 filt = window*lumafilt;
|
||||
yiq.x += dot(samp.xy, filt) + dot(samp2.zw, filt);
|
||||
norm_y += dot(one.xy, filt);
|
||||
filt = window*chromafilt;
|
||||
yiq.y += dot(samp.xy, filt*cos((vec2(0,1)+vec2(4*(i+p)))*vec2(PI/6.0)));
|
||||
yiq.y += dot(samp2.zw,filt*cos((vec2(6,7)+vec2(4*(i+p)))*vec2(PI/6.0)));
|
||||
yiq.z += dot(samp.xy, filt*sin((vec2(0,1)+vec2(4*(i+p)))*vec2(PI/6.0)));
|
||||
yiq.z += dot(samp2.zw,filt*sin((vec2(6,7)+vec2(4*(i+p)))*vec2(PI/6.0)));
|
||||
norm_c += dot(one.xy, filt);
|
||||
|
||||
yiq *= vec3(0.5/norm_y, 1.0/norm_c, 1.0/norm_c);
|
||||
|
||||
//FragColor = vec4(dot(yiq, vec3(1.0, 0.946882, 0.623557)),
|
||||
// dot(yiq, vec3(1.0,-0.274788,-0.635691)),
|
||||
// dot(yiq, vec3(1.0,-1.108545, 1.709007)),
|
||||
// 0.0);
|
||||
FragColor = vec4(yiq+vec3(0,0.5,0.5),0.0);
|
||||
}
|
||||
#endif
|
Before Width: | Height: | Size: 849 B After Width: | Height: | Size: 849 B |
Loading…
Reference in New Issue
Block a user