#version 430 core in Fragment { // @Performance: Are this fields aligned to vec4? Is it better to reorder them? vec2 position; vec4 color; vec2 uv; } frag; uniform int width; // Width of the screen in pixels uniform int height; // Height of the screen in pixels uniform int has_texture0; uniform sampler2D texture0; uniform int texture_channels0; uniform vec4 color0; out vec4 FragColor; void main() { FragColor = frag.color; if(has_texture0 != 0) { vec4 texture_color; if(texture_channels0 == 1) texture_color = vec4(1.0, 1.0, 1.0, texture(texture0, frag.uv).r); else if(texture_channels0 == 3) texture_color = vec4(texture(texture0, frag.uv).rgb, 1.0); else texture_color = texture(texture0, frag.uv); FragColor = color0 * frag.color * texture_color; FragColor.rgb *= FragColor.a; // Premultiplied alpha } }