It works!

This commit is contained in:
Benjamin Schaaf
2021-04-15 23:14:20 +10:00
parent aa8b2409d9
commit 337526e9b9
19 changed files with 1230 additions and 675 deletions

11
data/blit.frag Normal file
View File

@@ -0,0 +1,11 @@
precision mediump float;
uniform sampler2D texture;
varying vec2 uv;
#define fetch(p) texture2D(texture, p).r
void main() {
gl_FragColor = texture2D(texture, uv);
}

12
data/blit.vert Normal file
View File

@@ -0,0 +1,12 @@
precision mediump float;
attribute vec2 vert;
attribute vec2 tex_coord;
varying vec2 uv;
void main() {
uv = tex_coord;
gl_Position = vec4(vert, 0, 1);
}

View File

@@ -1,36 +1,43 @@
precision mediump float;
precision highp float;
uniform sampler2D texture;
// uniform sampler2D srgb_map;
uniform sampler2D pixel_layout;
uniform mat3 color_matrix;
varying vec2 uv1;
varying vec2 uv2;
varying vec2 pixel_coord;
uniform vec2 pixel_size;
// varying vec2 uv1;
// varying vec2 uv2;
varying vec2 top_left_uv;
varying vec2 top_right_uv;
varying vec2 bottom_left_uv;
varying vec2 bottom_right_uv;
varying vec2 half_pixel_coord;
#define fetch(p) texture2D(texture, p).r
void main() {
vec4 pixels = vec4(
fetch(uv1),
fetch(vec2(uv1.x, uv2.y)),
fetch(uv2),
fetch(vec2(uv2.x, uv1.y)));
fetch(top_left_uv),
fetch(top_right_uv),
fetch(bottom_right_uv),
fetch(bottom_left_uv));
vec2 arrangement = mod(pixel_coord, 2.0);
vec2 arrangement = floor(half_pixel_coord);
vec2 is_top_left = step(1.0, arrangement);
vec2 is_bottom_left = step(1.0, arrangement);
vec3 color = mix(
mix(pixels.zyx, pixels.wzy, is_top_left.y),
mix(pixels.yzw, pixels.xyz, is_top_left.y),
is_top_left.x);
// vec3 color = mix(
// mix(pixels.xyz, pixels.yzw, is_bottom_left.y),
// mix(pixels.wzy, pixels.zyx, is_bottom_left.y),
// is_bottom_left.x);
vec3 color = pixels.zyx;
vec3 srgb_color = pow(color, vec3(1.0 / 2.2));
// vec3 srgb_color = vec3(
// texture2D(srgb_map, vec2(color.r, 0)).r,
// texture2D(srgb_map, vec2(color.g, 0)).r,
// texture2D(srgb_map, vec2(color.b, 0)).r);
// Fast SRGB estimate. See https://mimosa-pudica.net/fast-gamma/
vec3 srgb_color = (vec3(1.138) * inversesqrt(color) - vec3(0.138)) * color;
gl_FragColor = vec4((color_matrix * srgb_color).bgr, 0);
// Slow SRGB estimate
// vec3 srgb_color = pow(color, vec3(1.0 / 2.2));
gl_FragColor = vec4(color_matrix * srgb_color, 0);
}

View File

@@ -1,21 +1,32 @@
precision mediump float;
precision highp float;
attribute vec2 vert;
attribute vec2 tex_coord;
uniform mat3 transform;
uniform vec2 pixel_size;
uniform vec2 half_image_size;
varying vec2 uv1;
varying vec2 uv2;
varying vec2 pixel_coord;
// varying vec2 uv1;
// varying vec2 uv2;
varying vec2 top_left_uv;
varying vec2 top_right_uv;
varying vec2 bottom_left_uv;
varying vec2 bottom_right_uv;
varying vec2 half_pixel_coord;
void main() {
uv1 = tex_coord - pixel_size / 2.0;
uv2 = tex_coord + pixel_size / 2.0;
uv1 += pixel_size;
uv2 += pixel_size;
pixel_coord = uv1 / pixel_size;
top_left_uv = tex_coord - pixel_size / 2.0;
bottom_right_uv = tex_coord + pixel_size / 2.0;
top_right_uv = vec2(top_left_uv.x, bottom_right_uv.y);
bottom_left_uv = vec2(bottom_right_uv.x, top_left_uv.y);
// uv1 = tex_coord - pixel_size / 2.0;
// uv2 = tex_coord + pixel_size / 2.0;
// uv1 += pixel_size;
// uv2 += pixel_size;
half_pixel_coord = top_left_uv * half_image_size;
gl_Position = vec4(transform * vec3(vert, 1), 1);
}