Trimap implemented; need bugfixes
This commit is contained in:
@@ -8,10 +8,70 @@ out vec3 color;
|
||||
|
||||
// Values that stay constant for the whole mesh.
|
||||
uniform sampler2D myTextureSampler;
|
||||
uniform float pixWidth;
|
||||
uniform float pixHeight;
|
||||
|
||||
void main(){
|
||||
|
||||
// Output color = color of the texture at the specified UV
|
||||
color = texture( myTextureSampler, UV ).rgb;
|
||||
|
||||
|
||||
|
||||
int IS_BACKGROUND = 0;
|
||||
int IS_UNDEFINED = 1;
|
||||
int IS_FOREGROUND = 2;
|
||||
int UNSET = -1;
|
||||
|
||||
|
||||
vec3 getColor(vec2 uvCoord) {
|
||||
return texture(myTextureSampler, UV).rgb;
|
||||
}
|
||||
|
||||
bool isBackground(vec3 c) {
|
||||
if (all( lessThanEqual(c, vec3(51.0f/255.0f, 208.0f/255.0f, 13.0f/255.0f))) &&
|
||||
all(greaterThanEqual(c, vec3(47.0f/255.0f, 204.0f/255.0f, 9.0f/255.0f)))
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void main(){
|
||||
int status = UNSET;
|
||||
float pw = pixWidth;
|
||||
float ph = pixHeight;
|
||||
|
||||
// 49,206, 11
|
||||
// Output color = color of the texture at the specified UV
|
||||
color = getColor(UV);
|
||||
for(int w=-5;w<=5;w++){
|
||||
for(int h=-5;h<=5;h++){
|
||||
if (w+h==-10) { // first pixel
|
||||
if (isBackground(getColor(UV+vec2(pixWidth*w,pixHeight*h)))) {
|
||||
status = IS_BACKGROUND;
|
||||
} else {
|
||||
status = IS_FOREGROUND;
|
||||
}
|
||||
} else { // other pixels
|
||||
if (isBackground(getColor(UV+vec2(pixWidth*w,pixHeight*h)))) {
|
||||
if (status != IS_BACKGROUND) {
|
||||
status = IS_UNDEFINED;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (status != IS_FOREGROUND) {
|
||||
status = IS_UNDEFINED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (status == IS_BACKGROUND) {
|
||||
color = vec3(1.0f, 0.0f, 0.0f);
|
||||
} else if (status == IS_FOREGROUND) {
|
||||
color = vec3(0.0f, 1.0f, 0.0f);
|
||||
} else {
|
||||
color = vec3(0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user