First version of fragment shader
This commit is contained in:
@@ -20,6 +20,11 @@ int IS_UNDEFINED = 1;
|
|||||||
int IS_FOREGROUND = 2;
|
int IS_FOREGROUND = 2;
|
||||||
int UNSET = -1;
|
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) {
|
vec3 getTriColor(vec2 uvCoord) {
|
||||||
return texture(trimap, uvCoord).rgb;
|
return texture(trimap, uvCoord).rgb;
|
||||||
}
|
}
|
||||||
@@ -42,6 +47,42 @@ int getState(vec3 c) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(){
|
void main(){
|
||||||
color = getTriColor(UV);
|
color = getTriColor(UV);
|
||||||
@@ -53,6 +94,7 @@ void main(){
|
|||||||
} else if (status==IS_BACKGROUND) {
|
} else if (status==IS_BACKGROUND) {
|
||||||
color = getBackColor(UV).rgb;
|
color = getBackColor(UV).rgb;
|
||||||
} else {
|
} else {
|
||||||
// render undefined area
|
vec4 h=Pruefe_Pixel_in_Umgebung(UV);
|
||||||
|
color = h.xyz;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user