Use gamma-corrected mixing in shaders

This commit is contained in:
Lior Halphon 2020-06-19 23:18:38 +03:00
parent 096eb78be7
commit e88a48e0a1
5 changed files with 18 additions and 12 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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));
}

View File

@ -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);
}

View File

@ -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))