gl01/internal/igwrap/backend/shader.frag

37 lines
849 B
GLSL

#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)
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) {
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);
} 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;
}
}