summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/render/bgfx/fs_ntsc_encode.sc
blob: 61f5ae12ac980df36314b88267ff3ad8b035d3ce (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
$input v_color0, v_texcoord0

// license:BSD-3-Clause
// copyright-holders:Ryan Holtz,ImJezze
//-----------------------------------------------------------------------------
// NTSC Effect
//-----------------------------------------------------------------------------

// NB: intentionally wasteful of uniforms in order for easier slider utilization

#include "../../../../../3rdparty/bgfx/examples/common/common.sh"

// Autos
uniform vec4 u_source_dims;

// User-supplied
uniform vec4 u_a_value;
uniform vec4 u_b_value;
uniform vec4 u_cc_value;
uniform vec4 u_p_value;
uniform vec4 u_scan_time;
uniform vec4 u_jitter_offset;

// Parametric
uniform vec4 u_jitter_amount;

// Samplers
SAMPLER2D(s_tex, 0);

//-----------------------------------------------------------------------------
// Constants
//-----------------------------------------------------------------------------

void main()
{
	vec2 PValueSourceTexel = vec2(u_p_value.x, 0.0) / u_source_dims.xy;

	vec2 C0 = v_texcoord0 + PValueSourceTexel * vec2(0.0,  0.0);
	vec2 C1 = v_texcoord0 + PValueSourceTexel * vec2(0.25, 0.0);
	vec2 C2 = v_texcoord0 + PValueSourceTexel * vec2(0.5,  0.0);
	vec2 C3 = v_texcoord0 + PValueSourceTexel * vec2(0.75, 0.0);
	vec4 Cx = vec4(C0.x, C1.x, C2.x, C3.x);
	vec4 Cy = vec4(C0.y, C1.y, C2.y, C3.y);
	vec4 Texel0 = texture2D(s_tex, C0);
	vec4 Texel1 = texture2D(s_tex, C1);
	vec4 Texel2 = texture2D(s_tex, C2);
	vec4 Texel3 = texture2D(s_tex, C3);

	vec4 HPosition = Cx;
	vec4 VPosition = Cy;

	const vec4 YDot = vec4(0.299, 0.587, 0.114, 0.0);
	const vec4 IDot = vec4(0.595716, -0.274453, -0.321263, 0.0);
	const vec4 QDot = vec4(0.211456, -0.522591, 0.311135, 0.0);
	vec4 Y = vec4(dot(Texel0, YDot), dot(Texel1, YDot), dot(Texel2, YDot), dot(Texel3, YDot));
	vec4 I = vec4(dot(Texel0, IDot), dot(Texel1, IDot), dot(Texel2, IDot), dot(Texel3, IDot));
	vec4 Q = vec4(dot(Texel0, QDot), dot(Texel1, QDot), dot(Texel2, QDot), dot(Texel3, QDot));

	const float PI = 3.1415927;
	const float PI2 = 6.2831854;
	
	float W = PI2 * u_cc_value.x * u_scan_time.x;
	float WoPI = W / PI;

	float HOffset = (u_a_value.x + u_jitter_amount.x * u_jitter_offset.x) / WoPI;
	float VScale =  (u_b_value.x * u_source_dims.y) / WoPI;

	vec4 T = Cx + vec4(HOffset, HOffset, HOffset, HOffset) + Cy * vec4(VScale, VScale, VScale, VScale);
	vec4 TW = T * W;

	gl_FragColor = Y + I * cos(TW) + Q * sin(TW);
}