//********************************* // // Depth Of Field Simulation v1.0 // // Author: Mario Klingemann // mario@quasimondo.com // http://incubator.quasimondo.com // // // This is the first attempt and // not yet documented. // //******************************** Convolver c; BImage[] layers; int layerCount; int maxLayer; int maxRadius; float fLayerCount; boolean initDone; float zmin; float zmax; float ax; float ay; void setup() { size(200, 200); background(255); stroke(200); smooth(); c=new Convolver(1); layerCount=3; maxLayer=layerCount-1; fLayerCount=float(layerCount); layers=new BImage[layerCount]; maxRadius=layerCount*2; zmin=.94; zmax=.05; ax=HALF_PI; ay=0; } void loop() { background(255); translate(100,100,-250); rotateY(ay); rotateX(ax); ax+=.1; ay+=.03; fill(240,230,220); box(100); fill(230,230,230); push(); translate(0,-150,0); box(50); pop(); push(); translate(0,150,0); box(50); pop(); push(); translate(150,0,0); box(50); pop(); push(); translate(-150,0,0); box(50); pop(); push(); translate(0,0,150); box(50); pop(); translate(0,0,-150); box(50); zBlur(); } void zBlur(){ int x,y,i,l,m1,m2,rv,gv,bv; float d; layers[0]=new BImage(width, height); layers[0].pixels=pixels; for (i=1;i>16)*m2 + ((p2 & 0xff0000)>>16)*m1) << 8) & 0xff0000; gv=((((p1 & 0x00ff00)>>8 )*m2 + ((p2 & 0x00ff00)>>8 )*m1)) & 0x00ff00; bv=((((p1 & 0x0000ff) *m2 + (p2 & 0x0000ff) *m1)) >> 8) & 0x0000ff; pixels[i]=rv | gv | bv; } i++; } } } float getMaxZ(int x,int y,int r){ x=max(0,x-r); y=max(0,y-r); r*=2; int xu=min(x+r,width-1); int yu=min(y+r,height-1); float maxZ=0; float[] gz=g.zbuffer; float gzi; for (int ym=y;ym>16; g[i]=(ri&0x00ff00)>>8; b[i]=(ri&0x0000ff); } int r2[]=new int[wh]; int g2[]=new int[wh]; int b2[]=new int[wh]; yi=0; for (yl=0;yl=0 && read=0){ cr+=mult[i][r2[read]]; cg+=mult[i][g2[read]]; cb+=mult[i][b2[read]]; sum+=kernel[i]; } ri++; read+=w; } pix[xl+yi]=0xff000000 | (cr/sum)<<16 | (cg/sum)<<8 | (cb/sum); } yi+=w; } } }