SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit e88a48e0a13f92c565dcc62ff6bd9ce4a8774725 parent 096eb78be70ed22f4e3d204a739750a0593f1add Author: Lior Halphon <LIJI32@gmail.com> Date: Fri, 19 Jun 2020 23:18:38 +0300 Use gamma-corrected mixing in shaders Diffstat:
| M | Shaders/CRT.fsh | 3 | --- |
| M | Shaders/HQ2x.fsh | 4 | ++-- |
| M | Shaders/MasterShader.fsh | 14 | +++++++++++--- |
| M | Shaders/MasterShader.metal | 7 | ++++--- |
| M | Shaders/OmniScale.fsh | 2 | +- |
5 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/Shaders/CRT.fsh b/Shaders/CRT.fsh @@ -158,8 +158,5 @@ STATIC vec4 scale(sampler2D image, vec2 position, vec2 input_resolution, vec2 ou ret *= output_resolution.y - pixel_position.y; } - // Gamma correction - ret = pow(ret, vec4(0.72)); - return ret; } diff --git a/Shaders/HQ2x.fsh b/Shaders/HQ2x.fsh @@ -12,7 +12,7 @@ STATIC vec3 rgb_to_hq_colospace(vec4 rgb) STATIC bool is_different(vec4 a, vec4 b) { vec3 diff = abs(rgb_to_hq_colospace(a) - rgb_to_hq_colospace(b)); - return diff.x > 0.188 || diff.y > 0.027 || diff.z > 0.031; + return diff.x > 0.018 || diff.y > 0.002 || diff.z > 0.005; } #define P(m, r) ((pattern & (m)) == (r)) @@ -84,7 +84,7 @@ STATIC vec4 scale(sampler2D image, vec2 position, vec2 input_resolution, vec2 ou 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); + return interp_3px(w4, 4.0, 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); diff --git a/Shaders/MasterShader.fsh b/Shaders/MasterShader.fsh @@ -9,14 +9,22 @@ uniform vec2 origin; #define equal(x, y) ((x) == (y)) #define inequal(x, y) ((x) != (y)) #define STATIC +#define GAMMA (2.2) out vec4 frag_color; +vec4 _texture(sampler2D t, vec2 pos) +{ + return pow(texture(t, pos), vec4(GAMMA)); +} + +#define texture _texture + #line 1 {filter} -#define BLEND_BIAS (1.0/3.0) +#define BLEND_BIAS (2.0/5.0) #define DISABLED 0 #define SIMPLE 1 @@ -58,7 +66,7 @@ void main() break; } - frag_color = mix(scale(image, position, input_resolution, output_resolution), - scale(previous_image, position, input_resolution, output_resolution), ratio); + frag_color = pow(mix(scale(image, position, input_resolution, output_resolution), + scale(previous_image, position, input_resolution, output_resolution), ratio), vec4(1.0 / GAMMA)); } diff --git a/Shaders/MasterShader.metal b/Shaders/MasterShader.metal @@ -12,6 +12,7 @@ typedef texture2d<half> sampler2D; #define equal(x, y) all((x) == (y)) #define inequal(x, y) any((x) != (y)) #define STATIC static +#define GAMMA (2.2) typedef struct { float4 position [[position]]; @@ -36,7 +37,7 @@ vertex rasterizer_data vertex_shader(uint index [[ vertex_id ]], static inline float4 texture(texture2d<half> texture, float2 pos) { constexpr sampler texture_sampler; - return float4(texture.sample(texture_sampler, pos)); + return pow(float4(texture.sample(texture_sampler, pos)), GAMMA); } #line 1 @@ -87,7 +88,7 @@ fragment float4 fragment_shader(rasterizer_data in [[stage_in]], break; } - return mix(scale(image, in.texcoords, input_resolution, *output_resolution), - scale(previous_image, in.texcoords, input_resolution, *output_resolution), ratio); + return pow(mix(scale(image, in.texcoords, input_resolution, *output_resolution), + scale(previous_image, in.texcoords, input_resolution, *output_resolution), ratio), 1 / GAMMA); } diff --git a/Shaders/OmniScale.fsh b/Shaders/OmniScale.fsh @@ -19,7 +19,7 @@ STATIC vec3 rgb_to_hq_colospace(vec4 rgb) STATIC bool is_different(vec4 a, vec4 b) { vec3 diff = abs(rgb_to_hq_colospace(a) - rgb_to_hq_colospace(b)); - return diff.x > 0.125 || diff.y > 0.027 || diff.z > 0.031; + return diff.x > 0.018 || diff.y > 0.002 || diff.z > 0.005; } #define P(m, r) ((pattern & (m)) == (r))
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.