Files
cpp-imanox-chroma-matting/opengl-test-two/refinement.fragmentshader

47 lines
853 B
Plaintext

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