Psycho_Gamer
03-26-2007, 08:34 PM
Hello,
So, my scene basically is composed of two spheres lying on a plane. Each of these objects are reflective. I am performing recursive ray shading as follows:
//the colour to return...Start it off black.
Colour col(0.0, 0.0, 0.0);
//end recursion
if(curDepth==maxDepth){
col = ray.col;
return col;
}
traverseScene(_root, ray);
//did the ray hit anything?
if (!ray.intersection.none) {
computeShading(ray);
col = ray.col;
//the colour that reflection causes.
Colour reflectionColour(0.0, 0.0, 0.0);
//check for reflection.
if(ray.intersection.mat->reflection>0){
Vector3D normal= ray.intersection.normal;
Vector3D reflectionMirror= ray.dir - ((2*(normal.dot(ray.dir)))*normal);
//create the reflection ray, and shoot it out to the scene.
Ray3D reflectRay;
reflectRay.dir=reflectionMirror;
reflectRay.origin=ray.intersection.point;
reflectionColour=shadeRay(reflectRay, curDepth+1, maxDepth);
}
col = ray.col +(ray.intersection.mat->reflection * reflectionColour);
ray.col=col;
ray.col.clamp();
}
return col;
My Ray3d struct is:
struct Ray3D {
Ray3D() {
intersection.none = true;
}
Ray3D( Point3D p, Vector3D v ) : origin(p), dir(v) {
intersection.none = true;
}
// The origin of the ray
Point3D origin;
//the direction that this ray is going in/
Vector3D dir;
// Intersection status, should be computed by the intersection
// function.
Intersection intersection;
// Current colour of the ray, should be computed by the shading
// function.
Colour col;
};
Intersection Struct is:
struct Intersection {
// Location of intersection.
Point3D point;
// Normal at the intersection.
Vector3D normal;
// Material at the intersection.
Material* mat;
// Position of the intersection point on your ray.
// (i.e. point = ray.origin + t_value * ray.dir)
// This is used when you need to intersect multiply objects and
// only want to keep the nearest intersection.
double t_value;
// Set to true when no intersection has occured.
bool none;
//where the light source is located for this ray.
Vector3D lightSource;
};
Does anyone know why my reflection is not working? It basically changes all of the colours in my scene to funky colours. I have been on this for 4 hours,lol. I bet it is something really small too :(
Thanks
So, my scene basically is composed of two spheres lying on a plane. Each of these objects are reflective. I am performing recursive ray shading as follows:
//the colour to return...Start it off black.
Colour col(0.0, 0.0, 0.0);
//end recursion
if(curDepth==maxDepth){
col = ray.col;
return col;
}
traverseScene(_root, ray);
//did the ray hit anything?
if (!ray.intersection.none) {
computeShading(ray);
col = ray.col;
//the colour that reflection causes.
Colour reflectionColour(0.0, 0.0, 0.0);
//check for reflection.
if(ray.intersection.mat->reflection>0){
Vector3D normal= ray.intersection.normal;
Vector3D reflectionMirror= ray.dir - ((2*(normal.dot(ray.dir)))*normal);
//create the reflection ray, and shoot it out to the scene.
Ray3D reflectRay;
reflectRay.dir=reflectionMirror;
reflectRay.origin=ray.intersection.point;
reflectionColour=shadeRay(reflectRay, curDepth+1, maxDepth);
}
col = ray.col +(ray.intersection.mat->reflection * reflectionColour);
ray.col=col;
ray.col.clamp();
}
return col;
My Ray3d struct is:
struct Ray3D {
Ray3D() {
intersection.none = true;
}
Ray3D( Point3D p, Vector3D v ) : origin(p), dir(v) {
intersection.none = true;
}
// The origin of the ray
Point3D origin;
//the direction that this ray is going in/
Vector3D dir;
// Intersection status, should be computed by the intersection
// function.
Intersection intersection;
// Current colour of the ray, should be computed by the shading
// function.
Colour col;
};
Intersection Struct is:
struct Intersection {
// Location of intersection.
Point3D point;
// Normal at the intersection.
Vector3D normal;
// Material at the intersection.
Material* mat;
// Position of the intersection point on your ray.
// (i.e. point = ray.origin + t_value * ray.dir)
// This is used when you need to intersect multiply objects and
// only want to keep the nearest intersection.
double t_value;
// Set to true when no intersection has occured.
bool none;
//where the light source is located for this ray.
Vector3D lightSource;
};
Does anyone know why my reflection is not working? It basically changes all of the colours in my scene to funky colours. I have been on this for 4 hours,lol. I bet it is something really small too :(
Thanks