added Color::operator*=(), added jitter computation to reflectance and transparency recursion, recursing now but there is still a jitter or recursion issue
git-svn-id: svn://anubis/fart/trunk@182 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
1 parent
1f00625379
commit
e233056880
9 files changed
+71
-22
No files matched your search
+42
-8
@@ -139,10 +139,13 @@ void Scene::renderPixel(int x, int y, unsigned char * pixel)
|
||||
|
||||
Color Scene::traceRay(const Ray & ray)
|
||||
{
|
||||
return traceRayDepth(ray, m_max_depth);
|
||||
return traceRayRecurse(ray, m_max_depth, 1.0);
|
||||
}
|
||||
|
||||
Color Scene::traceRayDepth(const Ray & ray, int depth)
|
||||
/**
|
||||
* factor: the proportion of the final color that this computation is worth
|
||||
*/
|
||||
Color Scene::traceRayRecurse(const Ray & ray, int depth, double factor)
|
||||
{
|
||||
Color color;
|
||||
|
||||
@@ -154,13 +157,44 @@ Color Scene::traceRayDepth(const Ray & ray, int depth)
|
||||
refptr<Material> material = hit.shape->getMaterial();
|
||||
|
||||
Vector surfacePoint = ray[hit.dist];
|
||||
Vector surfaceNormal = hit.shape->getNormalAt(surfacePoint);
|
||||
|
||||
color += Lighting::computePhong(material,
|
||||
m_lights,
|
||||
ray,
|
||||
surfacePoint,
|
||||
hit.shape->getNormalAt(surfacePoint),
|
||||
m_ambient_light);
|
||||
color = Lighting::computePhong(material,
|
||||
m_lights,
|
||||
ray,
|
||||
surfacePoint,
|
||||
surfaceNormal,
|
||||
m_ambient_light);
|
||||
|
||||
if (depth > 0 && factor > SCENE_FACTOR_THRESHOLD)
|
||||
{
|
||||
double reflectance = material->getReflectance();
|
||||
if (factor * reflectance > SCENE_FACTOR_THRESHOLD)
|
||||
{
|
||||
color *= (1.0 - reflectance);
|
||||
Vector reflected_direction =
|
||||
(-ray.getDirection()).reflect(surfaceNormal);
|
||||
Ray newRay(surfacePoint, reflected_direction);
|
||||
Vector jitter_surface_point = newRay[0.001];
|
||||
Ray jitterNewRay(jitter_surface_point, reflected_direction);
|
||||
Color c = traceRayRecurse(jitterNewRay,
|
||||
depth - 1,
|
||||
factor * reflectance);
|
||||
color += c * reflectance;
|
||||
}
|
||||
|
||||
double transparency = material->getTransparency();
|
||||
if (factor * transparency > SCENE_FACTOR_THRESHOLD)
|
||||
{
|
||||
color *= (1.0 - transparency);
|
||||
Vector jitter_surface_point = ray[hit.dist + 0.001];
|
||||
Ray newRay(jitter_surface_point, ray.getDirection());
|
||||
Color c = traceRayRecurse(newRay,
|
||||
depth - 1,
|
||||
factor * transparency);
|
||||
color += c * transparency;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return color;
|
||||
|
||||
+2
-3
@@ -17,8 +17,7 @@
|
||||
#include "parser/parser.h"
|
||||
#include "parser/nodes.h"
|
||||
|
||||
#define SCENE_MAX_TRANSPARENT_HITS 8
|
||||
#define SCENE_TRANSPARENCY_THRESHOLD 0.01
|
||||
#define SCENE_FACTOR_THRESHOLD 0.02
|
||||
|
||||
class Scene
|
||||
{
|
||||
@@ -51,7 +50,7 @@ class Scene
|
||||
/* private methods */
|
||||
void renderPixel(int x, int y, unsigned char * pixel);
|
||||
Color traceRay(const Ray & ray);
|
||||
Color traceRayDepth(const Ray & ray, int depth);
|
||||
Color traceRayRecurse(const Ray & ray, int depth, double factor);
|
||||
ShapeDistance getRayClosestHit(const Ray & ray);
|
||||
|
||||
/* In Scene-load.cc */
|
||||
|
||||
Reference in new issue
Block a user