added refraction computations to Scene::traceRay()
git-svn-id: svn://anubis/fart/trunk@376 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
1 parent
931cde802e
commit
22f4a79671
4 files changed
+21
-8
No files matched your search
+13
-5
@@ -119,13 +119,15 @@ void Scene::renderPixel(int x, int y, unsigned char * pixel)
|
||||
|
||||
Color Scene::traceRay(const Ray & ray)
|
||||
{
|
||||
return traceRayRecurse(ray, m_max_depth, 1.0);
|
||||
static refptr<Material> air = new Material();
|
||||
return traceRayRecurse(ray, m_max_depth, 1.0, air);
|
||||
}
|
||||
|
||||
/**
|
||||
* factor: the proportion of the final color that this computation is worth
|
||||
*/
|
||||
Color Scene::traceRayRecurse(const Ray & ray, int depth, double factor)
|
||||
Color Scene::traceRayRecurse(const Ray & ray, int depth, double factor,
|
||||
refptr<Material> last_material)
|
||||
{
|
||||
Color color;
|
||||
|
||||
@@ -161,7 +163,8 @@ Color Scene::traceRayRecurse(const Ray & ray, int depth, double factor)
|
||||
Ray jitterNewRay(jitter_surface_point, reflected_direction);
|
||||
Color c = traceRayRecurse(jitterNewRay,
|
||||
depth - 1,
|
||||
factor * reflectance);
|
||||
factor * reflectance,
|
||||
material);
|
||||
color += c * reflectance;
|
||||
}
|
||||
|
||||
@@ -171,10 +174,15 @@ Color Scene::traceRayRecurse(const Ray & ray, int depth, double factor)
|
||||
color *= (1.0 - transparency);
|
||||
Vector jitter_surface_point = hit.position
|
||||
+ ray.getDirection() * 0.0001;
|
||||
Ray newRay(jitter_surface_point, ray.getDirection());
|
||||
Vector refracted_direction =
|
||||
ray.getDirection().refract(hit.normal,
|
||||
last_material->getRefraction(),
|
||||
material->getRefraction());
|
||||
Ray newRay(jitter_surface_point, refracted_direction);
|
||||
Color c = traceRayRecurse(newRay,
|
||||
depth - 1,
|
||||
factor * transparency);
|
||||
factor * transparency,
|
||||
material);
|
||||
color += c * transparency;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -46,7 +46,8 @@ class Scene
|
||||
protected:
|
||||
/* private methods */
|
||||
Color traceRay(const Ray & ray);
|
||||
Color traceRayRecurse(const Ray & ray, int depth, double factor);
|
||||
Color traceRayRecurse(const Ray & ray, int depth, double factor,
|
||||
refptr<Material> last_material);
|
||||
Shape::Intersection getRayClosestHit(const Ray & ray);
|
||||
Color computePhong(const refptr<Material> material,
|
||||
const Ray & viewRay,
|
||||
|
||||
Reference in new issue
Block a user