summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/render/bgfx/shaders/chains/misc/fs_blit_yuy16.sc
blob: 326ff0e2b04852ebbf647eda4d162a3438c5410d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
$input v_color0, v_texcoord0

// license:BSD-3-Clause
// copyright-holders:Ryan Holtz

#include "common.sh"

// Samplers
SAMPLER2D(s_tex, 0);

#define round(X) floor((X)+0.5)

vec4 u_tex_size0;
vec4 u_inv_tex_size0;

vec3 ycc_to_rgb(float y, float cb, float cr)
{
	float r = saturate(y + 1.40200 * (cr - 0.5));
	float g = saturate(y - 0.34414 * (cb - 0.5) - 0.71414 * (cr - 0.5));
	float b = saturate(y + 1.77200 * (cb - 0.5));
	return vec3(r, g, b);
}

void main()
{
	vec2 size_minus_one = u_tex_size0.xy - vec2(1.0, 1.0);
	vec2 original_uv = round(v_texcoord0.xy * size_minus_one);
	float mod_val = mod(original_uv.x, 2.0);
	vec2 rounded_uv = round(vec2(original_uv.x - mod_val, original_uv.y));
	vec2 next_uv = rounded_uv + vec2(1.0, 0.0);
	vec2 srcpix0 = texture2D(s_tex, rounded_uv / size_minus_one).rg;
	vec2 srcpix1 = texture2D(s_tex, next_uv / size_minus_one).rg;
	float cr = srcpix1.r;
	float cb = srcpix0.r;
	if (mod_val < 1.0)
		gl_FragColor = vec4(ycc_to_rgb(srcpix0.g, cb, cr), 1.0) * v_color0;
	else
		gl_FragColor = vec4(ycc_to_rgb(srcpix1.g, cb, cr), 1.0) * v_color0;
}