From 325208d460a737cbcf3b041c4e925aa678d9cac5 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Thu, 22 Sep 2022 16:07:58 -0300 Subject: [PATCH] feat: implement better Colour Emulation --- src/platform.zig | 11 ++++++----- src/shader/pixelbuf.frag | 24 ++++++++++++++++++------ src/shader/pixelbuf.vert | 16 ++++++++-------- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/platform.zig b/src/platform.zig index f9b7d4d..3d3328a 100644 --- a/src/platform.zig +++ b/src/platform.zig @@ -25,10 +25,10 @@ pub const Gui = struct { // zig fmt: off const vertices: [32]f32 = [_]f32{ // Positions // Colours // Texture Coords - 1.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, // Top Right - 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, // Bottom Right - -1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, // Bottom Left - -1.0, -1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, // Top Left + 1.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, // Top Right + 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, // Bottom Right + -1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, // Bottom Left + -1.0, -1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, // Top Left }; const indices: [6]u32 = [_]u32{ @@ -236,7 +236,8 @@ pub const Gui = struct { pub fn deinit(self: *Self) void { self.audio.deinit(); - + // TODO: Buffer deletions + gl.deleteProgram(self.program_id); SDL.SDL_GL_DeleteContext(self.ctx); SDL.SDL_DestroyWindow(self.window); SDL.SDL_Quit(); diff --git a/src/shader/pixelbuf.frag b/src/shader/pixelbuf.frag index f867bde..c45efae 100644 --- a/src/shader/pixelbuf.frag +++ b/src/shader/pixelbuf.frag @@ -1,13 +1,25 @@ #version 330 core -out vec4 FragColor; +out vec4 frag_color; -in vec3 ourColor; -in vec2 TexCoord; +in vec3 color; +in vec2 uv; -// texture sampler -uniform sampler2D texture1; +uniform sampler2D screen; void main() { - FragColor = texture(texture1, TexCoord); + // https://near.sh/video/color-emulation + // Thanks to Talarubi + Near for the Colour Correction + // Thanks to fleur + mattrb for the Shader Impl + + vec4 color = texture(screen, uv); + color.rgb = pow(color.rgb, vec3(4.0)); // LCD Gamma + + frag_color = vec4( + pow(vec3( + 0 * color.b + 50 * color.g + 255 * color.r, + 30 * color.b + 230 * color.g + 10 * color.r, + 220 * color.b + 10 * color.g + 50 * color.r + ) / 255, vec3(1.0 / 2.2)), // Out Gamma + 1.0); } diff --git a/src/shader/pixelbuf.vert b/src/shader/pixelbuf.vert index 0738b36..43ef32e 100644 --- a/src/shader/pixelbuf.vert +++ b/src/shader/pixelbuf.vert @@ -1,13 +1,13 @@ #version 330 core -layout (location = 0) in vec3 aPos; -layout (location = 1) in vec3 aColor; -layout (location = 2) in vec2 aTexCoord; +layout (location = 0) in vec3 pos; +layout (location = 1) in vec3 in_color; +layout (location = 2) in vec2 in_uv; -out vec3 ourColor; -out vec2 TexCoord; +out vec3 color; +out vec2 uv; void main() { - gl_Position = vec4(aPos, 1.0); - ourColor = aColor; - TexCoord = aTexCoord; + color = in_color; + uv = in_uv; + gl_Position = vec4(pos, 1.0); } \ No newline at end of file