Skip to content

Commit

Permalink
Added the cornell box, to visualize better any work on photon mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro committed May 12, 2009
1 parent 5dbc9e9 commit 0e230b2
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 18 deletions.
46 changes: 38 additions & 8 deletions main.cpp
Expand Up @@ -108,15 +108,15 @@ Color castRay(Ray ray, int recursive, double &dst)
{
//Increase the ray counter
nrays++;

//Was there an intersection?
bool intersect = false;
//Is this object receiving light?
bool shadow = false;

//Main color, reflection and refraction color
Color c(0.0, 0.0, 0.0), c2(0.0, 0.0, 0.0), c3(0.0, 0.0, 0.0);

//Pointer to the interseted object
Object *o;

Expand Down Expand Up @@ -200,7 +200,7 @@ Color castRay(Ray ray, int recursive, double &dst)
Vector3 r = l - norm*2*l.dot(norm);
double k = v.dot(r);
if(k > 0)
c = c + ls*pow(k, 20.0)*o->getMat().spec;
c = c + ls*pow(k, 20.0)*o->getMat().spec;
}
}
}
Expand Down Expand Up @@ -349,7 +349,7 @@ void init()

//SET 1
//Add some spheres
objects.push_back(new Sphere(1, Vector3(-3, -4, -11),
/*objects.push_back(new Sphere(1, Vector3(-3, -4, -11),
Material(Color(1.0,0,0), 0.95, 0.8, 0.05, 0.0, 1.2)));
objects.push_back(new Sphere(1.1, Vector3(-1.2, -3.5, -7),
Material(Color(0,0,1.0), 0.0, 0.3, 0.0, 1.0, 1.51714)));
Expand All @@ -375,11 +375,41 @@ void init()
Vector3(-7.5f, 5.0f, -18.0f),
Material(Color(0.3,0.3,0.7), 0.7, 0.4, 0.6, 0.5, 1.2)));

//Lights, and global ambient
//Lights, and global ambient
lights.push_back(Light(Vector3(-5, 3.0, 2.0), Color(0.0, 0.0, 0.0), Color(0.6f, 0.6f, 0.6f), Color(0.7f, 0.7f, 0.7f), GLOBAL));
lights.push_back(Light(Vector3(5, 1.0, 3.0), Color(0.0, 0.0, 0.0), Color(0.6f, 0.6f, 0.8f), Color(0.6f, 0.6f, 0.8f), GLOBAL));
gAmbient = Color(0.00, 0.00, 0.00);
lights.push_back(Light(Vector3(5, 1.0, 3.0), Color(0.0, 0.0, 0.0), Color(0.6f, 0.6f, 0.8f), Color(0.6f, 0.6f, 0.8f), GLOBAL));*/




/* Cornell Box */
objects.push_back(new Wall(Vector3(-2.0f, -2.0f, -2.0f), Vector3(2.0f, 2.0f, -2.0f),
Vector3(2.0f, -2.0f, -2.0f), Material(Color(0.8,0.8,0.8),
1.0, 0.35, 0.0, 0.0, 1.2), false, true));
objects.push_back(new Wall(Vector3(-2.0f, -2.0f, -2.0f), Vector3(-2.0f, 2.0f, 2.0f),
Vector3(-2.0f, 2.0f, -2.0f), Material(Color(1,0.0,0.0),
1.0, 0.35, 0.0, 0.0, 1.2), false, true));
objects.push_back(new Wall(Vector3(2.0f, -2.0f, -2.0f), Vector3(2.0f, 2.0f, 2.0f),
Vector3(2.0f, -2.0f, 2.0f), Material(Color(0.0,1,0.0),
1.0, 0.35, 0.0, 0.0, 1.2), false, true));
objects.push_back(new Wall(Vector3(-2.0f, 2.0f, -2.0f), Vector3(2.0f, 2.0f, 2.0f),
Vector3(2.0f, 2.0f, -2.0f), Material(Color(0.8,0.8,0.8),
1.0, 0.35, 0.0, 0.0, 1.2), false, true));
objects.push_back(new Wall(Vector3(-2.0f, -2.0f, -2.0f), Vector3(2.0f, -2.0f, 2.0f),
Vector3(-2.0f, -2.0f, 2.0f), Material(Color(0.8,0.8,0.8),
1.0, 0.35, 0.0, 0.0, 1.2), false, true));

objects.push_back(new Sphere(0.6, Vector3(-1, -1.4, 0),
Material(Color(0.0,0.0,1.0), 0.0, 0.1, 1.0, 0.0, 1.2)));

objects.push_back(new Sphere(0.5, Vector3(1, 0, 1),
Material(Color(0.0,0.0,1.0), 1.0, 0.7, 0.0, 0.0, 1.2)));

lights.push_back(Light(Vector3(0, 1, 2), Color(0.0, 0.0, 0.0), Color(0.6f, 0.6f, 0.8f), Color(0.6f, 0.6f, 0.8f), GLOBAL));


//THIS IS THE DEFAULT = COLOR(0,0,0); DO NOT CHANGE UNLESS NECESARY
gAmbient = Color(0.1, 0.1, 0.1);

nrays = 0;
}
Expand Down
Binary file modified main.o
Binary file not shown.
17 changes: 9 additions & 8 deletions objects/Wall.cpp
@@ -1,16 +1,15 @@
#include "Wall.h"
#include <iostream>
using namespace std;
Wall::Wall()
{
//Wall(Vector3(-20.0f, 0.0f, 20.0f), Vector3(20.0f, 0.0f, -20.0f), Vector3(20.0f, 0.0f, 20.0f), Color(1,1,1), Color(1,1,1), Color(1,1,1), 1);
}

Wall:: Wall(Vector3 min, Vector3 max, Vector3 other, Material mat, bool emmit)
:Object((min+max)/2, mat, emmit)
Wall:: Wall(Vector3 min, Vector3 max, Vector3 other, Material mat, bool em, bool inf)
:Object((min+max)/2, mat, em)
{
Wall::min = min;
Wall::max = max;
infinite = inf;

Vector3 u = min - other;
Vector3 v = max - other;
Expand All @@ -20,11 +19,13 @@ Wall:: Wall(Vector3 min, Vector3 max, Vector3 other, Material mat, bool emmit)
d = -(a*min[0] + b*min[1] + c*min[2]);
}

Wall:: Wall(Vector3 min, Vector3 max, Vector3 other, Material mat, Texture tex, bool emmit)
:Object((min+max)/2, mat, tex, emmit)
Wall:: Wall(Vector3 min, Vector3 max, Vector3 other, Material mat,
Texture tex, bool em, bool inf)
:Object((min+max)/2, mat, tex, em)
{
Wall::min = min;
Wall::max = max;
infinite = infinite;

Vector3 u = min - other;
Vector3 v = max - other;
Expand Down Expand Up @@ -69,7 +70,7 @@ Color Wall::getColor(Vector3 &p)
If there is no intersection it returns -1
*/
double Wall::rayIntersection(Ray &ray)
{
{
Vector3 n(a,b,c);
double dot = n.dot(ray.getDir());
if(dot >= 0)return -1;
Expand All @@ -78,7 +79,7 @@ double Wall::rayIntersection(Ray &ray)

Vector3 p = ray.getPoint(t);

if(p >= min && p <= max)
if(infinite || (p >= min && p <= max))
return t;

return -1;
Expand Down
7 changes: 5 additions & 2 deletions objects/Wall.h
Expand Up @@ -12,10 +12,13 @@ class Wall :public Object
Vector3 min, max;
//Plane Ecuation
double a,b,c,d;
bool infinite;
public:
Wall(void);
Wall(Vector3 min, Vector3 max, Vector3 other, Material mat, bool emmit=false);
Wall(Vector3 min, Vector3 max, Vector3 other, Material mat, Texture tex, bool emit=false);
Wall(Vector3 min, Vector3 max, Vector3 other, Material mat,
bool emmit=false, bool infinite=false);
Wall(Vector3 min, Vector3 max, Vector3 other, Material mat,
Texture tex, bool emit=false, bool infinite = false);

//Is the point inside
bool isInside(Vector3 &point);
Expand Down
Binary file modified objects/Wall.o
Binary file not shown.

0 comments on commit 0e230b2

Please sign in to comment.