#version 330 core // Interpolated values from the vertex shaders in vec2 UV; // Ouput data out vec3 color; // Values that stay constant for the whole mesh. uniform sampler2D trimap; uniform sampler2D foreground; uniform sampler2D background; // Relative width/height of a pixel uniform float pixWidth; uniform float pixHeight; int IS_BACKGROUND = 0; int IS_UNDEFINED = 1; int IS_FOREGROUND = 2; int UNSET = -1; vec3 getTriColor(vec2 uvCoord) { return texture(trimap, uvCoord).rgb; } vec3 getForeColor(vec2 uvCoord) { return texture(foreground, uvCoord).rgb; } vec3 getBackColor(vec2 uvCoord) { return texture(background, uvCoord).rgb; } int getState(vec3 c) { if (all(lessThanEqual(c, vec3(0.2f)))) { return IS_BACKGROUND; } else if (all(greaterThanEqual(c, vec3(0.8f)))) { return IS_FOREGROUND; } else { return IS_UNDEFINED; } } void main(){ color = getTriColor(UV); int status = getState(color); if (status==IS_FOREGROUND) { color = getForeColor(UV).rgb; } else if (status==IS_BACKGROUND) { color = getBackColor(UV).rgb; } else { // render undefined area } }