forked from Themaister/slang-shaders
/
psp-color.slang
81 lines (70 loc) · 1.96 KB
/
psp-color.slang
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
73
74
75
76
77
78
79
80
81
#version 450
layout(push_constant) uniform Push
{
float target_gamma;
} params;
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
/*
Shader Modified: Pokefan531
Color Mangler
Author: hunterk
License: Public domain
*/
// Shader that replicates the LCD dynamics from PSP 1000 and PSP 2000
#pragma parameter target_gamma "Gamma Mode" 2.2 2.2 2.4 0.2
#define display_gamma 2.2
#define sat 1.0
#define lum 1.0
#define contrast 1.0
#define blr 0.0
#define blg 0.0
#define blb 0.0
#define r 0.95
#define g 0.80
#define b 0.98
#define rg 0.03
#define rb 0.01
#define gr 0.02
#define gb 0.01
#define br 0.0
#define bg 0.17
#define overscan_percent_x 0.0
#define overscan_percent_y 0.0
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
vec4 screen = pow(texture(Source, vTexCoord), vec4(params.target_gamma)).rgba;
vec4 avglum = vec4(0.5);
screen = mix(screen, avglum, (1.0 - contrast));
// r g b black
mat4 color = mat4(r, rg, rb, 0.0, //red channel
gr, g, gb, 0.0, //green channel
br, bg, b, 0.0, //blue channel
blr, blg, blb, 0.0); //alpha channel; these numbers do nothing for our purposes.
mat4 adjust = mat4((1.0 - sat) * 0.3086 + sat, (1.0 - sat) * 0.3086, (1.0 - sat) * 0.3086, 1.0,
(1.0 - sat) * 0.6094, (1.0 - sat) * 0.6094 + sat, (1.0 - sat) * 0.6094, 1.0,
(1.0 - sat) * 0.0820, (1.0 - sat) * 0.0820, (1.0 - sat) * 0.0820 + sat, 1.0,
0.0, 0.0, 0.0, 1.0);
color *= adjust;
screen = clamp(screen * lum, 0.0, 1.0);
screen = color * screen;
FragColor = pow(screen, vec4(1.0 / display_gamma));
}