Framebuffer working; Trimap renders to FB; Refinem. use Trimap to Screen
This commit is contained in:
46
opengl-test-two/refinement.fragmentshader
Normal file
46
opengl-test-two/refinement.fragmentshader
Normal file
@@ -0,0 +1,46 @@
|
||||
#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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user