-
Notifications
You must be signed in to change notification settings - Fork 4
/
defaultColorCorrection.frag.glsl
121 lines (92 loc) · 2.45 KB
/
defaultColorCorrection.frag.glsl
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "include/common.glsl"
#include "include/uniforms.glsl"
qf_varying vec2 v_TexCoord;
uniform sampler2D u_BaseTexture;
#ifdef APPLY_LUT
uniform sampler2D u_ColorLUT;
#endif
#ifdef APPLY_BLOOM
uniform sampler2D u_BloomTexture0;
uniform sampler2D u_BloomTexture1;
uniform sampler2D u_BloomTexture2;
uniform sampler2D u_BloomTexture3;
#endif
const float W = 0.90; // the white point
const float B = 0.80; // the bright point for bloom
#ifdef APPLY_HDR
uniform myhalf u_HDRGamma;
uniform myhalf u_HDRExposure;
vec3 ACESFilm(vec3 x)
{
float a = 2.51f;
float b = 0.03f;
float c = 2.43f;
float d = 0.59f;
float e = 0.14f;
vec3 s = ((x*(a*x+b))/(x*(c*x+d)+e));
return s;
}
vec3 ToneMap(vec3 c)
{
return ACESFilm(c / 2.0) / ACESFilm(vec3(W) / 2.0);
}
#endif
#ifdef APPLY_BLOOM
vec3 Bloom(vec2 t)
{
vec3 bloom = qf_texture(u_BloomTexture0, t).rgb +
qf_texture(u_BloomTexture1, t).rgb +
qf_texture(u_BloomTexture2, t).rgb +
qf_texture(u_BloomTexture3, t).rgb;
return clamp(bloom, 0.0, 1.0);
}
#endif
#ifdef APPLY_LUT
vec3 ColorMap(vec3 c)
{
vec3 coords = c;
coords.rg = coords.rg * vec2(0.9375) + vec2(0.03125);
coords *= vec3(1.0, 0.0625, 15.0);
float blueMix = fract(coords.b);
vec2 blueOffset = vec2(0.0, floor(coords.b) * 0.0625);
vec3 color1 = qf_texture(u_ColorLUT, coords.rg + blueOffset).rgb;
blueOffset.y = min(blueOffset.y + 0.0625, 0.9375);
vec3 color2 = qf_texture(u_ColorLUT, coords.rg + blueOffset).rgb;
coords = mix(color1, color2, blueMix);
return coords;
}
#endif
void main(void)
{
vec4 texel = qf_texture(u_BaseTexture, v_TexCoord);
vec3 coords = texel.rgb;
#ifdef APPLY_HDR
coords = ToneMap(coords * u_HDRExposure);
#endif
#ifdef APPLY_SRGB2LINEAR
#ifdef APPLY_HDR
coords = pow(coords, vec3(1.0 / u_HDRGamma));
#else
coords = pow(coords, vec3(1.0 / 2.2));
#endif
#endif
#ifdef APPLY_OVEBRIGHT
qf_FragColor = vec4(coords, texel.a);
qf_BrightColor = vec4(coords - clamp(coords, 0.0, B), texel.a);
#else
#if defined(APPLY_LUT) && defined(APPLY_SRGB2LINEAR)
coords = clamp(coords, 0.0, 1.0);
#endif
#ifdef APPLY_LUT
coords = ColorMap(coords);
#ifdef APPLY_BLOOM
coords += ColorMap(Bloom(v_TexCoord));
#endif // APPLY_BLOOM
#else
#ifdef APPLY_BLOOM
coords += Bloom(v_TexCoord);
#endif // APPLY_BLOOM
#endif // APPLY_LUT
qf_FragColor = vec4(coords, texel.a);
#endif // APPLY_OUT_BLOOM
}