void doRender(void* arg){ RenderParams rarg = *((RenderParams *)arg); //cout<<"Do render...."<<endl; bool pixelHit=false; HitInfo hitInfo; hitInfo.Init(); Point2 pixLoc = rarg.pixLocation; Cone r = rarg.ray; int PixIndex = rarg.pixIndex; Color shade(0,0,0); vector<Point2> haltonXY; float dx = rarg.PixParams.x; float dy = rarg.PixParams.y; float x=0; float y=0; _f.Normalize(); _s.Normalize(); const float pts[9]={_s.x,_u.x,-_f.x,_s.y,_u.y,-_f.y,_s.z,_u.z,-_f.z}; Matrix3 RotMat; RotMat.Set(pts); for(int i=0; i < MIN_N_SAMPLES; i++){ x = dx * Halton(i+1, H_BASE_1); y = dy * Halton(i+1, H_BASE_2); if(x > dx * 0.5) { x -= dx; } if(y < dy * 0.5) { y -= dy; } x += rarg.K.x; y += rarg.K.y; Point2 sampleLoc = Point2(x,y); haltonXY.push_back(sampleLoc); } vector<Color> shades; if(rootNode.GetNumChild()>0){ for(int i=0; i< MIN_N_SAMPLES;i++){ Point3 sampleDir = Point3(haltonXY.at(i).x, haltonXY.at(i).y, rarg.K.z); int rindex = rand() % MAX_N_SAMPLES; //rindex = i; Point3 randPos = rarg.ConfCirclePts.at(rindex); Cone sampleRay = Cone(randPos, sampleDir); sampleRay.dir = sampleRay.dir * RotMat; sampleRay.dir -= randPos - camera.pos; sampleRay.dir.Normalize(); sampleRay.radius = r.radius; sampleRay.tanAngle = r.tanAngle; r = sampleRay; if(RayTrace_2(r, hitInfo)) { pixelHit=true; shade = hitInfo.node->GetMaterial()->Shade(r, hitInfo, lights, 8); shades.push_back(shade); } hitInfo.Init(); } if(VarianceOverThreshold(shades)){ renderImage.SetSampleCountPixel(PixIndex, 255); hitInfo.Init(); for(int i=MIN_N_SAMPLES; i < MAX_N_SAMPLES; i++){ x = dx * Halton(i+1, H_BASE_1); y = dy * Halton(i+1, H_BASE_2); if(x > dx * 0.5) { x -= dx;} if(y < dy * 0.5) { y -= dy;} x += rarg.K.x; y += rarg.K.y; Point2 sampleLoc = Point2(x,y); haltonXY.push_back(sampleLoc); Point3 sampleDir = Point3(haltonXY.at(i).x, haltonXY.at(i).y, rarg.K.z); int rindex = rand() % MAX_N_SAMPLES; //rindex = i; Point3 randPos = rarg.ConfCirclePts.at(rindex); Cone sampleRay = Cone(randPos, sampleDir); sampleRay.dir = sampleRay.dir * RotMat; sampleRay.dir -= randPos - camera.pos; sampleRay.dir.Normalize(); sampleRay.radius = r.radius; sampleRay.tanAngle = r.tanAngle; r = sampleRay; if(RayTrace_2(r, hitInfo)) { pixelHit=true; shade = hitInfo.node->GetMaterial()->Shade(r, hitInfo, lights, 5); shades.push_back(shade); } hitInfo.Init(); } shade = AverageShades(shades, (int)shades.size()); } else{ shade = AverageShades(shades, (int)shades.size()); renderImage.SetSampleCountPixel(PixIndex, 0); } renderImage.PutPixel(PixIndex, shade, hitInfo.z); } if(!pixelHit){ Point3 uvw(pixLoc.x/ camera.imgWidth,pixLoc.y/camera.imgHeight,0); shade = background.Sample(uvw); renderImage.PutPixel(PixIndex, shade, BIGFLOAT); } pthread_mutex_lock(&setPix_mutex); renderImage.IncrementNumRenderPixel(1); pthread_mutex_unlock(&setPix_mutex); }