#version 330 core in vec2 wspTekstur; uniform sampler2D ProbnikTekstury; out vec3 kolor_out; float Jasnosc(vec4 kolor) { return (kolor.r + kolor.g + kolor.b)/3.0; } vec4 SkalaSzarosci(vec4 kolor) { float jasnosc = Jasnosc(kolor); return vec4(jasnosc, jasnosc, jasnosc, kolor.a); } const vec2 rozmiarOkna = vec2(800,600); //const int zakres = 3; //parametr decydujacy o "rozmyciu" obrazu //vec2 rozmiarProstokata = vec2(10, 10); //w pikselach mat3 sx = mat3( 1.0, 2.0, 1.0, 0.0, 0.0, 0.0, -1.0, -2.0, -1.0); mat3 sy = mat3( 1.0, 0.0, -1.0, 2.0, 0.0, -2.0, 1.0, 0.0, -1.0 ); void main() { //kolor_out = texture(ProbnikTekstury, wspTekstur).rgb; //kolor_out = SkalaSzarosci(texture(ProbnikTekstury, wspTekstur)).rgb; //widok zza lodu //vec2 przesuniecie = 0.01 * vec2(sin(80.0*wspTekstur.x), cos(60.0*wspTekstur.y)); //kolor_out = texture(ProbnikTekstury, wspTekstur + przesuniecie).rgb; /* //zmniejszanie rozdzielczosci tekstury vec4 teksel = vec4(0); float sumaWag = 0; for(int ix = -zakres; ix <= zakres; ix++) { for(int iy = -zakres; iy <= zakres; iy++) { float dx = ix / rozmiarOkna.x; float dy = iy / rozmiarOkna.y; //float r2 = dx*dx + dy*dy; float waga = 1; //tu można wymyślną funkcję teksel += texture(ProbnikTekstury, wspTekstur + vec2(dx, dy)) * waga; sumaWag += waga; } } teksel.rgb /= sumaWag; teksel.a = 1; */ /* //pikseloza float dx = rozmiarProstokata.x/rozmiarOkna.x; //rozmiar prostokata we wsp. ekranu float dy = rozmiarProstokata.y/rozmiarOkna.y; vec2 _wspTekstur = vec2(dx*floor(wspTekstur.x/dx), dy*floor(wspTekstur.y/dy)); vec4 teksel = texture(ProbnikTekstury, _wspTekstur); */ //vec4 teksel = texture(ProbnikTekstury, wspTekstur); //kolor_out = teksel.rgb; //krawedzie - operator Sobela (jest wiecej podobnych operatorow) - rozniczkowanie na kracie //https://computergraphics.stackexchange.com/questions/3646/opengl-glsl-sobel-edge-detection-filter //http://rastergrid.com/blog/2011/01/frei-chen-edge-detector/ vec3 teksel = texture(ProbnikTekstury, wspTekstur).rgb; //vec2 wspTekstur2 = gl_FragCoord.st/rozmiarOkna; //przesuniecie o wysokosc paska tytulu i bocznego //vec3 teksel = texture(ProbnikTekstury, wspTekstur2).rgb; mat3 j; //macierz jasnosci for (int ix=-1; ix<=1; ix++) { for (int iy=-1; iy<=1; iy++) { //texelFetch - inaczej niz texture robi prosty dostep do teksela, bez filtrowania, interpolowania itp. //vec3 _teksel = texelFetch(ProbnikTekstury, ivec2(gl_FragCoord) + ivec2(ix, iy), 0).rgb; vec3 _teksel = texelFetch(ProbnikTekstury, ivec2(wspTekstur*rozmiarOkna) + ivec2(ix, iy), 0).rgb; j[ix+1][iy+1] = length(_teksel); } } float gx = dot(sx[0], j[0]) + dot(sx[1], j[1]) + dot(sx[2], j[2]); float gy = dot(sy[0], j[0]) + dot(sy[1], j[1]) + dot(sy[2], j[2]); float g = sqrt(gx*gx + gy*gy); //kolor_out = teksel; //kolor_out = vec3(g); kolor_out = 1 - vec3(g); //kolor_out = teksel + vec3(g); }