-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathBackground.frag
More file actions
38 lines (33 loc) · 1.13 KB
/
Background.frag
File metadata and controls
38 lines (33 loc) · 1.13 KB
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
#version 330 core
#extension GL_KHR_blend_equation_advanced: enable
#extension GL_ARB_sample_shading: enable
in vec2 textureUV;
in vec4 vertexColor;
#ifdef GL_KHR_blend_equation_advanced
layout(blend_support_all_equations) out;
#endif
out vec4 FragColor;
uniform sampler2D rteTexture;
uniform sampler2D rtePalette;
uniform vec4 rteColor = vec4(1.0);
uniform bool rteBlendInvert = false;
uniform bool drawMasked = false;
vec4 textureAA(sampler2D tex, vec2 uv) {
vec2 texsize = vec2(textureSize(tex, 0));
vec2 uv_texspace = uv * texsize;
vec2 seam = floor(uv_texspace + .5);
uv_texspace = (uv_texspace - seam) / fwidth(uv_texspace) + seam;
uv_texspace = clamp(uv_texspace, seam - .5, seam + .5);
return texture(tex, uv_texspace / texsize);
}
void main() {
float red = texture(rteTexture, textureUV).r;
if (red==0 && drawMasked) {
discard;
}
if (!rteBlendInvert) {
FragColor = textureAA(rtePalette, vec2(red * vertexColor.r, 0.0)) * vec4(rteColor.rgb, rteColor.a * vertexColor.a);
} else {
FragColor = vec4(vec3(1.0), 0.0) - (textureAA(rtePalette, vec2(red * vertexColor.r, 0.0)) * vec4(rteColor.rgb, -rteColor.a * vertexColor.a));
}
}