Merge pull request #98 from jdgleaver/cc-update

(handheld) Update colour correction shaders
This commit is contained in:
hizzlekizzle 2019-04-18 11:21:15 -05:00 committed by GitHub
commit 77d4efd688
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 76 additions and 67 deletions

View file

@ -21,7 +21,7 @@ layout(std140, set = 0, binding = 0) uniform UBO
*/
// Shader that replicates the LCD dynamics from a GameBoy Advance
#pragma parameter darken_screen "Darken Screen" 0.5 -0.25 2.0 0.05
#pragma parameter darken_screen "Darken Screen" 0.5 -0.25 1.5 0.05
#define target_gamma 2.2
#define display_gamma 2.2
@ -31,14 +31,14 @@ layout(std140, set = 0, binding = 0) uniform UBO
#define blr 0.0
#define blg 0.0
#define blb 0.0
#define r 0.845
#define g 0.68
#define b 0.755
#define rg 0.09
#define rb 0.16
#define gr 0.17
#define gb 0.085
#define br -0.015
#define r 0.86
#define g 0.66
#define b 0.81
#define rg 0.11
#define rb 0.1325
#define gr 0.19
#define gb 0.0575
#define br -0.05
#define bg 0.23
#define overscan_percent_x 0.0
#define overscan_percent_y 0.0

View file

@ -1,18 +1,8 @@
#version 450
/*
GBC Color Correction Shader
A shader that replicates the LCD dynamics from a Game Boy Color
Color values are derived from Gambatte's color correction implementation, with some tweaks.
Based on Color Mangler
Author: hunterk
License: Public domain
*/
layout(push_constant) uniform Push
{
float darken_screen;
float brighten_screen;
} params;
layout(std140, set = 0, binding = 0) uniform UBO
@ -23,22 +13,33 @@ layout(std140, set = 0, binding = 0) uniform UBO
vec4 SourceSize;
} global;
#pragma parameter darken_screen "Darken Screen" 0.0 -0.25 2.0 0.05
/*
Shader Modified: Pokefan531
Color Mangler
Author: hunterk
License: Public domain
*/
// Shader that replicates the LCD dynamics from a GameBoy Advance
#pragma parameter brighten_screen "Brighten Screen" 0.5 -0.25 1.2 0.05
#define target_gamma 2.2
#define display_gamma 2.2
#define sat 1.0
#define lum 1.0
#define contrast 1.0
#define blr 0.0
#define blg 0.0
#define blb 0.0
#define r 0.78824
#define g 0.72941
#define b 0.82
#define rg 0.025
#define rb 0.12039
#define gr 0.12157
#define gb 0.12157
#define br 0.0
#define bg 0.275000
#define r 0.87
#define g 0.66
#define b 0.79
#define rg 0.115
#define rb 0.14
#define gr 0.18
#define gb 0.07
#define br -0.05
#define bg 0.225
#pragma stage vertex
layout(location = 0) in vec4 Position;
@ -58,14 +59,22 @@ layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
vec4 screen = pow(texture(Source, vTexCoord), vec4(target_gamma + params.darken_screen)).rgba;
vec4 screen = pow(texture(Source, vTexCoord), vec4(target_gamma + (params.brighten_screen * -1.0))).rgba;
vec4 avglum = vec4(0.5);
screen = mix(screen, avglum, (1.0 - contrast));
// red green blue alpha ; alpha does nothing for our purposes
mat4 color = mat4(r, rg, rb, 0.0, //red
gr, g, gb, 0.0, //green
br, bg, b, 0.0, //blue
blr, blg, blb, 0.0); //black
// r g b black
mat4 color = mat4(r, rg, rb, 0.0, //red channel
gr, g, gb, 0.0, //green channel
br, bg, b, 0.0, //blue channel
blr, blg, blb, 0.0); //alpha channel; these numbers do nothing for our purposes.
mat4 adjust = mat4((1.0 - sat) * 0.3086 + sat, (1.0 - sat) * 0.3086, (1.0 - sat) * 0.3086, 1.0,
(1.0 - sat) * 0.6094, (1.0 - sat) * 0.6094 + sat, (1.0 - sat) * 0.6094, 1.0,
(1.0 - sat) * 0.0820, (1.0 - sat) * 0.0820, (1.0 - sat) * 0.0820 + sat, 1.0,
0.0, 0.0, 0.0, 1.0);
color *= adjust;
screen = clamp(screen * lum, 0.0, 1.0);
screen = color * screen;
FragColor = pow(screen, vec4(1.0 / display_gamma));
FragColor = pow(screen, vec4(1.0 / (display_gamma)));
}

View file

@ -24,15 +24,15 @@ layout(std140, set = 0, binding = 0) uniform UBO
#define blr 0.0
#define blg 0.0
#define blb 0.0
#define r 0.83
#define g 0.65
#define b 0.765
#define rg 0.105
#define rb 0.105
#define r 0.85
#define g 0.655
#define b 0.865
#define rg 0.095
#define rb 0.06
#define gr 0.20
#define gb 0.13
#define br -0.03
#define bg 0.245
#define gb 0.075
#define br -0.05
#define bg 0.25
#define overscan_percent_x 0.0
#define overscan_percent_y 0.0

View file

@ -31,14 +31,14 @@ layout(std140, set = 0, binding = 0) uniform UBO
#define blr 0.0
#define blg 0.0
#define blb 0.0
#define r 0.745
#define r 0.88
#define g 0.69
#define b 0.775
#define b 0.765
#define rg 0.06
#define rb 0.085
#define gr 0.315
#define gb 0.14
#define br -0.06
#define gr 0.24
#define gb 0.15
#define br -0.12
#define bg 0.25
#define overscan_percent_x 0.0
#define overscan_percent_y 0.0

View file

@ -24,15 +24,15 @@ layout(std140, set = 0, binding = 0) uniform UBO
#define blr 0.0
#define blg 0.0
#define blb 0.0
#define r 0.92
#define r 0.98
#define g 0.795
#define b 0.975
#define rg 0.035
#define b 0.98
#define rg 0.04
#define rb 0.01
#define gr 0.24
#define gb 0.015
#define br -0.16
#define bg 0.17
#define gr 0.20
#define gb 0.01
#define br -0.18
#define bg 0.165
#define overscan_percent_x 0.0
#define overscan_percent_y 0.0

View file

@ -31,12 +31,12 @@ layout(std140, set = 0, binding = 0) uniform UBO
#define blr 0.0
#define blg 0.0
#define blb 0.0
#define r 0.74
#define g 0.68
#define b 0.68
#define rg 0.08
#define rb 0.08
#define gr 0.26
#define r 0.73
#define g 0.675
#define b 0.675
#define rg 0.085
#define rb 0.085
#define gr 0.27
#define gb 0.24
#define br 0.0
#define bg 0.24

View file

@ -9,6 +9,6 @@ scale0 = "1.000000"
filter_linear1 = "false"
parameters = "darken_screen;RETRO_PIXEL_SIZE"
darken_screen = "0.500000"
parameters = "brighten_screen;RETRO_PIXEL_SIZE"
brighten_screen = "0.500000"
RETRO_PIXEL_SIZE = "0.840000"