Added HQ2x shader, upgrading to OpenGL 3

This commit is contained in:
Lior Halphon 2016-06-14 14:11:37 +03:00
parent 8153b765a2
commit 52afba21d1
15 changed files with 224 additions and 85 deletions

View File

@ -23,6 +23,7 @@
@"Scale4x",
@"AAScale2x",
@"AAScale4x",
@"HQ2x",
@"OmniScale",
@"AAOmniScale",
];

View File

@ -1,15 +1,18 @@
#import "GBShader.h"
#import <OpenGL/gl.h>
#import <OpenGL/gl3.h>
/*
Loosely based of https://www.raywenderlich.com/70208/opengl-es-pixel-shaders-tutorial
This code probably makes no sense after I upgraded it to OpenGL 3, since OpenGL makes aboslute no sense and has zero
helpful documentation.
*/
static NSString * const vertex_shader = @"\n\
attribute vec2 aPosition;\n\
\n\
#version 150 \n\
in vec4 aPosition;\n\
void main(void) {\n\
gl_Position = vec4(aPosition, 0., 1.);\n\
gl_Position = aPosition;\n\
}\n\
";
@ -69,8 +72,9 @@ void main(void) {\n\
mix_previous_uniform = glGetUniformLocation(program, "uMixPrevious");
// Configure OpenGL ES
[self configureOpenGLES];
// Configure OpenGL
[self configureOpenGL];
}
return self;
}
@ -90,23 +94,38 @@ void main(void) {\n\
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 160, 144, 0, GL_RGBA, GL_UNSIGNED_BYTE, previous);
glUniform1i(previous_texture_uniform, 1);
}
glBindFragDataLocation(program, 0, "frag_color");
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
- (void)configureOpenGLES
- (void)configureOpenGL
{
// Program
glUseProgram(program);
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
GLuint vbo;
glGenBuffers(1, &vbo);
// Attributes
glEnableVertexAttribArray(position_attribute);
static GLfloat const quad[8] = {
-1.f, -1.f,
-1.f, +1.f,
+1.f, -1.f,
+1.f, +1.f,
static GLfloat const quad[16] = {
-1.f, -1.f, 0, 1,
-1.f, +1.f, 0, 1,
+1.f, -1.f, 0, 1,
+1.f, +1.f, 0, 1,
};
glVertexAttribPointer(position_attribute, 2, GL_FLOAT, GL_FALSE, 0, quad);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(quad), quad, GL_STATIC_DRAW);
glEnableVertexAttribArray(position_attribute);
glVertexAttribPointer(position_attribute, 4, GL_FLOAT, GL_FALSE, 0, 0);
}
+ (GLuint)programWithVertexShader:(NSString*)vsh fragmentShader:(NSString*)fsh
@ -129,7 +148,6 @@ void main(void) {\n\
glGetProgramInfoLog(program, sizeof(messages), 0, &messages[0]);
NSLog(@"%@:- GLSL Program Error: %s", self, messages);
}
// Delete shaders
glDeleteShader(vertex_shader);
glDeleteShader(fragment_shader);
@ -162,7 +180,6 @@ void main(void) {\n\
glGetShaderInfoLog(shader, sizeof(messages), 0, &messages[0]);
NSLog(@"%@:- GLSL Shader Error: %s", self, messages);
}
return shader;
}

View File

@ -12,6 +12,30 @@ static GBShader *shader = nil;
unsigned char current_buffer;
}
- (void) awakeFromNib
{
NSOpenGLPixelFormatAttribute attrs[] =
{
NSOpenGLPFAOpenGLProfile,
NSOpenGLProfileVersion3_2Core,
0
};
NSOpenGLPixelFormat *pf = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs] ;
if (!pf)
{
NSLog(@"No OpenGL pixel format");
}
NSOpenGLContext* context = [[NSOpenGLContext alloc] initWithFormat:pf shareContext:nil] ;
[self setPixelFormat:pf];
[self setOpenGLContext:context];
}
- (void) _init
{
image_buffers[0] = malloc(160 * 144 * 4);

View File

@ -38,7 +38,7 @@
</textField>
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="6pP-kK-EEC">
<rect key="frame" x="30" y="223" width="245" height="26"/>
<popUpButtonCell key="cell" type="push" title="Nearest Neighbor (Pixelated)" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="neN-eo-LA7" id="I1w-05-lGl">
<popUpButtonCell key="cell" type="push" title="HQ2x" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="gxB-Uj-wp2" id="I1w-05-lGl">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="xDC-0T-Qg9">
@ -54,6 +54,7 @@
<menuItem title="Anti-aliased Scale4x" id="zJR-ER-Ygo">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="HQ2x" state="on" id="gxB-Uj-wp2"/>
<menuItem title="OmniScale (Beta, any factor)" id="doe-kf-quG">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>

View File

@ -8,10 +8,10 @@ vec4 omniScale(sampler2D image, vec2 texCoord)
{
vec2 pixel = texCoord * textureDimensions - vec2(0.5, 0.5);
vec4 q11 = texture2D(image, vec2(floor(pixel.x) / textureDimensions.x, floor(pixel.y) / textureDimensions.y));
vec4 q12 = texture2D(image, vec2(floor(pixel.x) / textureDimensions.x, ceil(pixel.y) / textureDimensions.y));
vec4 q21 = texture2D(image, vec2(ceil(pixel.x) / textureDimensions.x, floor(pixel.y) / textureDimensions.y));
vec4 q22 = texture2D(image, vec2(ceil(pixel.x) / textureDimensions.x, ceil(pixel.y) / textureDimensions.y));
vec4 q11 = texture(image, vec2(floor(pixel.x) / textureDimensions.x, floor(pixel.y) / textureDimensions.y));
vec4 q12 = texture(image, vec2(floor(pixel.x) / textureDimensions.x, ceil(pixel.y) / textureDimensions.y));
vec4 q21 = texture(image, vec2(ceil(pixel.x) / textureDimensions.x, floor(pixel.y) / textureDimensions.y));
vec4 q22 = texture(image, vec2(ceil(pixel.x) / textureDimensions.x, ceil(pixel.y) / textureDimensions.y));
vec2 pos = fract(pixel);
@ -25,7 +25,7 @@ vec4 omniScale(sampler2D image, vec2 texCoord)
int diagonalBias = 0;
for (float y = -1.0; y < 3.0; y++) {
for (float x = -1.0; x < 3.0; x++) {
vec4 color = texture2D(image, (pixel + vec2(x, y)) / textureDimensions);
vec4 color = texture(image, (pixel + vec2(x, y)) / textureDimensions);
if (color == q11) diagonalBias++;
if (color == q12) diagonalBias--;
}
@ -104,7 +104,7 @@ vec4 omniScale(sampler2D image, vec2 texCoord)
return q22;
}
vec4 filter(sampler2D image)
vec4 scale(sampler2D image)
{
vec2 texCoord = vec2(gl_FragCoord.x, uResolution.y - gl_FragCoord.y) / uResolution;
vec2 pixel = vec2(1.0, 1.0) / uResolution;

View File

@ -8,15 +8,15 @@ vec4 scale2x(sampler2D image)
// A B C
// D E F
// G H I
vec4 A = texture2D(image, texCoord + vec2( -o.x, o.y));
vec4 B = texture2D(image, texCoord + vec2( 0, o.y));
vec4 C = texture2D(image, texCoord + vec2( o.x, o.y));
vec4 D = texture2D(image, texCoord + vec2( -o.x, 0));
vec4 E = texture2D(image, texCoord + vec2( 0, 0));
vec4 F = texture2D(image, texCoord + vec2( o.x, 0));
vec4 G = texture2D(image, texCoord + vec2( -o.x, -o.y));
vec4 H = texture2D(image, texCoord + vec2( 0, -o.y));
vec4 I = texture2D(image, texCoord + vec2( o.x, -o.y));
vec4 A = texture(image, texCoord + vec2( -o.x, o.y));
vec4 B = texture(image, texCoord + vec2( 0, o.y));
vec4 C = texture(image, texCoord + vec2( o.x, o.y));
vec4 D = texture(image, texCoord + vec2( -o.x, 0));
vec4 E = texture(image, texCoord + vec2( 0, 0));
vec4 F = texture(image, texCoord + vec2( o.x, 0));
vec4 G = texture(image, texCoord + vec2( -o.x, -o.y));
vec4 H = texture(image, texCoord + vec2( 0, -o.y));
vec4 I = texture(image, texCoord + vec2( o.x, -o.y));
vec2 p = texCoord * textureDimensions;
// p = the position within a pixel [0...1]
p = fract(p);
@ -39,9 +39,9 @@ vec4 scale2x(sampler2D image)
}
}
vec4 filter(sampler2D image)
vec4 scale(sampler2D image)
{
vec2 texCoord = vec2(gl_FragCoord.x, uResolution.y - gl_FragCoord.y) / uResolution;
return mix(texture2D(image, texCoord), scale2x(image), 0.5);
return mix(texture(image, texCoord), scale2x(image), 0.5);
}

View File

@ -6,15 +6,15 @@ vec4 scale2x(sampler2D image, vec2 texCoord)
// A B C
// D E F
// G H I
vec4 A = texture2D(image, texCoord + vec2( -o.x, o.y));
vec4 B = texture2D(image, texCoord + vec2( 0, o.y));
vec4 C = texture2D(image, texCoord + vec2( o.x, o.y));
vec4 D = texture2D(image, texCoord + vec2( -o.x, 0));
vec4 E = texture2D(image, texCoord + vec2( 0, 0));
vec4 F = texture2D(image, texCoord + vec2( o.x, 0));
vec4 G = texture2D(image, texCoord + vec2( -o.x, -o.y));
vec4 H = texture2D(image, texCoord + vec2( 0, -o.y));
vec4 I = texture2D(image, texCoord + vec2( o.x, -o.y));
vec4 A = texture(image, texCoord + vec2( -o.x, o.y));
vec4 B = texture(image, texCoord + vec2( 0, o.y));
vec4 C = texture(image, texCoord + vec2( o.x, o.y));
vec4 D = texture(image, texCoord + vec2( -o.x, 0));
vec4 E = texture(image, texCoord + vec2( 0, 0));
vec4 F = texture(image, texCoord + vec2( o.x, 0));
vec4 G = texture(image, texCoord + vec2( -o.x, -o.y));
vec4 H = texture(image, texCoord + vec2( 0, -o.y));
vec4 I = texture(image, texCoord + vec2( o.x, -o.y));
vec2 p = texCoord * textureDimensions;
// p = the position within a pixel [0...1]
p = fract(p);
@ -39,10 +39,10 @@ vec4 scale2x(sampler2D image, vec2 texCoord)
vec4 aaScale2x(sampler2D image, vec2 texCoord)
{
return mix(texture2D(image, texCoord), scale2x(image, texCoord), 0.5);
return mix(texture(image, texCoord), scale2x(image, texCoord), 0.5);
}
vec4 filter(sampler2D image)
vec4 scale(sampler2D image)
{
// o = offset, the width of a pixel
vec2 o = 1.0 / (textureDimensions * 2.);

View File

@ -1,13 +1,13 @@
vec4 filter(sampler2D image)
vec4 scale(sampler2D image)
{
vec2 texCoord = vec2(gl_FragCoord.x, uResolution.y - gl_FragCoord.y) / uResolution;
vec2 pixel = texCoord * textureDimensions - vec2(0.5, 0.5);
vec4 q11 = texture2D(image, vec2(floor(pixel.x) / textureDimensions.x, floor(pixel.y) / textureDimensions.y));
vec4 q12 = texture2D(image, vec2(floor(pixel.x) / textureDimensions.x, ceil(pixel.y) / textureDimensions.y));
vec4 q21 = texture2D(image, vec2(ceil(pixel.x) / textureDimensions.x, floor(pixel.y) / textureDimensions.y));
vec4 q22 = texture2D(image, vec2(ceil(pixel.x) / textureDimensions.x, ceil(pixel.y) / textureDimensions.y));
vec4 q11 = texture(image, vec2(floor(pixel.x) / textureDimensions.x, floor(pixel.y) / textureDimensions.y));
vec4 q12 = texture(image, vec2(floor(pixel.x) / textureDimensions.x, ceil(pixel.y) / textureDimensions.y));
vec4 q21 = texture(image, vec2(ceil(pixel.x) / textureDimensions.x, floor(pixel.y) / textureDimensions.y));
vec4 q22 = texture(image, vec2(ceil(pixel.x) / textureDimensions.x, ceil(pixel.y) / textureDimensions.y));
vec4 r1 = mix(q11, q21, fract(pixel.x));
vec4 r2 = mix(q12, q22, fract(pixel.x));

93
Shaders/HQ2x.fsh Normal file
View File

@ -0,0 +1,93 @@
/* Based on this (really good) article: http://blog.pkh.me/p/19-butchering-hqx-scaling-filters.html */
/* Todo: Add the real YUV difference from HQ2x*/
bool is_different(vec4 a, vec4 b)
{
return length(a - b) > 0.15;
}
#define P(m, r) ((pattern & (m)) == (r))
vec4 interp_2px(vec4 c1, float w1, vec4 c2, float w2)
{
return (c1 * w1 + c2 * w2) / (w1 + w2);
}
vec4 interp_3px(vec4 c1, float w1, vec4 c2, float w2, vec4 c3, float w3)
{
return (c1 * w1 + c2 * w2 + c3 * w3) / (w1 + w2 + w3);
}
vec4 scale(sampler2D image)
{
// o = offset, the width of a pixel
vec2 o = 1.0 / textureDimensions;
vec2 texCoord = vec2(gl_FragCoord.x, uResolution.y - gl_FragCoord.y) / uResolution;
/* We always calculate the top left pixel. If we need a different pixel, we flip the image */
// p = the position within a pixel [0...1]
vec2 p = fract(texCoord * textureDimensions);
if (p.x > 0.5) o.x = -o.x;
if (p.y > 0.5) o.y = -o.y;
vec4 w0 = texture(image, texCoord + vec2( -o.x, -o.y));
vec4 w1 = texture(image, texCoord + vec2( 0, -o.y));
vec4 w2 = texture(image, texCoord + vec2( o.x, -o.y));
vec4 w3 = texture(image, texCoord + vec2( -o.x, 0));
vec4 w4 = texture(image, texCoord + vec2( 0, 0));
vec4 w5 = texture(image, texCoord + vec2( o.x, 0));
vec4 w6 = texture(image, texCoord + vec2( -o.x, o.y));
vec4 w7 = texture(image, texCoord + vec2( 0, o.y));
vec4 w8 = texture(image, texCoord + vec2( o.x, o.y));
int pattern = 0;
if (is_different(w0, w4)) pattern |= 1;
if (is_different(w1, w4)) pattern |= 2;
if (is_different(w2, w4)) pattern |= 4;
if (is_different(w3, w4)) pattern |= 8;
if (is_different(w5, w4)) pattern |= 16;
if (is_different(w6, w4)) pattern |= 32;
if (is_different(w7, w4)) pattern |= 64;
if (is_different(w8, w4)) pattern |= 128;
if ((P(0xbf,0x37) || P(0xdb,0x13)) && is_different(w1, w5))
return interp_2px(w4, 3.0, w3, 1.0);
if ((P(0xdb,0x49) || P(0xef,0x6d)) && is_different(w7, w3))
return interp_2px(w4, 3.0, w1, 1.0);
if ((P(0x0b,0x0b) || P(0xfe,0x4a) || P(0xfe,0x1a)) && is_different(w3, w1))
return w4;
if ((P(0x6f,0x2a) || P(0x5b,0x0a) || P(0xbf,0x3a) || P(0xdf,0x5a) ||
P(0x9f,0x8a) || P(0xcf,0x8a) || P(0xef,0x4e) || P(0x3f,0x0e) ||
P(0xfb,0x5a) || P(0xbb,0x8a) || P(0x7f,0x5a) || P(0xaf,0x8a) ||
P(0xeb,0x8a)) && is_different(w3, w1))
return interp_2px(w4, 3.0, w0, 1.0);
if (P(0x0b,0x08))
return interp_3px(w4, 2.0, w0, 1.0, w1, 1.0);
if (P(0x0b,0x02))
return interp_3px(w4, 2.0, w0, 1.0, w3, 1.0);
if (P(0x2f,0x2f))
return interp_3px(w4, 1.04, w3, 1.0, w1, 1.0);
if (P(0xbf,0x37) || P(0xdb,0x13))
return interp_3px(w4, 5.0, w1, 2.0, w3, 1.0);
if (P(0xdb,0x49) || P(0xef,0x6d))
return interp_3px(w4, 5.0, w3, 2.0, w1, 1.0);
if (P(0x1b,0x03) || P(0x4f,0x43) || P(0x8b,0x83) || P(0x6b,0x43))
return interp_2px(w4, 3.0, w3, 1.0);
if (P(0x4b,0x09) || P(0x8b,0x89) || P(0x1f,0x19) || P(0x3b,0x19))
return interp_2px(w4, 3.0, w1, 1.0);
if (P(0x7e,0x2a) || P(0xef,0xab) || P(0xbf,0x8f) || P(0x7e,0x0e))
return interp_3px(w4, 2.0, w3, 3.0, w1, 3.0);
if (P(0xfb,0x6a) || P(0x6f,0x6e) || P(0x3f,0x3e) || P(0xfb,0xfa) ||
P(0xdf,0xde) || P(0xdf,0x1e))
return interp_2px(w4, 3.0, w0, 1.0);
if (P(0x0a,0x00) || P(0x4f,0x4b) || P(0x9f,0x1b) || P(0x2f,0x0b) ||
P(0xbe,0x0a) || P(0xee,0x0a) || P(0x7e,0x0a) || P(0xeb,0x4b) ||
P(0x3b,0x1b))
return interp_3px(w4, 2.0, w3, 1.0, w1, 1.0);
return interp_3px(w4, 6.0, w3, 1.0, w1, 1.0);
}

View File

@ -1,3 +1,4 @@
#version 150
uniform sampler2D image;
uniform sampler2D previousImage;
uniform bool uMixPrevious;
@ -5,14 +6,16 @@ uniform bool uMixPrevious;
uniform vec2 uResolution;
const vec2 textureDimensions = vec2(160, 144);
out vec4 frag_color;
#line 1
{filter}
void main() {
if (uMixPrevious) {
gl_FragColor = mix(filter(image), filter(previousImage), 0.5);
frag_color = mix(scale(image), scale(previousImage), 0.5);
}
else {
gl_FragColor = filter(image);
frag_color = scale(image);
}
}

View File

@ -1,6 +1,6 @@
vec4 filter(sampler2D image)
vec4 scale(sampler2D image)
{
vec2 texCoord = vec2(gl_FragCoord.x, uResolution.y - gl_FragCoord.y) / uResolution;
return texture2D(image, texCoord);
return texture(image, texCoord);
}

View File

@ -4,16 +4,16 @@ float quickDistance(vec4 a, vec4 b)
return abs(a.x - b.x) + abs(a.y - b.y) + abs(a.z - b.z);
}
vec4 filter(sampler2D image)
vec4 scale(sampler2D image)
{
vec2 texCoord = vec2(gl_FragCoord.x, uResolution.y - gl_FragCoord.y) / uResolution;
vec2 pixel = texCoord * textureDimensions - vec2(0.5, 0.5);
vec4 q11 = texture2D(image, (pixel ) / textureDimensions);
vec4 q12 = texture2D(image, (pixel + vec2(0.0, 1.0)) / textureDimensions);
vec4 q21 = texture2D(image, (pixel + vec2(1.0, 0.0)) / textureDimensions);
vec4 q22 = texture2D(image, (pixel + vec2(1.0, 1.0)) / textureDimensions);
vec4 q11 = texture(image, (pixel ) / textureDimensions);
vec4 q12 = texture(image, (pixel + vec2(0.0, 1.0)) / textureDimensions);
vec4 q21 = texture(image, (pixel + vec2(1.0, 0.0)) / textureDimensions);
vec4 q22 = texture(image, (pixel + vec2(1.0, 1.0)) / textureDimensions);
vec2 pos = fract(pixel);
@ -27,7 +27,7 @@ vec4 filter(sampler2D image)
int diagonalBias = 0;
for (float y = -1.0; y < 3.0; y++) {
for (float x = -1.0; x < 3.0; x++) {
vec4 color = texture2D(image, (pixel + vec2(x, y)) / textureDimensions);
vec4 color = texture(image, (pixel + vec2(x, y)) / textureDimensions);
if (color == q11) diagonalBias++;
if (color == q12) diagonalBias--;
}

View File

@ -1,6 +1,6 @@
/* Shader implementation of Scale2x is adapted from https://gist.github.com/singron/3161079 */
vec4 filter(sampler2D image)
vec4 scale(sampler2D image)
{
// o = offset, the width of a pixel
vec2 o = 1.0 / textureDimensions;
@ -10,15 +10,15 @@ vec4 filter(sampler2D image)
// A B C
// D E F
// G H I
vec4 A = texture2D(image, texCoord + vec2( -o.x, o.y));
vec4 B = texture2D(image, texCoord + vec2( 0, o.y));
vec4 C = texture2D(image, texCoord + vec2( o.x, o.y));
vec4 D = texture2D(image, texCoord + vec2( -o.x, 0));
vec4 E = texture2D(image, texCoord + vec2( 0, 0));
vec4 F = texture2D(image, texCoord + vec2( o.x, 0));
vec4 G = texture2D(image, texCoord + vec2( -o.x, -o.y));
vec4 H = texture2D(image, texCoord + vec2( 0, -o.y));
vec4 I = texture2D(image, texCoord + vec2( o.x, -o.y));
vec4 A = texture(image, texCoord + vec2( -o.x, o.y));
vec4 B = texture(image, texCoord + vec2( 0, o.y));
vec4 C = texture(image, texCoord + vec2( o.x, o.y));
vec4 D = texture(image, texCoord + vec2( -o.x, 0));
vec4 E = texture(image, texCoord + vec2( 0, 0));
vec4 F = texture(image, texCoord + vec2( o.x, 0));
vec4 G = texture(image, texCoord + vec2( -o.x, -o.y));
vec4 H = texture(image, texCoord + vec2( 0, -o.y));
vec4 I = texture(image, texCoord + vec2( o.x, -o.y));
vec2 p = texCoord * textureDimensions;
// p = the position within a pixel [0...1]
p = fract(p);

View File

@ -6,15 +6,15 @@ vec4 scale2x(sampler2D image, vec2 texCoord)
// A B C
// D E F
// G H I
vec4 A = texture2D(image, texCoord + vec2( -o.x, o.y));
vec4 B = texture2D(image, texCoord + vec2( 0, o.y));
vec4 C = texture2D(image, texCoord + vec2( o.x, o.y));
vec4 D = texture2D(image, texCoord + vec2( -o.x, 0));
vec4 E = texture2D(image, texCoord + vec2( 0, 0));
vec4 F = texture2D(image, texCoord + vec2( o.x, 0));
vec4 G = texture2D(image, texCoord + vec2( -o.x, -o.y));
vec4 H = texture2D(image, texCoord + vec2( 0, -o.y));
vec4 I = texture2D(image, texCoord + vec2( o.x, -o.y));
vec4 A = texture(image, texCoord + vec2( -o.x, o.y));
vec4 B = texture(image, texCoord + vec2( 0, o.y));
vec4 C = texture(image, texCoord + vec2( o.x, o.y));
vec4 D = texture(image, texCoord + vec2( -o.x, 0));
vec4 E = texture(image, texCoord + vec2( 0, 0));
vec4 F = texture(image, texCoord + vec2( o.x, 0));
vec4 G = texture(image, texCoord + vec2( -o.x, -o.y));
vec4 H = texture(image, texCoord + vec2( 0, -o.y));
vec4 I = texture(image, texCoord + vec2( o.x, -o.y));
vec2 p = texCoord * textureDimensions;
// p = the position within a pixel [0...1]
vec4 R;
@ -38,7 +38,7 @@ vec4 scale2x(sampler2D image, vec2 texCoord)
}
}
vec4 filter(sampler2D image)
vec4 scale(sampler2D image)
{
// o = offset, the width of a pixel
vec2 o = 1.0 / (textureDimensions * 2.);

View File

@ -1,13 +1,13 @@
vec4 filter(sampler2D image)
vec4 scale(sampler2D image)
{
vec2 texCoord = vec2(gl_FragCoord.x, uResolution.y - gl_FragCoord.y) / uResolution;
vec2 pixel = texCoord * textureDimensions - vec2(0.5, 0.5);
vec4 q11 = texture2D(image, vec2(floor(pixel.x) / textureDimensions.x, floor(pixel.y) / textureDimensions.y));
vec4 q12 = texture2D(image, vec2(floor(pixel.x) / textureDimensions.x, ceil(pixel.y) / textureDimensions.y));
vec4 q21 = texture2D(image, vec2(ceil(pixel.x) / textureDimensions.x, floor(pixel.y) / textureDimensions.y));
vec4 q22 = texture2D(image, vec2(ceil(pixel.x) / textureDimensions.x, ceil(pixel.y) / textureDimensions.y));
vec4 q11 = texture(image, vec2(floor(pixel.x) / textureDimensions.x, floor(pixel.y) / textureDimensions.y));
vec4 q12 = texture(image, vec2(floor(pixel.x) / textureDimensions.x, ceil(pixel.y) / textureDimensions.y));
vec4 q21 = texture(image, vec2(ceil(pixel.x) / textureDimensions.x, floor(pixel.y) / textureDimensions.y));
vec4 q22 = texture(image, vec2(ceil(pixel.x) / textureDimensions.x, ceil(pixel.y) / textureDimensions.y));
vec2 smooth = smoothstep(0., 1., fract(pixel));