gl01/internal/igwrap/backend/shader.frag

38 lines
880 B
GLSL
Raw Normal View History

2022-02-10 19:58:51 +08:00
#version 330
#define FLAG_RED (1<<0)
#define FLAG_GREEN (1<<1)
#define FLAG_BLUE (1<<2)
#define FLAG_ALPHA (1<<3)
#define FLAG_COLORS (FLAG_RED | FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA)
#define FLAG_LINEAR (1<<4)
#define FLAG_IMGUI_FONT (1<<5)
#define FLAG_FLIP_Y (1<<6)
2022-02-10 19:58:51 +08:00
uniform sampler2D tex;
uniform int flags;
in vec2 fragUV;
in vec4 fragColor;
out vec4 outputColor;
const float gamma = 2.2;
void main() {
if ((flags & FLAG_IMGUI_FONT) != 0) {
2022-02-10 19:58:51 +08:00
outputColor = vec4(fragColor.rgb, fragColor.a * texture(tex, fragUV.st).r);
} else if ((flags & FLAG_COLORS) == FLAG_RED) {
outputColor = vec4(vec3(texture(tex, fragUV.st).r), 1);
2022-02-10 19:58:51 +08:00
} else {
vec4 color = texture(tex, fragUV.st);
if ((flags & FLAG_LINEAR) != 0)
color.rgb = pow(color.rgb, vec3(1.0/gamma));
outputColor = color * fragColor;
if ((flags & FLAG_ALPHA) == 0)
outputColor.a = 1;
}
}