/* Nicolas Sievers 3/04 - Edge mapper W/Blur Maybe Sobel*/ surface edge_mapperWblurSobel(float Kd = 1, next = .005 , thrshld = .2; string texname = "") { color surfcolor = color(1,1,1); float diff,camDist; float i,j,k,m; printf("%f\n", length(I)); if(texname != "") { float total = 0; float index = 0; camDist = length(I); float thrshldCor = thrshld + (thrshld * (1/(camDist))); float blurValues[9]; float counter = 0; float surround[9]; float counter1 = 0; /*blur loops*/ for(k=-1;k<=1;k=k+1) { for(m=-1;m<=1;m=m+1) { float test_pixel = float texture(texname, s + (k*next), t + (m*next)); total = 0; index = 0; for(i=-1;i<=1;i=i+1) { for(j=-1;j<=1;j=j+1) { float compare_pixel = float texture(texname, s + (k*next) + (i*next), t + (m*next) + (j*next)); total += compare_pixel; index += 1; } } blurValues[counter] = (total/index); counter += 1; } } /*edge detection loops*/ float test_pixel = blurValues[4]; float newCnt = counter; float total_diff = 0; for(i=-1;i<=1;i=i+1) { for(j=-1;j<=1;j=j+1) { surround[counter1] = blurValues[counter - newCnt]; counter1 += 1; newCnt -= 1; } } float Sx = (surround[2] + (2*surround[5]) + surround[8]) - (surround[0] + (2*surround[3]) + surround[6]); float Sy = (surround[0] + (2*surround[1]) + surround[2]) - (surround[6] + (2*surround[7]) + surround[8]); float Mag = sqrt( pow(Sx,2) + pow(Sy,2) ); float edgeColor = 1 - smoothstep(-.8,.8,Mag - thrshldCor); surfcolor = (texture(texname[0], s, t)*edgeColor,texture(texname[1], s, t)*edgeColor, texture(texname[2], s, t)*edgeColor); } /* STEP 1 - make a copy of the surface normal one unit in length */ normal n = normalize(N); normal nf = faceforward(n, I); /* STEP 2 - set the apparent surface opacity */ Oi = Os; /* STEP 3 - calculate the diffuse lighting component */ color diffusecolor = Kd * diffuse(nf); /* STEP 4 - calculate the apparent surface color */ Ci = Oi * Cs * surfcolor * diffusecolor; }