Assorted bug fixes.
This commit is contained in:
81
TODO.org
81
TODO.org
@@ -26,84 +26,3 @@
|
|||||||
- [X] Tone mapping
|
- [X] Tone mapping
|
||||||
- [ ] Texture mapping
|
- [ ] Texture mapping
|
||||||
- [ ] Photon mapping
|
- [ ] Photon mapping
|
||||||
|
|
||||||
* Junk
|
|
||||||
|
|
||||||
#+BEGIN_SRC c++
|
|
||||||
void scene_1(vector<Figure *> & vf, vector<Light *> & vl, Environment * & e, Camera * c) {
|
|
||||||
Sphere * s;
|
|
||||||
Plane * p;
|
|
||||||
Disk * d;
|
|
||||||
DirectionalLight * l;
|
|
||||||
|
|
||||||
e = new Environment(NULL, false, vec3(0.7f, 0.4f, 0.05f));
|
|
||||||
|
|
||||||
s = new Sphere(1.0f, 1.0f, -2.0f, 0.5f);
|
|
||||||
s->m_mat->m_diffuse = vec3(1.0f, 0.0f, 0.0f);
|
|
||||||
vf.push_back(static_cast<Figure *>(s));
|
|
||||||
|
|
||||||
s = new Sphere(-1.0f, 1.0f, -2.0f, 0.5f);
|
|
||||||
s->m_mat->m_diffuse = vec3(0.0f, 1.0f, 0.0f);
|
|
||||||
vf.push_back(static_cast<Figure *>(s));
|
|
||||||
|
|
||||||
s = new Sphere(1.0f, -1.0f, -2.0f, 0.5f);
|
|
||||||
s->m_mat->m_diffuse = vec3(0.0f, 0.0f, 1.0f);
|
|
||||||
vf.push_back(static_cast<Figure *>(s));
|
|
||||||
|
|
||||||
s = new Sphere(-1.0f, -1.0f, -2.0f, 0.5f);
|
|
||||||
s->m_mat->m_diffuse = vec3(1.0f, 0.0f, 1.0f);
|
|
||||||
vf.push_back(static_cast<Figure *>(s));
|
|
||||||
|
|
||||||
s = new Sphere(0.0f, 0.0f, -2.0f, 1.0f);
|
|
||||||
s->m_mat->m_diffuse = vec3(1.0f, 1.0f, 0.0f);
|
|
||||||
vf.push_back(static_cast<Figure *>(s));
|
|
||||||
|
|
||||||
p = new Plane(vec3(0.0f, -1.5f, 0.0f), vec3(0.0f, 1.0f, 0.0f));
|
|
||||||
p->m_mat->m_diffuse = vec3(1.0f, 0.5f, 0.4f);
|
|
||||||
vf.push_back(static_cast<Figure *>(p));
|
|
||||||
|
|
||||||
s = new Sphere(-1.5f, 0.0f, -2.0f, 0.5f);
|
|
||||||
s->m_mat->m_diffuse = vec3(1.0f, 1.0f, 1.0f);
|
|
||||||
s->m_mat->m_rho = 0.3f;
|
|
||||||
vf.push_back(static_cast<Figure *>(s));
|
|
||||||
|
|
||||||
s = new Sphere(1.5f, 0.0f, -2.0f, 0.5f);
|
|
||||||
s->m_mat->m_diffuse = vec3(1.0f, 1.0f, 1.0f);
|
|
||||||
s->m_mat->m_rho = 0.08f;
|
|
||||||
s->m_mat->m_refract = true;
|
|
||||||
s->m_mat->m_ref_index = 1.1f;
|
|
||||||
vf.push_back(static_cast<Figure *>(s));
|
|
||||||
|
|
||||||
s = new Sphere(0.0f, 1.5f, -2.0f, 0.5f);
|
|
||||||
s->m_mat->m_diffuse = vec3(1.0f, 1.0f, 1.0f);
|
|
||||||
s->m_mat->m_rho = 0.5f;
|
|
||||||
vf.push_back(static_cast<Figure *>(s));
|
|
||||||
|
|
||||||
s = new Sphere(0.0f, 0.0f, -1.0f, 0.25f);
|
|
||||||
s->m_mat->m_diffuse = vec3(1.0f, 1.0f, 1.0f);
|
|
||||||
s->m_mat->m_rho = 0.1f;
|
|
||||||
vf.push_back(static_cast<Figure *>(s));
|
|
||||||
|
|
||||||
d = new Disk(vec3(-0.0f, -0.0f, -0.5f), vec3(0.0f, 0.0f, 0.1f), 0.25f);
|
|
||||||
d->m_mat->m_diffuse = vec3(1.0f, 0.0f, 0.0f);
|
|
||||||
d->m_mat->m_rho = 0.3f;
|
|
||||||
d->m_mat->m_refract = true;
|
|
||||||
d->m_mat->m_ref_index = 1.33f;
|
|
||||||
vf.push_back(static_cast<Figure *>(d));
|
|
||||||
|
|
||||||
l = new DirectionalLight();
|
|
||||||
l->m_position = normalize(vec3(1.0f, 1.0f, 1.0f));
|
|
||||||
l->m_diffuse = vec3(0.0f, 1.0f, 1.0f);
|
|
||||||
vl.push_back(static_cast<Light *>(l));
|
|
||||||
|
|
||||||
l = new DirectionalLight();
|
|
||||||
l->m_position = normalize(vec3(-1.0f, 1.0f, 1.0f));
|
|
||||||
l->m_diffuse = vec3(1.0f, 1.0f, 0.0f);
|
|
||||||
vl.push_back(static_cast<Light *>(l));
|
|
||||||
|
|
||||||
l = new DirectionalLight();
|
|
||||||
l->m_position = normalize(vec3(0.0f, 1.0f, -1.0f));
|
|
||||||
l->m_diffuse = vec3(1.0f, 0.0f, 1.0f);
|
|
||||||
vl.push_back(static_cast<Light *>(l));
|
|
||||||
}
|
|
||||||
#+END_SRC
|
|
||||||
|
@@ -2,13 +2,17 @@
|
|||||||
#ifndef DIRECTIONAL_LIGHT_HPP
|
#ifndef DIRECTIONAL_LIGHT_HPP
|
||||||
#define DIRECTIONAL_LIGHT_HPP
|
#define DIRECTIONAL_LIGHT_HPP
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include "light.hpp"
|
#include "light.hpp"
|
||||||
|
|
||||||
|
using glm::normalize;
|
||||||
|
|
||||||
class DirectionalLight: public Light {
|
class DirectionalLight: public Light {
|
||||||
public:
|
public:
|
||||||
DirectionalLight(): Light() { }
|
DirectionalLight(): Light() { }
|
||||||
|
|
||||||
DirectionalLight(vec3 _p, vec3 _d, vec3 _s): Light(_p, _d, _s) { }
|
DirectionalLight(vec3 _p, vec3 _d, vec3 _s): Light(normalize(_p), _d, _s) { }
|
||||||
|
|
||||||
virtual vec3 direction(vec3 point);
|
virtual vec3 direction(vec3 point);
|
||||||
virtual float distance(vec3 point);
|
virtual float distance(vec3 point);
|
||||||
|
27
main.cpp
27
main.cpp
@@ -30,10 +30,6 @@ using namespace glm;
|
|||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
// Function prototypes.
|
// Function prototypes.
|
||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
// static void scene_1(vector<Figure *> & vf, vector<Light *> & vl, Environment * & e, Camera * c);
|
|
||||||
// static void scene_2(vector<Figure *> & vf, vector<Light *> & vl, Environment * & e, Camera * c);
|
|
||||||
// static void scene_3(vector<Figure *> & vf, vector<Light *> & vl, Environment * & e, Camera * c);
|
|
||||||
// static void scene_4(vector<Figure *> & vf, vector<Light *> & vl, Environment * & e, Camera * c);
|
|
||||||
static void print_usage(char ** const argv);
|
static void print_usage(char ** const argv);
|
||||||
static void parse_args(int argc, char ** const argv);
|
static void parse_args(int argc, char ** const argv);
|
||||||
|
|
||||||
@@ -143,6 +139,7 @@ int main(int argc, char ** argv) {
|
|||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
// Copy the pixels to the output bitmap.
|
// Copy the pixels to the output bitmap.
|
||||||
|
if (g_tracer == MONTE_CARLO || g_tracer == JENSEN) {
|
||||||
cout << "Saving output image." << endl;
|
cout << "Saving output image." << endl;
|
||||||
input_bitmap = FreeImage_AllocateT(FIT_RGBF, g_w, g_h, 96);
|
input_bitmap = FreeImage_AllocateT(FIT_RGBF, g_w, g_h, 96);
|
||||||
pitch = FreeImage_GetPitch(input_bitmap);
|
pitch = FreeImage_GetPitch(input_bitmap);
|
||||||
@@ -165,6 +162,28 @@ int main(int argc, char ** argv) {
|
|||||||
FreeImage_Unload(input_bitmap);
|
FreeImage_Unload(input_bitmap);
|
||||||
FreeImage_Unload(output_bitmap);
|
FreeImage_Unload(output_bitmap);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
input_bitmap = FreeImage_Allocate(g_w, g_h, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
|
||||||
|
pitch = FreeImage_GetLine(input_bitmap) / FreeImage_GetWidth(input_bitmap);
|
||||||
|
bits = (BYTE *)FreeImage_GetBits(input_bitmap);
|
||||||
|
for (unsigned int y = 0; y < FreeImage_GetHeight(input_bitmap); y++) {
|
||||||
|
bits = FreeImage_GetScanLine(input_bitmap, y);
|
||||||
|
for (unsigned int x = 0; x < FreeImage_GetWidth(input_bitmap); x++) {
|
||||||
|
bits[FI_RGBA_RED] = static_cast<BYTE>(image[g_h - 1 - y][x].r * 255.0f);
|
||||||
|
bits[FI_RGBA_GREEN] = static_cast<BYTE>(image[g_h - 1 - y][x].g * 255.0f);
|
||||||
|
bits[FI_RGBA_BLUE] = static_cast<BYTE>(image[g_h - 1 - y][x].b * 255.0f);
|
||||||
|
bits += pitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FreeImage_AdjustGamma(input_bitmap, g_gamma);
|
||||||
|
|
||||||
|
// Save the output image.
|
||||||
|
fif = FreeImage_GetFIFFromFilename(g_out_file_name != NULL ? g_out_file_name : OUT_FILE);
|
||||||
|
FreeImage_Save(fif, input_bitmap, g_out_file_name != NULL ? g_out_file_name : OUT_FILE);
|
||||||
|
FreeImage_Unload(input_bitmap);
|
||||||
|
}
|
||||||
|
|
||||||
// Clean up.
|
// Clean up.
|
||||||
if (g_out_file_name != NULL)
|
if (g_out_file_name != NULL)
|
||||||
free(g_out_file_name);
|
free(g_out_file_name);
|
||||||
|
BIN
output.png
BIN
output.png
Binary file not shown.
Before Width: | Height: | Size: 396 KiB After Width: | Height: | Size: 396 KiB |
44
scene.cpp
44
scene.cpp
@@ -89,7 +89,7 @@ static const string LGT_SPD_KEY = "spot_direction";
|
|||||||
static const string LGT_SPC_KEY = "spot_cutoff";
|
static const string LGT_SPC_KEY = "spot_cutoff";
|
||||||
static const string LGT_SPE_KEY = "spot_exponent";
|
static const string LGT_SPE_KEY = "spot_exponent";
|
||||||
|
|
||||||
Scene::Scene(const char * file_name, int h, int w, float fov) throw(SceneError) {
|
Scene::Scene(const char * file_name, int h, int w, float fov) {
|
||||||
ostringstream oss;
|
ostringstream oss;
|
||||||
ifstream ifs(file_name, ios::in);
|
ifstream ifs(file_name, ios::in);
|
||||||
Value val;
|
Value val;
|
||||||
@@ -142,6 +142,8 @@ Scene::Scene(const char * file_name, int h, int w, float fov) throw(SceneError)
|
|||||||
}
|
}
|
||||||
} catch (SceneError & e) {
|
} catch (SceneError & e) {
|
||||||
throw e;
|
throw e;
|
||||||
|
} catch (runtime_error & r) {
|
||||||
|
throw SceneError("Type error in input file.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there were no camera and/or environment defined, create some default ones.
|
// If there were no camera and/or environment defined, create some default ones.
|
||||||
@@ -169,7 +171,7 @@ Scene::~Scene() {
|
|||||||
m_lights.clear();
|
m_lights.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::read_vector(Value & val, vec3 & vec) throw(SceneError) {
|
void Scene::read_vector(Value & val, vec3 & vec) {
|
||||||
Array a = val.get_value<Array>();
|
Array a = val.get_value<Array>();
|
||||||
|
|
||||||
if (a.size() < 3)
|
if (a.size() < 3)
|
||||||
@@ -178,7 +180,7 @@ void Scene::read_vector(Value & val, vec3 & vec) throw(SceneError) {
|
|||||||
vec = vec3(a[0].get_value<double>(), a[1].get_value<double>(), a[2].get_value<double>());
|
vec = vec3(a[0].get_value<double>(), a[1].get_value<double>(), a[2].get_value<double>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::read_environment(Value & v) throw(SceneError) {
|
void Scene::read_environment(Value & v) {
|
||||||
string t_name = "";
|
string t_name = "";
|
||||||
bool l_probe = false, has_tex = false, has_color = false;
|
bool l_probe = false, has_tex = false, has_color = false;
|
||||||
vec3 color = vec3(1.0f);
|
vec3 color = vec3(1.0f);
|
||||||
@@ -211,13 +213,12 @@ void Scene::read_environment(Value & v) throw(SceneError) {
|
|||||||
m_env = new Environment(has_tex ? t_name.c_str() : NULL , l_probe, color);
|
m_env = new Environment(has_tex ? t_name.c_str() : NULL , l_probe, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::read_camera(Value & v) throw(SceneError) {
|
void Scene::read_camera(Value & v) {
|
||||||
bool has_up = false, has_left = false, has_eye = false, has_look = false;
|
bool has_up = false, has_left = false, has_eye = false, has_look = false;
|
||||||
vec3 eye, look, left, up, translation;
|
vec3 eye, look, left, up, translation;
|
||||||
float pitch = 0.0f, yaw = 0.0f, roll = 0.0f;
|
float pitch = 0.0f, yaw = 0.0f, roll = 0.0f;
|
||||||
Object cam_obj = v.get_value<Object>();
|
Object cam_obj = v.get_value<Object>();
|
||||||
|
|
||||||
try {
|
|
||||||
for (Object::iterator it = cam_obj.begin(); it != cam_obj.end(); it++) {
|
for (Object::iterator it = cam_obj.begin(); it != cam_obj.end(); it++) {
|
||||||
if ((*it).name_ == CAM_EYE_KEY) {
|
if ((*it).name_ == CAM_EYE_KEY) {
|
||||||
read_vector((*it).value_, eye);
|
read_vector((*it).value_, eye);
|
||||||
@@ -250,9 +251,6 @@ void Scene::read_camera(Value & v) throw(SceneError) {
|
|||||||
else
|
else
|
||||||
cerr << "Unrecognized key \"" << (*it).name_ << "\" in camera." << endl;
|
cerr << "Unrecognized key \"" << (*it).name_ << "\" in camera." << endl;
|
||||||
}
|
}
|
||||||
} catch (SceneError & e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!has_eye || !has_look)
|
if (!has_eye || !has_look)
|
||||||
throw SceneError("Must specify an eye and look positions for the camera.");
|
throw SceneError("Must specify an eye and look positions for the camera.");
|
||||||
@@ -271,14 +269,13 @@ void Scene::read_camera(Value & v) throw(SceneError) {
|
|||||||
m_cam->translate(translation);
|
m_cam->translate(translation);
|
||||||
}
|
}
|
||||||
|
|
||||||
Material * Scene::read_material(Value & v) throw(SceneError) {
|
Material * Scene::read_material(Value & v) {
|
||||||
vec3 emission = vec3(0.0f), diffuse = vec3(1.0f), specular = vec3(1.0f);
|
vec3 emission = vec3(0.0f), diffuse = vec3(1.0f), specular = vec3(1.0f);
|
||||||
bool transmissive = false;
|
bool transmissive = false;
|
||||||
float rho = 0.0f, ref_index = 1.0f, shininess = 89.0f;
|
float rho = 0.0f, ref_index = 1.0f, shininess = 89.0f;
|
||||||
Material * mat = NULL;
|
Material * mat = NULL;
|
||||||
Object mat_obj = v.get_value<Object>();
|
Object mat_obj = v.get_value<Object>();
|
||||||
|
|
||||||
try {
|
|
||||||
for (Object::iterator it = mat_obj.begin(); it != mat_obj.end(); it++) {
|
for (Object::iterator it = mat_obj.begin(); it != mat_obj.end(); it++) {
|
||||||
if ((*it).name_ == MLT_EMS_KEY) {
|
if ((*it).name_ == MLT_EMS_KEY) {
|
||||||
read_vector((*it).value_, emission);
|
read_vector((*it).value_, emission);
|
||||||
@@ -312,9 +309,6 @@ Material * Scene::read_material(Value & v) throw(SceneError) {
|
|||||||
} else
|
} else
|
||||||
cerr << "Unrecognized key \"" << (*it).name_ << "\" in material." << endl;
|
cerr << "Unrecognized key \"" << (*it).name_ << "\" in material." << endl;
|
||||||
}
|
}
|
||||||
} catch(SceneError & e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mat == NULL)
|
if (mat == NULL)
|
||||||
mat = new Material();
|
mat = new Material();
|
||||||
@@ -329,14 +323,13 @@ Material * Scene::read_material(Value & v) throw(SceneError) {
|
|||||||
return mat;
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
Figure * Scene::read_sphere(Value &v) throw(SceneError) {
|
Figure * Scene::read_sphere(Value &v) {
|
||||||
bool has_position = false, has_radius = false;
|
bool has_position = false, has_radius = false;
|
||||||
vec3 position;
|
vec3 position;
|
||||||
float radius = 1.0f;
|
float radius = 1.0f;
|
||||||
Material * mat = NULL;
|
Material * mat = NULL;
|
||||||
Object sph_obj = v.get_value<Object>();
|
Object sph_obj = v.get_value<Object>();
|
||||||
|
|
||||||
try {
|
|
||||||
for (Object::iterator it = sph_obj.begin(); it != sph_obj.end(); it++) {
|
for (Object::iterator it = sph_obj.begin(); it != sph_obj.end(); it++) {
|
||||||
if ((*it).name_ == FIG_POS_KEY) {
|
if ((*it).name_ == FIG_POS_KEY) {
|
||||||
read_vector((*it).value_, position);
|
read_vector((*it).value_, position);
|
||||||
@@ -360,9 +353,6 @@ Figure * Scene::read_sphere(Value &v) throw(SceneError) {
|
|||||||
} else
|
} else
|
||||||
cerr << "Unrecognized key \"" << (*it).name_ << "\" in sphere." << endl;
|
cerr << "Unrecognized key \"" << (*it).name_ << "\" in sphere." << endl;
|
||||||
}
|
}
|
||||||
} catch (SceneError & e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!has_position || !has_radius)
|
if (!has_position || !has_radius)
|
||||||
throw SceneError("Sphere must specify a position and radius.");
|
throw SceneError("Sphere must specify a position and radius.");
|
||||||
@@ -370,13 +360,12 @@ Figure * Scene::read_sphere(Value &v) throw(SceneError) {
|
|||||||
return static_cast<Figure *>(new Sphere(position, radius, mat));
|
return static_cast<Figure *>(new Sphere(position, radius, mat));
|
||||||
}
|
}
|
||||||
|
|
||||||
Figure * Scene::read_plane(Value &v) throw(SceneError) {
|
Figure * Scene::read_plane(Value &v) {
|
||||||
bool has_position = false, has_normal = false;
|
bool has_position = false, has_normal = false;
|
||||||
vec3 position, normal = vec3(0.0f, 1.0f, 0.0f);
|
vec3 position, normal = vec3(0.0f, 1.0f, 0.0f);
|
||||||
Material * mat = NULL;
|
Material * mat = NULL;
|
||||||
Object pln_obj = v.get_value<Object>();
|
Object pln_obj = v.get_value<Object>();
|
||||||
|
|
||||||
try {
|
|
||||||
for (Object::iterator it = pln_obj.begin(); it != pln_obj.end(); it++) {
|
for (Object::iterator it = pln_obj.begin(); it != pln_obj.end(); it++) {
|
||||||
if ((*it).name_ == FIG_POS_KEY || (*it).name_ == PLN_PNT_KEY) {
|
if ((*it).name_ == FIG_POS_KEY || (*it).name_ == PLN_PNT_KEY) {
|
||||||
read_vector((*it).value_, position);
|
read_vector((*it).value_, position);
|
||||||
@@ -396,9 +385,6 @@ Figure * Scene::read_plane(Value &v) throw(SceneError) {
|
|||||||
} else
|
} else
|
||||||
cerr << "Unrecognized key \"" << (*it).name_ << "\" in plane." << endl;
|
cerr << "Unrecognized key \"" << (*it).name_ << "\" in plane." << endl;
|
||||||
}
|
}
|
||||||
} catch (SceneError & e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!has_position || !has_normal)
|
if (!has_position || !has_normal)
|
||||||
throw SceneError("Plane must specify a point and normal vector.");
|
throw SceneError("Plane must specify a point and normal vector.");
|
||||||
@@ -406,14 +392,13 @@ Figure * Scene::read_plane(Value &v) throw(SceneError) {
|
|||||||
return static_cast<Figure *>(new Plane(position, normal, mat));
|
return static_cast<Figure *>(new Plane(position, normal, mat));
|
||||||
}
|
}
|
||||||
|
|
||||||
Figure * Scene::read_disk(Value &v) throw(SceneError) {
|
Figure * Scene::read_disk(Value &v) {
|
||||||
bool has_position = false, has_normal = false, has_radius = false;
|
bool has_position = false, has_normal = false, has_radius = false;
|
||||||
vec3 position, normal = vec3(0.0f, 1.0f, 0.0f);
|
vec3 position, normal = vec3(0.0f, 1.0f, 0.0f);
|
||||||
float radius = 1.0f;
|
float radius = 1.0f;
|
||||||
Material * mat = NULL;
|
Material * mat = NULL;
|
||||||
Object dsk_obj = v.get_value<Object>();
|
Object dsk_obj = v.get_value<Object>();
|
||||||
|
|
||||||
try {
|
|
||||||
for (Object::iterator it = dsk_obj.begin(); it != dsk_obj.end(); it++) {
|
for (Object::iterator it = dsk_obj.begin(); it != dsk_obj.end(); it++) {
|
||||||
if ((*it).name_ == FIG_POS_KEY || (*it).name_ == PLN_PNT_KEY) {
|
if ((*it).name_ == FIG_POS_KEY || (*it).name_ == PLN_PNT_KEY) {
|
||||||
read_vector((*it).value_, position);
|
read_vector((*it).value_, position);
|
||||||
@@ -441,9 +426,6 @@ Figure * Scene::read_disk(Value &v) throw(SceneError) {
|
|||||||
} else
|
} else
|
||||||
cerr << "Unrecognized key \"" << (*it).name_ << "\" in disk." << endl;
|
cerr << "Unrecognized key \"" << (*it).name_ << "\" in disk." << endl;
|
||||||
}
|
}
|
||||||
} catch (SceneError & e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!has_position || !has_normal || !has_radius)
|
if (!has_position || !has_normal || !has_radius)
|
||||||
throw SceneError("Disk must specify a point, a normal vector and a radius.");
|
throw SceneError("Disk must specify a point, a normal vector and a radius.");
|
||||||
@@ -451,12 +433,11 @@ Figure * Scene::read_disk(Value &v) throw(SceneError) {
|
|||||||
return static_cast<Figure *>(new Disk(position, normal, radius, mat));
|
return static_cast<Figure *>(new Disk(position, normal, radius, mat));
|
||||||
}
|
}
|
||||||
|
|
||||||
Light * Scene::read_light(Value & v, light_type_t t) throw(SceneError) {
|
Light * Scene::read_light(Value & v, light_type_t t) {
|
||||||
vec3 position, diffuse = vec3(1.0f), specular = vec3(1.0f), spot_dir = vec3(0.0f, -1.0f, 0.0f);
|
vec3 position, diffuse = vec3(1.0f), specular = vec3(1.0f), spot_dir = vec3(0.0f, -1.0f, 0.0f);
|
||||||
float const_att = 1.0f, lin_att = 0.0f, quad_att = 0.0f, spot_cutoff = 45.0f, spot_exp = 0.0f;
|
float const_att = 1.0f, lin_att = 0.0f, quad_att = 0.0f, spot_cutoff = 45.0f, spot_exp = 0.0f;
|
||||||
Object lght_obj = v.get_value<Object>();
|
Object lght_obj = v.get_value<Object>();
|
||||||
|
|
||||||
try {
|
|
||||||
for (Object::iterator it = lght_obj.begin(); it != lght_obj.end(); it++) {
|
for (Object::iterator it = lght_obj.begin(); it != lght_obj.end(); it++) {
|
||||||
if ((*it).name_ == FIG_POS_KEY || (*it).name_ == LGT_DIR_KEY)
|
if ((*it).name_ == FIG_POS_KEY || (*it).name_ == LGT_DIR_KEY)
|
||||||
read_vector((*it).value_, position);
|
read_vector((*it).value_, position);
|
||||||
@@ -485,9 +466,6 @@ Light * Scene::read_light(Value & v, light_type_t t) throw(SceneError) {
|
|||||||
else if ((*it).name_ == LGT_SPE_KEY)
|
else if ((*it).name_ == LGT_SPE_KEY)
|
||||||
spot_exp = static_cast<float>((*it).value_.get_value<double>());
|
spot_exp = static_cast<float>((*it).value_.get_value<double>());
|
||||||
}
|
}
|
||||||
} catch (SceneError & e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t == DIRECTIONAL)
|
if (t == DIRECTIONAL)
|
||||||
return static_cast<Light *>(new DirectionalLight(position, diffuse, specular));
|
return static_cast<Light *>(new DirectionalLight(position, diffuse, specular));
|
||||||
|
18
scene.hpp
18
scene.hpp
@@ -33,18 +33,18 @@ public:
|
|||||||
Environment * m_env;
|
Environment * m_env;
|
||||||
Camera * m_cam;
|
Camera * m_cam;
|
||||||
|
|
||||||
Scene(const char * file_name, int h = 480, int w = 640, float fov = 90.0f) throw(SceneError);
|
Scene(const char * file_name, int h = 480, int w = 640, float fov = 90.0f);
|
||||||
~Scene();
|
~Scene();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void read_vector(Value & val, vec3 & vec) throw(SceneError);
|
void read_vector(Value & val, vec3 & vec);
|
||||||
void read_environment(Value & v) throw(SceneError);
|
void read_environment(Value & v);
|
||||||
void read_camera(Value & v) throw(SceneError);
|
void read_camera(Value & v);
|
||||||
Material * read_material(Value & v) throw(SceneError);
|
Material * read_material(Value & v);
|
||||||
Figure * read_sphere(Value & v) throw(SceneError);
|
Figure * read_sphere(Value & v);
|
||||||
Figure * read_plane(Value & v) throw(SceneError);
|
Figure * read_plane(Value & v);
|
||||||
Figure * read_disk(Value & v) throw(SceneError);
|
Figure * read_disk(Value & v);
|
||||||
Light * read_light(Value & v, light_type_t t) throw(SceneError);
|
Light * read_light(Value & v, light_type_t t);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
124
scenes/scene1.json
Normal file
124
scenes/scene1.json
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
{
|
||||||
|
"directional_light": {
|
||||||
|
"direction": [1.0, 1.0, 1.0],
|
||||||
|
"diffuse": [0.0, 1.0, 1.0]
|
||||||
|
},
|
||||||
|
|
||||||
|
"directional_light": {
|
||||||
|
"direction": [-1.0, 1.0, 1.0],
|
||||||
|
"diffuse": [1.0, 1.0, 0.0]
|
||||||
|
},
|
||||||
|
|
||||||
|
"directional_light": {
|
||||||
|
"direction": [0.0, 1.0, -1.0],
|
||||||
|
"diffuse": [1.0, 0.0, 1.0]
|
||||||
|
},
|
||||||
|
|
||||||
|
"disk": {
|
||||||
|
"position": [-0.0, -0.0, -0.5],
|
||||||
|
"normal": [0.0, 0.0, 0.1],
|
||||||
|
"radius": 0.25,
|
||||||
|
"material": {
|
||||||
|
"diffuse": [1.0, 0.0, 0.0],
|
||||||
|
"rho": 0.3,
|
||||||
|
"transmissive": true,
|
||||||
|
"ref_index": 1.33
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"plane": {
|
||||||
|
"point": [0.0, -1.5, 0.0],
|
||||||
|
"normal": [0.0, 1.0, 0.0],
|
||||||
|
"material": {
|
||||||
|
"diffuse": [1.0, 0.5, 0.4]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"sphere": {
|
||||||
|
"position": [1.0, 1.0, -2.0],
|
||||||
|
"radius": 0.5,
|
||||||
|
"material": {
|
||||||
|
"diffuse": [1.0, 0.0, 0.0]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"sphere": {
|
||||||
|
"position": [-1.0, 1.0, -2.0],
|
||||||
|
"radius": 0.5,
|
||||||
|
"material": {
|
||||||
|
"diffuse": [0.0, 1.0, 0.0]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"sphere": {
|
||||||
|
"position": [1.0, -1.0, -2.0],
|
||||||
|
"radius": 0.5,
|
||||||
|
"material": {
|
||||||
|
"diffuse": [0.0, 0.0, 1.0]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"sphere": {
|
||||||
|
"position": [-1.0, -1.0, -2.0],
|
||||||
|
"radius": 0.5,
|
||||||
|
"material": {
|
||||||
|
"diffuse": [1.0, 0.0, 1.0]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"sphere": {
|
||||||
|
"position": [0.0, 0.0, -2.0],
|
||||||
|
"radius": 1.0,
|
||||||
|
"material": {
|
||||||
|
"diffuse": [1.0, 1.0, 0.0]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"sphere": {
|
||||||
|
"position": [-1.5, 0.0, -2.0],
|
||||||
|
"radius": 0.5,
|
||||||
|
"material": {
|
||||||
|
"diffuse": [1.0, 1.0, 1.0],
|
||||||
|
"rho": 0.3
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"sphere": {
|
||||||
|
"position": [1.5, 0.0, -2.0],
|
||||||
|
"radius": 0.5,
|
||||||
|
"material": {
|
||||||
|
"diffuse": [1.0, 1.0, 1.0],
|
||||||
|
"rho": 0.08,
|
||||||
|
"transmissive": true,
|
||||||
|
"ref_index": 1.1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"sphere": {
|
||||||
|
"position": [0.0, 1.5, -2.0],
|
||||||
|
"radius": 0.5,
|
||||||
|
"material": {
|
||||||
|
"diffuse": [1.0, 1.0, 1.0],
|
||||||
|
"rho": 0.5
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"sphere": {
|
||||||
|
"position": [0.0, 0.0, -1.0],
|
||||||
|
"radius": 0.25,
|
||||||
|
"material": {
|
||||||
|
"diffuse": [1.0, 1.0, 1.0],
|
||||||
|
"rho": 0.1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"environment": {
|
||||||
|
"color": [0.7, 0.4, 0.05]
|
||||||
|
},
|
||||||
|
|
||||||
|
"camera": {
|
||||||
|
"eye": [0.0, 0.0, 1.0],
|
||||||
|
"look": [0.0, 0.0, -1.0],
|
||||||
|
"up": [0.0, 1.0, 0.0]
|
||||||
|
}
|
||||||
|
}
|
@@ -85,8 +85,8 @@ vec3 WhittedTracer::trace_ray(Ray & r, Scene * s, unsigned int rec_level) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return final color.
|
// Return final color.
|
||||||
return _f->m_mat->m_emission + color;
|
return clamp(_f->m_mat->m_emission + color, 0.0f, 1.0f);
|
||||||
|
|
||||||
} else
|
} else
|
||||||
return s->m_env->get_color(r);
|
return clamp(s->m_env->get_color(r), 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user