partially working hq2x, may not work on macOS tho

This commit is contained in:
minjaesong
2023-07-21 20:29:17 +09:00
parent 0af2e57368
commit 91d94d2dab
8 changed files with 268 additions and 96 deletions

View File

@@ -1,24 +1,24 @@
// This float value should be defined from the compiling code.
// #define SCALE [2, 3, 4].0
#version 150
#ifdef GL_ES
precision mediump float;
#define PRECISION mediump
precision PRECISION float;
precision PRECISION int;
#else
#define PRECISION
#endif
#define SCALE 2.0
uniform sampler2D u_texture;
uniform sampler2D u_lut;
uniform vec2 u_textureSize;
in vec4 v_texCoord[4];
varying vec4 v_texCoord[4];
const mat3 YUV_MATRIX = mat3(0.299, 0.587, 0.114, -0.169, -0.331, 0.5, 0.5, -0.419, -0.081);
const vec3 YUV_THRESHOLD = vec3(48.0/255.0, 7.0/255.0, 6.0/255.0);
const vec3 YUV_OFFSET = vec3(0, 0.5, 0.5);
out vec4 fragColor;
bool diff(vec3 yuv1, vec3 yuv2) {
return any(greaterThan(abs((yuv1 + YUV_OFFSET) - (yuv2 + YUV_OFFSET)), YUV_THRESHOLD));
}
@@ -41,24 +41,24 @@ void main() {
float dx = v_texCoord[0].z;
float dy = v_texCoord[0].w;
vec3 p1 = texture(u_texture, v_texCoord[0].xy).rgb;
vec3 p2 = texture(u_texture, v_texCoord[0].xy + vec2(dx, dy) * quad).rgb;
vec3 p3 = texture(u_texture, v_texCoord[0].xy + vec2(dx, 0) * quad).rgb;
vec3 p4 = texture(u_texture, v_texCoord[0].xy + vec2(0, dy) * quad).rgb;
vec3 p1 = texture2D(u_texture, v_texCoord[0].xy).rgb;
vec3 p2 = texture2D(u_texture, v_texCoord[0].xy + vec2(dx, dy) * quad).rgb;
vec3 p3 = texture2D(u_texture, v_texCoord[0].xy + vec2(dx, 0) * quad).rgb;
vec3 p4 = texture2D(u_texture, v_texCoord[0].xy + vec2(0, dy) * quad).rgb;
// Use mat4 instead of mat4x3 here to support GLES.
mat4 pixels = mat4(vec4(p1, 0.0), vec4(p2, 0.0), vec4(p3, 0.0), vec4(p4, 0.0));
vec3 w1 = yuv * texture(u_texture, v_texCoord[1].xw).rgb;
vec3 w2 = yuv * texture(u_texture, v_texCoord[1].yw).rgb;
vec3 w3 = yuv * texture(u_texture, v_texCoord[1].zw).rgb;
vec3 w1 = yuv * texture2D(u_texture, v_texCoord[1].xw).rgb;
vec3 w2 = yuv * texture2D(u_texture, v_texCoord[1].yw).rgb;
vec3 w3 = yuv * texture2D(u_texture, v_texCoord[1].zw).rgb;
vec3 w4 = yuv * texture(u_texture, v_texCoord[2].xw).rgb;
vec3 w4 = yuv * texture2D(u_texture, v_texCoord[2].xw).rgb;
vec3 w5 = yuv * p1;
vec3 w6 = yuv * texture(u_texture, v_texCoord[2].zw).rgb;
vec3 w6 = yuv * texture2D(u_texture, v_texCoord[2].zw).rgb;
vec3 w7 = yuv * texture(u_texture, v_texCoord[3].xw).rgb;
vec3 w8 = yuv * texture(u_texture, v_texCoord[3].yw).rgb;
vec3 w9 = yuv * texture(u_texture, v_texCoord[3].zw).rgb;
vec3 w7 = yuv * texture2D(u_texture, v_texCoord[3].xw).rgb;
vec3 w8 = yuv * texture2D(u_texture, v_texCoord[3].yw).rgb;
vec3 w9 = yuv * texture2D(u_texture, v_texCoord[3].zw).rgb;
bvec3 pattern[3];
pattern[0] = bvec3(diff(w5, w1), diff(w5, w2), diff(w5, w3));
@@ -75,13 +75,9 @@ void main() {
vec2 step = vec2(1.0) / vec2(256.0, 16.0 * (SCALE * SCALE));
vec2 offset = step / vec2(2.0);
vec4 weights = texture(u_lut, index * step + offset);
vec4 weights = texture2D(u_lut, index * step + offset);
float sum = dot(weights, vec4(1));
vec3 res = (pixels * (weights / sum)).rgb;
fragColor = vec4(res.rgb, 1.0);
// fragColor = vec4(v_texCoord[0].x, v_texCoord[0].y, 0.0, 1.0);
gl_FragColor.rgb = res;
}

BIN
src/shaders/hq2x.png LFS Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -1,26 +1,25 @@
#version 150
#ifdef GL_ES
precision mediump float;
#define PRECISION mediump
precision PRECISION float;
precision PRECISION int;
#else
#define PRECISION
#endif
#define SCALE 1.0
in vec4 a_position;
in vec2 a_texCoord0;
attribute vec4 a_position;
attribute vec2 a_texCoord0;
uniform mat4 u_projTrans;
uniform vec2 u_textureSize;
out vec2 u_textureSize;
out vec4 v_texCoord[4];
varying vec4 v_texCoord[4];
void main() {
gl_Position = u_projTrans * a_position / SCALE;
gl_Position = a_position;
vec2 ps = 1.0/u_textureSize;
float dx = ps.x;
float dy = ps.y;
vec2 a_texCoord00 = a_texCoord0 / SCALE;
// +----+----+----+
// | | | |
// | w1 | w2 | w3 |
@@ -33,8 +32,8 @@ void main() {
// +----+----+----+
v_texCoord[0].zw = ps;
v_texCoord[0].xy = a_texCoord00.xy;
v_texCoord[1] = a_texCoord00.xxxy + vec4(-dx, 0, dx, -dy); // w1 | w2 | w3
v_texCoord[2] = a_texCoord00.xxxy + vec4(-dx, 0, dx, 0); // w4 | w5 | w6
v_texCoord[3] = a_texCoord00.xxxy + vec4(-dx, 0, dx, dy); // w7 | w8 | w9
v_texCoord[0].xy = a_texCoord0.xy;
v_texCoord[1] = a_texCoord0.xxxy + vec4(-dx, 0, dx, -dy); // w1 | w2 | w3
v_texCoord[2] = a_texCoord0.xxxy + vec4(-dx, 0, dx, 0); // w4 | w5 | w6
v_texCoord[3] = a_texCoord0.xxxy + vec4(-dx, 0, dx, dy); // w7 | w8 | w9
}

BIN
src/shaders/hq3x.png LFS Normal file

Binary file not shown.

BIN
src/shaders/hq4x.png LFS Normal file

Binary file not shown.