2018-06-15 15:22:09 +00:00
|
|
|
vec4 scale2x(sampler2D image, vec2 position, vec2 input_resolution, vec2 output_resolution)
|
2016-04-28 20:07:05 +00:00
|
|
|
{
|
|
|
|
// o = offset, the width of a pixel
|
2018-06-15 15:08:54 +00:00
|
|
|
vec2 o = 1.0 / input_resolution;
|
2016-04-28 20:07:05 +00:00
|
|
|
// texel arrangement
|
|
|
|
// A B C
|
|
|
|
// D E F
|
|
|
|
// G H I
|
2018-06-15 15:08:54 +00:00
|
|
|
vec4 A = texture(image, position + vec2( -o.x, o.y));
|
|
|
|
vec4 B = texture(image, position + vec2( 0, o.y));
|
|
|
|
vec4 C = texture(image, position + vec2( o.x, o.y));
|
|
|
|
vec4 D = texture(image, position + vec2( -o.x, 0));
|
|
|
|
vec4 E = texture(image, position + vec2( 0, 0));
|
|
|
|
vec4 F = texture(image, position + vec2( o.x, 0));
|
|
|
|
vec4 G = texture(image, position + vec2( -o.x, -o.y));
|
|
|
|
vec4 H = texture(image, position + vec2( 0, -o.y));
|
|
|
|
vec4 I = texture(image, position + vec2( o.x, -o.y));
|
|
|
|
vec2 p = position * input_resolution;
|
2016-04-28 20:07:05 +00:00
|
|
|
// p = the position within a pixel [0...1]
|
|
|
|
p = fract(p);
|
|
|
|
if (p.x > .5) {
|
|
|
|
if (p.y > .5) {
|
|
|
|
// Top Right
|
|
|
|
return B == F && B != D && F != H ? F : E;
|
|
|
|
} else {
|
|
|
|
// Bottom Right
|
|
|
|
return H == F && D != H && B != F ? F : E;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (p.y > .5) {
|
|
|
|
// Top Left
|
|
|
|
return D == B && B != F && D != H ? D : E;
|
|
|
|
} else {
|
|
|
|
// Bottom Left
|
|
|
|
return D == H && D != B && H != F ? D : E;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-15 15:22:09 +00:00
|
|
|
vec4 aaScale2x(sampler2D image, vec2 position, vec2 input_resolution, vec2 output_resolution)
|
2016-04-28 20:07:05 +00:00
|
|
|
{
|
2018-06-15 15:22:09 +00:00
|
|
|
return mix(texture(image, position), scale2x(image, position, input_resolution, output_resolution), 0.5);
|
2016-04-28 20:07:05 +00:00
|
|
|
}
|
|
|
|
|
2018-06-15 15:22:09 +00:00
|
|
|
vec4 scale(sampler2D image, vec2 position, vec2 input_resolution, vec2 output_resolution)
|
2016-04-28 20:07:05 +00:00
|
|
|
{
|
|
|
|
// o = offset, the width of a pixel
|
2018-06-15 15:08:54 +00:00
|
|
|
vec2 o = 1.0 / (input_resolution * 2.);
|
|
|
|
|
2016-04-28 20:07:05 +00:00
|
|
|
// texel arrangement
|
|
|
|
// A B C
|
|
|
|
// D E F
|
|
|
|
// G H I
|
2018-06-15 15:22:09 +00:00
|
|
|
vec4 A = aaScale2x(image, position + vec2( -o.x, o.y), input_resolution, output_resolution);
|
|
|
|
vec4 B = aaScale2x(image, position + vec2( 0, o.y), input_resolution, output_resolution);
|
|
|
|
vec4 C = aaScale2x(image, position + vec2( o.x, o.y), input_resolution, output_resolution);
|
|
|
|
vec4 D = aaScale2x(image, position + vec2( -o.x, 0), input_resolution, output_resolution);
|
|
|
|
vec4 E = aaScale2x(image, position + vec2( 0, 0), input_resolution, output_resolution);
|
|
|
|
vec4 F = aaScale2x(image, position + vec2( o.x, 0), input_resolution, output_resolution);
|
|
|
|
vec4 G = aaScale2x(image, position + vec2( -o.x, -o.y), input_resolution, output_resolution);
|
|
|
|
vec4 H = aaScale2x(image, position + vec2( 0, -o.y), input_resolution, output_resolution);
|
|
|
|
vec4 I = aaScale2x(image, position + vec2( o.x, -o.y), input_resolution, output_resolution);
|
2016-04-28 20:07:05 +00:00
|
|
|
vec4 R;
|
2018-06-15 15:08:54 +00:00
|
|
|
vec2 p = position * input_resolution * 2.;
|
2016-04-28 20:07:05 +00:00
|
|
|
// p = the position within a pixel [0...1]
|
|
|
|
p = fract(p);
|
|
|
|
if (p.x > .5) {
|
|
|
|
if (p.y > .5) {
|
|
|
|
// Top Right
|
|
|
|
R = B == F && B != D && F != H ? F : E;
|
|
|
|
} else {
|
|
|
|
// Bottom Right
|
|
|
|
R = H == F && D != H && B != F ? F : E;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (p.y > .5) {
|
|
|
|
// Top Left
|
|
|
|
R = D == B && B != F && D != H ? D : E;
|
|
|
|
} else {
|
|
|
|
// Bottom Left
|
|
|
|
R = D == H && D != B && H != F ? D : E;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mix(R, E, 0.5);
|
2018-06-15 15:08:54 +00:00
|
|
|
}
|