Refinementshader complete; Linear alpha value by distance
This commit is contained in:
@@ -21,9 +21,9 @@ int IS_FOREGROUND = 2;
|
|||||||
int UNSET = -1;
|
int UNSET = -1;
|
||||||
|
|
||||||
float M_PI= 3.14159;
|
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
|
int suchbreich=400; //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
|
vec4 SicheresPixel[20]; //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
|
int anzahl_richtungen=20; //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;
|
||||||
@@ -47,15 +47,15 @@ int getState(vec3 c) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 suche_Pixel_nach_winkel (vec2 start, float winkel){
|
vec4 suche_Pixel_nach_winkel (vec2 uv, float winkel){
|
||||||
vec2 pix;
|
vec2 pix;
|
||||||
float i=1;
|
float i=1;
|
||||||
winkel=winkel*1;
|
vec3 color_sichers_Pixel;
|
||||||
while(i<suchbreich){
|
while(i<suchbreich){
|
||||||
pix.x=start.x+ sin(winkel+M_PI)*pixWidth*i;
|
pix.x=uv.x+ sin(winkel)*pixWidth*i;
|
||||||
pix.y=start.y+ cos(winkel+M_PI)*pixWidth*i;
|
pix.y=uv.y+ cos(winkel)*pixWidth*i;
|
||||||
color = getTriColor(pix);
|
color_sichers_Pixel = getTriColor(pix);
|
||||||
int status = getState(color);
|
int status = getState(color_sichers_Pixel);
|
||||||
if (status==IS_FOREGROUND) {
|
if (status==IS_FOREGROUND) {
|
||||||
return vec4(getForeColor(pix), i);
|
return vec4(getForeColor(pix), i);
|
||||||
} else if (status==IS_BACKGROUND) {
|
} else if (status==IS_BACKGROUND) {
|
||||||
@@ -70,15 +70,46 @@ vec4 suche_Pixel_nach_winkel (vec2 start, float winkel){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 Pruefe_Pixel_in_Umgebung (vec2 start){
|
float Farbabstand(int i){
|
||||||
float winkel=2*M_PI/anzahl_richtungen;
|
float d=sqrt(pow(color.x-SicheresPixel[i].x,2)+pow(color.y-SicheresPixel[i].y,2)+pow(color.z-SicheresPixel[i].z, 2));//sqr((x1-x2)^2+(y1-y2)^2+(z1-z2)^2)
|
||||||
int i=1;
|
return d;
|
||||||
|
|
||||||
while(i<=anzahl_richtungen){
|
|
||||||
SicheresPixel[i-1]=suche_Pixel_nach_winkel(start, winkel*i);
|
|
||||||
i=i+i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vec3 Pruefe_Pixel_in_Umgebung (vec2 start){
|
||||||
|
float winkel=2*M_PI/anzahl_richtungen;
|
||||||
|
int i=0;
|
||||||
|
float maximal=0;
|
||||||
|
float gesamt_abstand=0.0f;
|
||||||
|
while(i<anzahl_richtungen){
|
||||||
|
SicheresPixel[i]=suche_Pixel_nach_winkel(start, winkel*i);
|
||||||
|
if(SicheresPixel[i].w!=-1)
|
||||||
|
gesamt_abstand+=SicheresPixel[i].w;
|
||||||
|
if(maximal<SicheresPixel[i].w)
|
||||||
|
maximal=SicheresPixel[i].w;
|
||||||
|
i=i+1;
|
||||||
|
}
|
||||||
|
maximal++;
|
||||||
|
//float d = Farbabstand(1);//eigene Funktion
|
||||||
|
/*float d1=distance(SicheresPixel[1].xyz, color);//mitgelieferte Funktion
|
||||||
|
if (d1==d ){
|
||||||
return SicheresPixel[1];
|
return SicheresPixel[1];
|
||||||
|
}else{
|
||||||
|
return vec3(0.5f);
|
||||||
|
}*/
|
||||||
|
i=0;
|
||||||
|
vec3 kombiniert=vec3(0.0f);
|
||||||
|
float nenner=anzahl_richtungen*maximal-gesamt_abstand;
|
||||||
|
while(i<anzahl_richtungen){
|
||||||
|
if(SicheresPixel[i].w!=-1)
|
||||||
|
kombiniert+=SicheresPixel[i].xyz*(maximal-SicheresPixel[i].w)/nenner;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return kombiniert;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +125,8 @@ void main(){
|
|||||||
} else if (status==IS_BACKGROUND) {
|
} else if (status==IS_BACKGROUND) {
|
||||||
color = getBackColor(UV).rgb;
|
color = getBackColor(UV).rgb;
|
||||||
} else {
|
} else {
|
||||||
vec4 h=Pruefe_Pixel_in_Umgebung(UV);
|
vec3 h=Pruefe_Pixel_in_Umgebung(UV);
|
||||||
color = h.xyz;
|
//h=vec3(0.5f);
|
||||||
|
color = h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ int UNSET = -1;
|
|||||||
|
|
||||||
vec3 greenValue = vec3(0.0f, 1.0f, 0.0f);
|
vec3 greenValue = vec3(0.0f, 1.0f, 0.0f);
|
||||||
vec3 difference = vec3(40.0f/255.0f);
|
vec3 difference = vec3(40.0f/255.0f);
|
||||||
int radius = 10;
|
int radius = 5;
|
||||||
|
|
||||||
|
|
||||||
vec3 getColor(vec2 uvCoord) {
|
vec3 getColor(vec2 uvCoord) {
|
||||||
|
|||||||
Reference in New Issue
Block a user