101 lines
2.3 KiB
Plaintext
101 lines
2.3 KiB
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;
|
|
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;
|
|
|
|
float M_PI= 3.14159;
|
|
int suchbreich=50; //die anzahl der Pixel, die maximal in eine Richtung gegangen wird um einen Sicheren Pixel zu finden
|
|
vec4 SicheresPixel[4]; //Speichert die das nachste Sichere Pixel, Array grosse=anzahl der Richtungen
|
|
int anzahl_richtungen=4; //Speichert anzahl der Richtungen muss gleich der Array grosse von SicheresPixel sein
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
vec4 suche_Pixel_nach_winkel (vec2 start, float winkel){
|
|
vec2 pix;
|
|
float i=1;
|
|
winkel=winkel*1;
|
|
while(i<suchbreich){
|
|
pix.x=start.x+ sin(winkel+M_PI)*pixWidth*i;
|
|
pix.y=start.y+ cos(winkel+M_PI)*pixWidth*i;
|
|
color = getTriColor(pix);
|
|
int status = getState(color);
|
|
if (status==IS_FOREGROUND) {
|
|
return vec4(getForeColor(pix), i);
|
|
} else if (status==IS_BACKGROUND) {
|
|
return vec4(getBackColor(pix), i);
|
|
}else{
|
|
i++;
|
|
}
|
|
|
|
}
|
|
return vec4(0.0f, 0.0f, 0.0f, -1.0f);
|
|
|
|
|
|
}
|
|
|
|
vec4 Pruefe_Pixel_in_Umgebung (vec2 start){
|
|
float winkel=2*M_PI/anzahl_richtungen;
|
|
int i=1;
|
|
|
|
while(i<=anzahl_richtungen){
|
|
SicheresPixel[i-1]=suche_Pixel_nach_winkel(start, winkel*i);
|
|
i=i+i;
|
|
}
|
|
return SicheresPixel[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
vec4 h=Pruefe_Pixel_in_Umgebung(UV);
|
|
color = h.xyz;
|
|
}
|
|
}
|