blob: deb82a8904e8329b15d8f0064b5c7bbc5fc24d3a (
plain)
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
|
flat in vec4 finalColor;
#ifndef USE_WIRE
in vec2 texCoord_interp;
#endif
out vec4 fragColor;
#ifndef USE_WIRE
uniform sampler2D image;
#endif
uniform int depthMode;
uniform bool useAlphaTest;
float linearrgb_to_srgb(float c)
{
if (c < 0.0031308) {
return (c < 0.0) ? 0.0 : c * 12.92;
}
else {
return 1.055 * pow(c, 1.0 / 2.4) - 0.055;
}
}
vec4 texture_read_as_srgb(sampler2D tex, vec2 co)
{
/* By convention image textures return scene linear colors, but
* overlays still assume srgb. */
vec4 color = texture(tex, co);
color.r = linearrgb_to_srgb(color.r);
color.g = linearrgb_to_srgb(color.g);
color.b = linearrgb_to_srgb(color.b);
return color;
}
void main()
{
#ifdef USE_WIRE
fragColor = finalColor;
#else
vec4 tex_col = texture_read_as_srgb(image, texCoord_interp);
fragColor = finalColor * tex_col;
if (useAlphaTest) {
/* Arbitrary discard anything below 5% opacity.
* Note that this could be exposed to the User. */
if (tex_col.a < 0.05) {
discard;
}
else {
fragColor.a = 1.0;
}
}
#endif
if (depthMode == DEPTH_BACK) {
gl_FragDepth = 0.999999;
}
else if (depthMode == DEPTH_FRONT) {
gl_FragDepth = 0.000001;
}
else if (depthMode == DEPTH_UNCHANGED) {
gl_FragDepth = gl_FragCoord.z;
}
}
|