modified shapes and Scene to return surface normal in the intersect object

git-svn-id: svn://anubis/fart/branches/2009-03-09_intersect_returning_normals@200 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop committed 2009-03-09 23:17:31 +00:00
1 parent 186bd0f8b5
commit 60b29d658d
18 files changed
+100 -171

No files matched your search

+20 -24
View File
@@ -148,27 +148,27 @@ Color Scene::traceRayRecurse(const Ray & ray, int depth, double factor)
{
Color color;
ShapeDistance hit = getRayClosestHit(ray);
Shape::Intersection hit = getRayClosestHit(ray);
if ( ! hit.shape.isNull() )
{
/* compute the Phong lighting for each hit */
refptr<Material> material = hit.shape->getMaterial();
Vector surfacePoint = ray[hit.dist];
Vector surfaceNormal = hit.shape->getNormalAt(surfacePoint);
/* TODO: make sure this can be removed */
#if 0
/* check for backfaces */
if (ray.getDirection() % surfaceNormal > 0.0)
{
/* if dot product is positive, this is a back-face */
surfaceNormal = -surfaceNormal;
}
#endif
color = computePhong(material,
ray,
surfacePoint,
surfaceNormal);
hit.position,
hit.normal);
if (depth > 0 && factor > SCENE_FACTOR_THRESHOLD)
{
@@ -177,8 +177,8 @@ Color Scene::traceRayRecurse(const Ray & ray, int depth, double factor)
{
color *= (1.0 - reflectance);
Vector reflected_direction =
(-ray.getDirection()).reflect(surfaceNormal);
Ray newRay(surfacePoint, reflected_direction);
(-ray.getDirection()).reflect(hit.normal);
Ray newRay(hit.position, reflected_direction);
Vector jitter_surface_point = newRay[0.0001];
Ray jitterNewRay(jitter_surface_point, reflected_direction);
Color c = traceRayRecurse(jitterNewRay,
@@ -191,7 +191,8 @@ Color Scene::traceRayRecurse(const Ray & ray, int depth, double factor)
if (factor * transparency > SCENE_FACTOR_THRESHOLD)
{
color *= (1.0 - transparency);
Vector jitter_surface_point = ray[hit.dist + 0.0001];
Vector jitter_surface_point = hit.position
+ ray.getDirection() * 0.0001;
Ray newRay(jitter_surface_point, ray.getDirection());
Color c = traceRayRecurse(newRay,
depth - 1,
@@ -204,9 +205,10 @@ Color Scene::traceRayRecurse(const Ray & ray, int depth, double factor)
return color;
}
Scene::ShapeDistance Scene::getRayClosestHit(const Ray & ray)
Shape::Intersection Scene::getRayClosestHit(const Ray & ray)
{
ShapeDistance hit;
Shape::Intersection hit;
double min_dist = 0.0;
bool foundOne = false;
/* loop through all shapes in the scene */
@@ -221,12 +223,12 @@ Scene::ShapeDistance Scene::getRayClosestHit(const Ray & ray)
i++)
{
refptr<Shape> shape = intersections[i].shape;
const Vector & isect_point = intersections[i].vector;
double intersect_dist = (isect_point - ray.getOrigin()).mag();
if (foundOne == false || intersect_dist < hit.dist)
const Vector & isect_point = intersections[i].position;
double intersect_dist = ray.getOrigin().dist_to(isect_point);
if (foundOne == false || intersect_dist < min_dist)
{
hit.shape = shape;
hit.dist = intersect_dist;
hit = intersections[i];
min_dist = intersect_dist;
foundOne = true;
}
}
@@ -306,12 +308,12 @@ double Scene::calculateLightContribution(const Ray & toLight,
for (;;)
{
ShapeDistance hit = getRayClosestHit(currentRay);
Shape::Intersection hit = getRayClosestHit(currentRay);
if ( hit.shape.isNull() )
break;
double offset = hit.dist + 0.0001;
double offset = currentRay.getOrigin().dist_to(hit.position) + 0.0001;
if ( dist_so_far + offset > dist_to_light )
break;
@@ -327,9 +329,3 @@ double Scene::calculateLightContribution(const Ray & toLight,
return contrib;
}
bool operator<(const Scene::ShapeDistance & sd1,
const Scene::ShapeDistance & sd2)
{
return sd1.dist < sd2.dist;
}
+1 -18
View File
@@ -22,20 +22,6 @@
class Scene
{
public:
/* types */
class ShapeDistance
{
public:
ShapeDistance() {}
ShapeDistance(refptr<Shape> shape, double dist)
{
this->shape = shape;
this->dist = dist;
}
refptr<Shape> shape;
double dist;
};
Scene(const std::map<std::string, const char *> & options,
const char * filename);
~Scene();
@@ -51,7 +37,7 @@ class Scene
void renderPixel(int x, int y, unsigned char * pixel);
Color traceRay(const Ray & ray);
Color traceRayRecurse(const Ray & ray, int depth, double factor);
ShapeDistance getRayClosestHit(const Ray & ray);
Shape::Intersection getRayClosestHit(const Ray & ray);
Color computePhong(const refptr<Material> material,
const Ray & viewRay,
const Vector & surfacePoint,
@@ -102,8 +88,5 @@ class Scene
unsigned char * m_data;
};
bool operator<(const Scene::ShapeDistance & sd1,
const Scene::ShapeDistance & sd2);
#endif