Skip to content

Commit

Permalink
Enhance: make the suspect point test logical to raytracer.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Wujun Zhou committed Mar 5, 2012
1 parent a412656 commit 1e1db9c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
14 changes: 5 additions & 9 deletions src/ImageBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,24 @@ ImageBuffer::ImageBuffer(int width,int height)
void
ImageBuffer::setColor(int x,int y,Color color)
{
int cr=std::floor(color.r*255);
int cr=std::floor(color.x*255);
if(cr>255)
cr=255;
int cg=std::floor(color.g*255);
int cg=std::floor(color.y*255);
if(cg>255)
cg=255;
int cb=std::floor(color.b*255);
int cb=std::floor(color.z*255);
if(cb>255)
cb=255;
buffer[x+y*width]=(cr<<16)|(cg<<8)|cb;
#ifndef NDEBUG
if(cr<0||cg<0||cb<0)
cout<<"suspect point:px="<<x<<",py="<<y<<"color:"<<color<<endl;
#endif /*NDEBUG*/
buffer[x+y*width]=((cr&255)<<16)|((cg&255)<<8)|(cb&255);
}

void
ImageBuffer::setDepth(int x,int y,float depth)
{
float normal=depth/garg_max_depth;
float invese=1.0-normal;
zbuffer[x+y*width]=(normal<0.0f)?0.0f:normal;
zbuffer[x+y*width]=(invese<0.0f)?0.0f:invese;
}

void
Expand Down
22 changes: 16 additions & 6 deletions src/Raytracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ Raytracer::doRaytrace()
/*using default shared, because on mac os x the const Camera will be
* predetermined as shard and have error
* 'camera' is predetermined 'shared' for 'shared'
* while on linux it must been marked as shared*/
* while on linux it must been marked as shared*/
#ifdef _OPENMP
#pragma omp parallel for schedule(dynamic) default(shared) \
private(x,y) shared(height,width,topGroup)
#endif
/*int nthreads, tid;
#pragma omp parallel private(nthreads, tid)
tid = omp_get_thread_num();
Expand All @@ -42,18 +44,26 @@ Raytracer::doRaytrace()
//cout<<x<<" "<<y<<" "<<ray.origin<<" "<<ray.direction<<endl;
topGroup->intersection(ray);
if (ray.hitObject==NULL){ /// not hit terminal ray
image.setColor(x,y,scene.getBackground());
image.setColor(x,y,scene.getBackground());
}else{
Vec3f hitPoint=ray.origin+ray.distance*ray.direction;
Vec3f normal=ray.hitObject->getNormal(hitPoint);
Material& material=scene.getMaterial(ray.hitObject->getMaterialIndex());

image.setDepth(x,y,ray.distance);
image.setColor(x,y,DOT(normal,-ray.direction)*(material.diffuseColor));
//cout<<x<<" "<<y<<"hit,distance:"<<ray.distance<<" hitpoint:"<<hitPoint<<"normal:"<<normal<<endl<<endl;
Color color=DOT(normal,-ray.direction)*(material.diffuseColor);

#ifndef RELEASE
if(color.x<0||color.y<0||color.z<0){
cout<<"suspect point:px="<<x<<",py="<<y<<"color:"<<color<<endl;
cout<<x<<" "<<y<<"hit,distance:"<<ray.distance<<" hitpoint:"<<hitPoint<<"normal:"<<normal<<"ray"<<ray.direction<<endl<<endl;
color.x=color.y=color.z=1.0f; //to make the point easier to seen
}
#endif /*RELEASE*/

image.setColor(x,y,color);
}
camera.updateRayX(ray);
}
// camera.updateRayY(ray);
camera.updateRayX(ray);
}
}

0 comments on commit 1e1db9c

Please sign in to comment.