all repos — mgba @ 9a78f564676de81899f47f23486488d01ea8ed6b

mGBA Game Boy Advance Emulator

res/shaders/gba-color.shader/gba-color.fs (view raw)

 1varying vec2 texCoord;
 2uniform sampler2D tex;
 3uniform vec2 texSize;
 4
 5uniform float darken_screen;
 6const float target_gamma = 2.2;
 7const float display_gamma = 2.5;
 8const float sat = 1.0;
 9const float lum = 0.99;
10const float contrast = 1.0;
11const vec3 bl = vec3(0.0, 0.0, 0.0);
12const vec3 r = vec3(0.84, 0.09, 0.15);
13const vec3 g = vec3(0.18, 0.67, 0.10);
14const vec3 b = vec3(0.0, 0.26, 0.73);
15
16void main() {
17	vec4 screen = pow(texture2D(tex, texCoord), vec4(target_gamma + darken_screen)).rgba;
18	vec4 avglum = vec4(0.5);
19	screen = mix(screen, avglum, (1.0 - contrast));
20 
21	mat4 color = mat4(	r.r,	r.g,	r.b,	0.0,
22				g.r,	g.g,	g.b,	0.0,
23				b.r,	b.g,	b.b,	0.0,
24				bl.r,	bl.g,	bl.b,	1.0);
25			  
26	mat4 adjust = mat4(	(1.0 - sat) * 0.3086 + sat,	(1.0 - sat) * 0.3086,		(1.0 - sat) * 0.3086,		1.0,
27				(1.0 - sat) * 0.6094,		(1.0 - sat) * 0.6094 + sat,	(1.0 - sat) * 0.6094,		1.0,
28				(1.0 - sat) * 0.0820,		(1.0 - sat) * 0.0820,		(1.0 - sat) * 0.0820 + sat,	1.0,
29				0.0,				0.0,				0.0,				1.0);
30	color *= adjust;
31	screen = clamp(screen * lum, 0.0, 1.0);
32	screen = color * screen;
33	gl_FragColor = pow(screen, vec4(1.0 / display_gamma + (darken_screen / 8.)));
34}